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 664 public function indexDocuments($max=null)
665 665 {
666 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 679 $this->checkForRegisteredTypes();
669 680  
670 681 $default->log->info('indexDocuments: start');
671 682 if (!$this->doesDiagnosticsPass())
672 683 {
  684 + unlink($indexLockFile);
673 685 return;
674 686 }
675 687  
676   - $config =& KTConfig::getSingleton();
677 688 if (is_null($max))
678 689 {
679 690 $max = $config->get('indexer/batchDocuments',20);
... ... @@ -702,12 +713,14 @@ abstract class Indexer
702 713 $result = DBUtil::getResultArray($sql);
703 714 if (PEAR::isError($result))
704 715 {
  716 + unlink($indexLockFile);
705 717 return;
706 718 }
707 719  
708 720 // bail if no work to do
709 721 if (count($result) == 0)
710 722 {
  723 + unlink($indexLockFile);
711 724 return;
712 725 }
713 726  
... ... @@ -915,6 +928,7 @@ abstract class Indexer
915 928  
916 929 }
917 930 $default->log->info('indexDocuments: done');
  931 + unlink($indexLockFile);
918 932 }
919 933  
920 934 public function migrateDocuments($max=null)
... ...