Make Maintenance::commitTransaction() do slave wait checks
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 31 Dec 2015 23:30:16 +0000 (15:30 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 31 Dec 2015 23:30:16 +0000 (15:30 -0800)
This makes it less likely to be forgotten in scripts.

Change-Id: I9b939dcda8d6191a2a5ee3b3b50d2ec950dc0402

maintenance/Maintenance.php

index e90812d..291920b 100644 (file)
@@ -109,6 +109,9 @@ abstract class Maintenance {
         */
        private $mDb = null;
 
+       /** @var float UNIX timestamp */
+       private $lastSlaveWait = 0.0;
+
        /**
         * Used when creating separate schema files.
         * @var resource
@@ -1178,21 +1181,27 @@ abstract class Maintenance {
        }
 
        /**
-        * Commit a transcation on a DB
+        * Commit the transcation on a DB handle and wait for slaves to catch up
         *
         * This method makes it clear that commit() is called from a maintenance script,
         * which has outermost scope. This is safe, unlike $dbw->commit() called in other places.
         *
         * @param IDatabase $dbw
         * @param string $fname Caller name
+        * @return bool Whether the slave wait succeeded
         * @since 1.27
         */
        protected function commitTransaction( IDatabase $dbw, $fname ) {
                $dbw->commit( $fname );
+
+               $ok = wfWaitForSlaves( $this->lastSlaveWait, false, '*', 30 );
+               $this->lastSlaveWait = microtime( true );
+
+               return $ok;
        }
 
        /**
-        * Rollback a transcation on a DB
+        * Rollback the transcation on a DB handle
         *
         * This method makes it clear that rollback() is called from a maintenance script,
         * which has outermost scope. This is safe, unlike $dbw->rollback() called in other places.