maintenance: Sanity check that --replicadb isn't using the master in sql.php
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 22 Aug 2019 00:35:02 +0000 (17:35 -0700)
committerKrinkle <krinklemail@gmail.com>
Sat, 24 Aug 2019 19:50:36 +0000 (19:50 +0000)
Change-Id: I0b7fd896c88b06cbc17b31b1ae2b9cb8e375da1b

maintenance/sql.php

index 21d8b2d..612c092 100644 (file)
@@ -67,7 +67,7 @@ class MwSql extends Maintenance {
                $replicaDB = $this->getOption( 'replicadb', $this->getOption( 'slave', '' ) );
                if ( $replicaDB === 'any' ) {
                        $index = DB_REPLICA;
-               } elseif ( $replicaDB != '' ) {
+               } elseif ( $replicaDB !== '' ) {
                        $index = null;
                        $serverCount = $lb->getServerCount();
                        for ( $i = 0; $i < $serverCount; ++$i ) {
@@ -76,7 +76,7 @@ class MwSql extends Maintenance {
                                        break;
                                }
                        }
-                       if ( $index === null ) {
+                       if ( $index === null || $index === $lb->getWriterIndex() ) {
                                $this->fatalError( "No replica DB server configured with the name '$replicaDB'." );
                        }
                } else {