Optimized index sub-process code.

This commit is contained in:
zhangpengfei 2021-01-26 11:32:02 +08:00
parent 22fbf1883f
commit 7e3bb085a8
3 changed files with 29 additions and 50 deletions

View File

@ -63,6 +63,7 @@ void FirstIndex::DoSomething(const QFileInfo& fileInfo){
}
void FirstIndex::run(){
int fifo_fd;
char buffer[2];
memset(buffer, 0, sizeof(buffer));
@ -75,32 +76,6 @@ void FirstIndex::run(){
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->p_indexGenerator->creatAllIndex(this->q_content_index);
@ -114,6 +89,19 @@ void FirstIndex::run(){
{
prctl(PR_SET_PDEATHSIG, SIGTERM);
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);
QMutex mutex1, mutex2, mutex3;
mutex1.lock();
@ -151,17 +139,6 @@ void FirstIndex::run(){
mutex1.unlock();
mutex2.unlock();
mutex3.unlock();
::exit(0);
// qDebug() << "first index end;";
//don't use it now!!!!
//MouseZhangZh
// this->~FirstIndex();
// qDebug() << "~FirstIndex end;"
if (this->q_index)
delete this->q_index;
@ -172,9 +149,7 @@ void FirstIndex::run(){
if (p_indexGenerator)
delete p_indexGenerator;
p_indexGenerator = nullptr;
QThreadPool::globalInstance()->releaseThread();
QThreadPool::globalInstance()->waitForDone();
::exit(0);
}
else if(pid < 0)
{
@ -186,17 +161,13 @@ void FirstIndex::run(){
--FileUtils::_index_status;
}
int retval = write(fifo_fd, buffer, strlen(buffer));
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;
HandlePathList(messageList);
qDebug()<<"begin creatAllIndex";
int size = _doc_list_content->size();
if(!size == 0)
{
@ -105,6 +106,7 @@ bool IndexGenerator::creatAllIndex(QQueue<QString> *messageList)
assert(false);
}
// FileUtils::_index_status &= ~0x2;
qDebug()<<"finish creatAllIndex";
_doc_list_content->clear();
delete _doc_list_content;
_doc_list_content = nullptr;
@ -142,10 +144,13 @@ IndexGenerator::~IndexGenerator()
QMutexLocker locker(&m_mutex);
qDebug() << "~IndexGenerator";
if(m_database_path)
delete m_database_path;
m_database_path->~WritableDatabase();
// delete m_database_path;
m_database_path = nullptr;
if(m_database_content)
delete m_database_content;
m_database_content->~WritableDatabase();
// delete m_database_content;
m_database_path = nullptr;
m_database_content = nullptr;
global_instance = nullptr;
// if(m_index_map)

View File

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