Merge "Add alternative DB_* class constants to ILoadBalancer"
[lhc/web/wiklou.git] / includes / libs / rdbms / lbfactory / LBFactory.php
index cf9a298..fd89f33 100644 (file)
@@ -157,6 +157,11 @@ abstract class LBFactory {
         * Create a new load balancer object. The resulting object will be untracked,
         * not chronology-protected, and the caller is responsible for cleaning it up.
         *
+        * This method is for only advanced usage and callers should almost always use
+        * getMainLB() instead. This method can be useful when a table is used as a key/value
+        * store. In that cases, one might want to query it in autocommit mode (DBO_TRX off)
+        * but still use DBO_TRX transaction rounds on other tables.
+        *
         * @param bool|string $domain Domain ID, or false for the current domain
         * @return ILoadBalancer
         */
@@ -175,11 +180,16 @@ abstract class LBFactory {
         * untracked, not chronology-protected, and the caller is responsible for
         * cleaning it up.
         *
+        * This method is for only advanced usage and callers should almost always use
+        * getExternalLB() instead. This method can be useful when a table is used as a
+        * key/value store. In that cases, one might want to query it in autocommit mode
+        * (DBO_TRX off) but still use DBO_TRX transaction rounds on other tables.
+        *
         * @param string $cluster External storage cluster, or false for core
         * @param bool|string $domain Domain ID, or false for the current domain
         * @return ILoadBalancer
         */
-       abstract protected function newExternalLB( $cluster, $domain = false );
+       abstract public function newExternalLB( $cluster, $domain = false );
 
        /**
         * Get a cached (tracked) load balancer for external storage
@@ -410,14 +420,14 @@ abstract class LBFactory {
         * This makes sense when lag being waiting on is caused by the code that does this check.
         * In that case, setting "ifWritesSince" can avoid the overhead of waiting for clusters
         * that were not changed since the last wait check. To forcefully wait on a specific cluster
-        * for a given wiki, use the 'wiki' parameter. To forcefully wait on an "external" cluster,
+        * for a given domain, use the 'domain' parameter. To forcefully wait on an "external" cluster,
         * use the "cluster" parameter.
         *
         * Never call this function after a large DB write that is *still* in a transaction.
         * It only makes sense to call this after the possible lag inducing changes were committed.
         *
         * @param array $opts Optional fields that include:
-        *   - wiki : wait on the load balancer DBs that handles the given wiki
+        *   - domain : wait on the load balancer DBs that handles the given domain ID
         *   - cluster : wait on the given external load balancer DBs
         *   - timeout : Max wait time. Default: ~60 seconds
         *   - ifWritesSince: Only wait if writes were done since this UNIX timestamp
@@ -426,19 +436,23 @@ abstract class LBFactory {
         */
        public function waitForReplication( array $opts = [] ) {
                $opts += [
-                       'wiki' => false,
+                       'domain' => false,
                        'cluster' => false,
                        'timeout' => 60,
                        'ifWritesSince' => null
                ];
 
+               if ( $opts['domain'] === false && isset( $opts['wiki'] ) ) {
+                       $opts['domain'] = $opts['wiki']; // b/c
+               }
+
                // Figure out which clusters need to be checked
                /** @var ILoadBalancer[] $lbs */
                $lbs = [];
                if ( $opts['cluster'] !== false ) {
                        $lbs[] = $this->getExternalLB( $opts['cluster'] );
-               } elseif ( $opts['wiki'] !== false ) {
-                       $lbs[] = $this->getMainLB( $opts['wiki'] );
+               } elseif ( $opts['domain'] !== false ) {
+                       $lbs[] = $this->getMainLB( $opts['domain'] );
                } else {
                        $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$lbs ) {
                                $lbs[] = $lb;
@@ -515,7 +529,9 @@ abstract class LBFactory {
         */
        public function getEmptyTransactionTicket( $fname ) {
                if ( $this->hasMasterChanges() ) {
-                       $this->queryLogger->error( __METHOD__ . ": $fname does not have outer scope." );
+                       $this->queryLogger->error( __METHOD__ . ": $fname does not have outer scope.\n" .
+                               ( new RuntimeException() )->getTraceAsString() );
+
                        return null;
                }
 
@@ -535,7 +551,9 @@ abstract class LBFactory {
         */
        public function commitAndWaitForReplication( $fname, $ticket, array $opts = [] ) {
                if ( $ticket !== $this->ticket ) {
-                       $this->perfLogger->error( __METHOD__ . ": $fname does not have outer scope." );
+                       $this->perfLogger->error( __METHOD__ . ": $fname does not have outer scope.\n" .
+                               ( new RuntimeException() )->getTraceAsString() );
+
                        return;
                }