Merge pull request #107 from iaom/0122-dev

Optimized index sub-process code.
This commit is contained in:
张佳萍 2021-01-26 11:36:44 +08:00 committed by GitHub
commit 9845fdd3bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 50 deletions

View File

@ -63,6 +63,7 @@ void FirstIndex::DoSomething(const QFileInfo& fileInfo){
} }
void FirstIndex::run(){ void FirstIndex::run(){
int fifo_fd; int fifo_fd;
char buffer[2]; char buffer[2];
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
@ -75,32 +76,6 @@ void FirstIndex::run(){
assert(false); assert(false);
} }
if (this->bool_dataBaseExist){
if (this->bool_dataBaseStatusOK){
int retval = write(fifo_fd, buffer, strlen(buffer));
if(retval == -1)
{
perror("write error\n");
}
printf("write data ok!\n");
//why???????????????????????????????????????????????????????????????
//why not quit?
// this->quit();
// exit(0);
return;
// this->wait();
}
else{
//if the parameter is false, index won't be rebuild
//if it is true, index will be rebuild
p_indexGenerator = IndexGenerator::getInstance(true,this);
}
}
else{
p_indexGenerator = IndexGenerator::getInstance(false,this);
}
// this->q_content_index->enqueue(QString("/home/zhangzihao/Desktop/qwerty/四库全书.txt")); // this->q_content_index->enqueue(QString("/home/zhangzihao/Desktop/qwerty/四库全书.txt"));
// this->p_indexGenerator->creatAllIndex(this->q_content_index); // this->p_indexGenerator->creatAllIndex(this->q_content_index);
@ -114,6 +89,19 @@ void FirstIndex::run(){
{ {
prctl(PR_SET_PDEATHSIG, SIGTERM); prctl(PR_SET_PDEATHSIG, SIGTERM);
prctl(PR_SET_NAME,"first-index"); prctl(PR_SET_NAME,"first-index");
if (this->bool_dataBaseExist){
if (this->bool_dataBaseStatusOK){
::exit(0);
}
else{
//if the parameter is false, index won't be rebuild
//if it is true, index will be rebuild
p_indexGenerator = IndexGenerator::getInstance(true,this);
}
}
else{
p_indexGenerator = IndexGenerator::getInstance(false,this);
}
QSemaphore sem(5); QSemaphore sem(5);
QMutex mutex1, mutex2, mutex3; QMutex mutex1, mutex2, mutex3;
mutex1.lock(); mutex1.lock();
@ -151,17 +139,6 @@ void FirstIndex::run(){
mutex1.unlock(); mutex1.unlock();
mutex2.unlock(); mutex2.unlock();
mutex3.unlock(); mutex3.unlock();
::exit(0);
// qDebug() << "first index end;";
//don't use it now!!!!
//MouseZhangZh
// this->~FirstIndex();
// qDebug() << "~FirstIndex end;"
if (this->q_index) if (this->q_index)
delete this->q_index; delete this->q_index;
@ -172,9 +149,7 @@ void FirstIndex::run(){
if (p_indexGenerator) if (p_indexGenerator)
delete p_indexGenerator; delete p_indexGenerator;
p_indexGenerator = nullptr; p_indexGenerator = nullptr;
::exit(0);
QThreadPool::globalInstance()->releaseThread();
QThreadPool::globalInstance()->waitForDone();
} }
else if(pid < 0) else if(pid < 0)
{ {
@ -186,17 +161,13 @@ void FirstIndex::run(){
--FileUtils::_index_status; --FileUtils::_index_status;
} }
int retval = write(fifo_fd, buffer, strlen(buffer)); int retval = write(fifo_fd, buffer, strlen(buffer));
if(retval == -1) if(retval == -1)
{ {
perror("write error\n"); qWarning("write error\n");
} }
printf("write data ok!\n"); qDebug("write data ok!\n");
return;
//quit() is shit!!!
// return;
// exit(0);
this->quit();
// this->wait();
} }

View File

@ -82,6 +82,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
{ {
// FileUtils::_index_status |= 0x2; // FileUtils::_index_status |= 0x2;
HandlePathList(messageList); HandlePathList(messageList);
qDebug()<<"begin creatAllIndex";
int size = _doc_list_content->size(); int size = _doc_list_content->size();
if(!size == 0) if(!size == 0)
{ {
@ -105,6 +106,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
assert(false); assert(false);
} }
// FileUtils::_index_status &= ~0x2; // FileUtils::_index_status &= ~0x2;
qDebug()<<"finish creatAllIndex";
_doc_list_content->clear(); _doc_list_content->clear();
delete _doc_list_content; delete _doc_list_content;
_doc_list_content = nullptr; _doc_list_content = nullptr;
@ -142,10 +144,13 @@ IndexGenerator::~IndexGenerator()
QMutexLocker locker(&m_mutex); QMutexLocker locker(&m_mutex);
qDebug() << "~IndexGenerator"; qDebug() << "~IndexGenerator";
if(m_database_path) if(m_database_path)
delete m_database_path; m_database_path->~WritableDatabase();
// delete m_database_path;
m_database_path = nullptr; m_database_path = nullptr;
if(m_database_content) if(m_database_content)
delete m_database_content; m_database_content->~WritableDatabase();
// delete m_database_content;
m_database_path = nullptr;
m_database_content = nullptr; m_database_content = nullptr;
global_instance = nullptr; global_instance = nullptr;
// if(m_index_map) // if(m_index_map)

View File

@ -353,6 +353,8 @@ fork:
} }
else if ( rc == 0 ) { else if ( rc == 0 ) {
qDebug() << "select timeout!"; qDebug() << "select timeout!";
::free(read_timeout);
IndexGenerator::getInstance()->~IndexGenerator();
::exit(0); ::exit(0);
}else{ }else{
numRead = read(m_fd, buf, BUF_LEN); numRead = read(m_fd, buf, BUF_LEN);
@ -387,6 +389,7 @@ fork:
// ::exit(0); // ::exit(0);
// } // }
// } // }
} }
else if (pid > 0){ else if (pid > 0){
memset(buf, 0x00, BUF_LEN); memset(buf, 0x00, BUF_LEN);