Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EZP-29608: better output of updateserachindexsolr #206

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 30 additions & 14 deletions bin/php/updatesearchindexsolr.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function run()
}


$this->CLI->output( 'Starting object re-indexing' );
$this->output( 'Starting object re-indexing' );

// Get PHP executable from user.
$this->getPHPExecutable();
Expand Down Expand Up @@ -204,14 +204,14 @@ function_exists( 'pcntl_fork' ) &&
function_exists( 'posix_kill' ) );
if ( $useFork )
{
$this->CLI->output( 'Using fork.' );
$this->output( 'Using fork.' );
}
else
{
$processLimit = 1;
}

$this->CLI->output( 'Using ' . $processLimit . ' concurent process(es)' );
$this->output( 'Using ' . $processLimit . ' concurent process(es)' );

$processList = array();
for ( $i = 0; $i < $processLimit; $i++ )
Expand All @@ -220,7 +220,7 @@ function_exists( 'posix_kill' ) );
}

$this->ObjectCount = $this->objectCount();
$this->CLI->output( 'Number of objects to index: ' . $this->ObjectCount );
$this->output( 'Number of objects to index: ' . $this->ObjectCount );
$this->Script->resetIteration( $this->ObjectCount, 0 );

$topNodeArray = eZPersistentObject::fetchObjectList(
Expand All @@ -246,8 +246,14 @@ function_exists( 'posix_kill' ) );
{
if ( $pid === -1 || !posix_kill( $pid, 0 ) )
{
if ($pid !== -1 )
{
$this->output( 'Process finished: ' . $pid );
}

$newPid = $this->forkAndExecute( $nodeID, $offset, $this->Limit );
$this->CLI->output( "\n" . 'Creating a new thread: ' . $newPid );
$this->output( "\n" . 'Created a new process: ' . $newPid . ' to handle '.$this->Limit.' nodes out of '.$subtreeCount.' children of node '.$nodeID.' starting at: '.$offset);

if ( $newPid > 0 )
{
$offset += $this->Limit;
Expand All @@ -263,7 +269,7 @@ function_exists( 'posix_kill' ) );
else
{
// Execute in same process
$this->CLI->output( "\n" . 'Starting a new batch' );
$this->output( "\n" . 'Starting a new batch' );
$count = $this->execute( $nodeID, $offset, $this->Limit );
$this->iterate( $count );
$offset += $this->Limit;
Expand Down Expand Up @@ -303,7 +309,7 @@ function_exists( 'posix_kill' ) );
}
else
{
$this->CLI->output( 'Process finished: ' . $pid );
$this->output( 'Process finished: ' . $pid );
$processList[$i] = -1;
}
}
Expand All @@ -315,16 +321,16 @@ function_exists( 'posix_kill' ) );
usleep( 500000 );
}

$this->CLI->output( 'Optimizing. Please wait ...' );
$this->output( 'Optimizing. Please wait ...' );
$searchEngine->optimize( true );
$endTS = microtime_float();

$this->CLI->output(
'Indexing took ' . ( $endTS - $startTS ) . ' secs ' .
'( average: ' . ( $this->ObjectCount / ( $endTS - $startTS ) ) . ' objects/sec )'
$this->output(
'Indexing took ' . sprintf( '%.3f', $endTS - $startTS ) . ' secs ' .
'( average: ' . sprintf( '%.3f', $this->ObjectCount / ( $endTS - $startTS ) ) . ' objects/sec )'
);

$this->CLI->output( 'Finished updating the search index.' );
$this->output( 'Finished updating the search index.' );
}

/**
Expand Down Expand Up @@ -355,6 +361,7 @@ protected function iterate( $count = false )
* @param int $nodeid
* @param int $offset
* @param int $limit
* @return int
*/
protected function forkAndExecute( $nodeID, $offset, $limit )
{
Expand Down Expand Up @@ -473,7 +480,7 @@ protected function cleanUp()
{
if ( $this->Options['clean'] )
{
$this->CLI->output( "eZSearchEngine: Cleaning up search data for current installation id" );
$this->output( "eZSearchEngine: Cleaning up search data for current installation id" );
$searchEngine = new eZSolr();
$allInstallations = false;
$optimize = false;
Expand All @@ -489,7 +496,7 @@ protected function cleanUpAll()
{
if ( $this->Options['clean-all'] )
{
$this->CLI->output( "eZSearchEngine: Cleaning up search data for all installations" );
$this->output( "eZSearchEngine: Cleaning up search data for all installations" );
$searchEngine = new eZSolr();
// The essence of teh All suffix
$allInstallations = true;
Expand Down Expand Up @@ -608,6 +615,15 @@ protected function checkSolrRunning()
}
}

protected function output( $string = false, $addEOL = true )
{
if ( $this->CLI->isQuiet() )
return;
fwrite(STDOUT, $string);
if ( $addEOL )
fwrite(STDOUT, $this->CLI->endlineString());
}

const DEFAULT_COMMIT_WITHIN = 30;

private $commitWithin = self::DEFAULT_COMMIT_WITHIN;
Expand Down