From d4e9dd90f4dbb8849b796a130dfdea4bf50f330e Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 3 Mar 2013 04:45:15 -0800 Subject: [PATCH] Added --postime option syncFileBackend. * Useful when starting positions are made after copying started. Change-Id: I34d996594753f7bc4449dac96a4822242c1897ee --- .../filebackend/filejournal/DBFileJournal.php | 16 ++++++++++++ .../filebackend/filejournal/FileJournal.php | 26 +++++++++++++++++++ maintenance/syncFileBackend.php | 7 ++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/includes/filebackend/filejournal/DBFileJournal.php b/includes/filebackend/filejournal/DBFileJournal.php index 44c6567b6a..73f29a9549 100644 --- a/includes/filebackend/filejournal/DBFileJournal.php +++ b/includes/filebackend/filejournal/DBFileJournal.php @@ -99,6 +99,22 @@ class DBFileJournal extends FileJournal { ); } + /** + * @see FileJournal::doGetPositionAtTime() + * @param $time integer|string timestamp + * @return integer|false + */ + protected function doGetPositionAtTime( $time ) { + $dbw = $this->getMasterDB(); + + $encTimestamp = $dbw->addQuotes( $dbw->timestamp( $time ) ); + return $dbw->selectField( 'filejournal', 'fj_id', + array( 'fj_backend' => $this->backend, "fj_timestamp <= $encTimestamp" ), + __METHOD__, + array( 'ORDER BY' => 'fj_timestamp DESC' ) + ); + } + /** * @see FileJournal::doGetChangeEntries() * @return Array diff --git a/includes/filebackend/filejournal/FileJournal.php b/includes/filebackend/filejournal/FileJournal.php index d99384db1b..b0f39c3be4 100644 --- a/includes/filebackend/filejournal/FileJournal.php +++ b/includes/filebackend/filejournal/FileJournal.php @@ -125,6 +125,23 @@ abstract class FileJournal { */ abstract protected function doGetCurrentPosition(); + /** + * Get the position ID of the latest journal entry at some point in time + * + * @param $time integer|string timestamp + * @return integer|false + */ + final public function getPositionAtTime( $time ) { + return $this->doGetPositionAtTime( $time ); + } + + /** + * @see FileJournal::getPositionAtTime() + * @param $time integer|string timestamp + * @return integer|false + */ + abstract protected function doGetPositionAtTime( $time ); + /** * Get an array of file change log entries. * A starting change ID and/or limit can be specified. @@ -201,6 +218,15 @@ class NullFileJournal extends FileJournal { return false; } + /** + * @see FileJournal::doGetPositionAtTime() + * @param $time integer|string timestamp + * @return integer|false + */ + protected function doGetPositionAtTime( $time ) { + return false; + } + /** * @see FileJournal::doGetChangeEntries() * @return Array diff --git a/maintenance/syncFileBackend.php b/maintenance/syncFileBackend.php index e279ccb1f3..a93ad7992d 100644 --- a/maintenance/syncFileBackend.php +++ b/maintenance/syncFileBackend.php @@ -39,6 +39,7 @@ class SyncFileBackend extends Maintenance { $this->addOption( 'end', 'Ending journal ID', false, true ); $this->addOption( 'posdir', 'Directory to read/record journal positions', false, true ); $this->addOption( 'posdump', 'Just dump current journal position into the position dir.' ); + $this->addOption( 'postime', 'For position dumps, get the ID at this time', false, true ); $this->addOption( 'verbose', 'Verbose mode', false, false, 'v' ); $this->setBatchSize( 50 ); } @@ -54,7 +55,11 @@ class SyncFileBackend extends Maintenance { if ( !$this->hasOption( 'posdir' ) ) { $this->error( "Param posdir required!", 1 ); } - $id = (int)$src->getJournal()->getCurrentPosition(); // default to 0 + if ( $this->hasOption( 'postime' ) ) { + $id = (int)$src->getJournal()->getPositionAtTime( $this->getOption( 'postime' ) ); + } else { + $id = (int)$src->getJournal()->getCurrentPosition(); + } $this->output( "Current journal position is $id.\n" ); if ( file_put_contents( $posFile, $id, LOCK_EX ) !== false ) { $this->output( "Saved journal position file.\n" ); -- 2.20.1