Commit 633e74f3d0f392023a150ef4e591fdd3b2e838a2

Authored by Conrad Vermeulen
1 parent 9ed398dc

KTS-673

"The search algorithm needs some work"
Updated. Prevent multiple instances of indexer running which may lock the server under load

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7536 c91229c3-7414-0410-bfa2-8a42b809f60b
search2/indexing/indexerCore.inc.php
@@ -664,16 +664,27 @@ abstract class Indexer @@ -664,16 +664,27 @@ abstract class Indexer
664 public function indexDocuments($max=null) 664 public function indexDocuments($max=null)
665 { 665 {
666 global $default; 666 global $default;
  667 + $config =& KTConfig::getSingleton();
  668 +
  669 + $indexLockFile = $config->get('cache/cacheDirectory') . '/main.index.lock';
  670 + if (is_file($indexLockFile))
  671 + {
  672 + $default->log->info('indexDocuments: main.index.lock seems to exist. it could be that the indexing is still underway.');
  673 + $default->log->info('indexDocuments: Remove "' . $indexLockFile . '" if the indexing is not running or extend the frequency at which the background task runs!');
  674 + return;
  675 + }
  676 + touch($indexLockFile);
  677 +
667 678
668 $this->checkForRegisteredTypes(); 679 $this->checkForRegisteredTypes();
669 680
670 $default->log->info('indexDocuments: start'); 681 $default->log->info('indexDocuments: start');
671 if (!$this->doesDiagnosticsPass()) 682 if (!$this->doesDiagnosticsPass())
672 { 683 {
  684 + unlink($indexLockFile);
673 return; 685 return;
674 } 686 }
675 687
676 - $config =& KTConfig::getSingleton();  
677 if (is_null($max)) 688 if (is_null($max))
678 { 689 {
679 $max = $config->get('indexer/batchDocuments',20); 690 $max = $config->get('indexer/batchDocuments',20);
@@ -702,12 +713,14 @@ abstract class Indexer @@ -702,12 +713,14 @@ abstract class Indexer
702 $result = DBUtil::getResultArray($sql); 713 $result = DBUtil::getResultArray($sql);
703 if (PEAR::isError($result)) 714 if (PEAR::isError($result))
704 { 715 {
  716 + unlink($indexLockFile);
705 return; 717 return;
706 } 718 }
707 719
708 // bail if no work to do 720 // bail if no work to do
709 if (count($result) == 0) 721 if (count($result) == 0)
710 { 722 {
  723 + unlink($indexLockFile);
711 return; 724 return;
712 } 725 }
713 726
@@ -915,6 +928,7 @@ abstract class Indexer @@ -915,6 +928,7 @@ abstract class Indexer
915 928
916 } 929 }
917 $default->log->info('indexDocuments: done'); 930 $default->log->info('indexDocuments: done');
  931 + unlink($indexLockFile);
918 } 932 }
919 933
920 public function migrateDocuments($max=null) 934 public function migrateDocuments($max=null)