Skip to content

Commit

Permalink
Fix EZP-29608: better output of updateserachindexsolr
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetano Giunta committed Jan 26, 2017
1 parent 20f281e commit cddb84d
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 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,17 @@ protected function checkSolrRunning()
}
}

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

const DEFAULT_COMMIT_WITHIN = 30;

private $commitWithin = self::DEFAULT_COMMIT_WITHIN;
Expand Down

0 comments on commit cddb84d

Please sign in to comment.