When calling in MW 1.31.1:
\MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getExternalLB('master')->getConnection(DB_MASTER);It returns a load balancer with the database of the local wiki instead of the correct(global/central) database defined in $wgExternalServers. The attached images are annotated to show the issue. This functionality works correctly in MW 1.29, but something has happened since then that causes it to get the incorrect database.
I spoke with legoktm on the #mediawiki IRC channel. He referenced a selectDB() issue that was fixed in the mw-1.32-wmf branches. I back ported the MW 1.32 "includes/libs/rdbms/" to test and unfortunately that did not solve the issue.
The scope is that it breaks internal extensions on Gamepedia/Hydra in addition to the popular Extension:AbuseFilter and Extension:Echo(EchoDbFactory).
$wgExternalServers:
$wgExternalServers = [ 'master' => [ [ 'host' => '127.0.0.1', 'dbname' => 'wikiauth', 'user' => 'bobdole', 'password' => 'bobdole', 'type' => $wgDBtype, 'load' => 1 ] ] ];
Relevant code:
/**
* Get the global database connection.
*
* @access public
* @param integer $dbtype either DB_MASTER or DB_SLAVE.
* @return mixed DatabaseBase or false on connection error.
*/
static public function getMasterDatabase($dbtype = DB_MASTER) {
global $wgGlobalBlockingDatabase;
if (self::$db !== null) {
return self::$db;
}
try {
self::$db = \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->getExternalLB($wgGlobalBlockingDatabase)->getConnection($dbtype);
return self::$db;
} catch (Exception $e) {
return false;
}
}[6682e743eeada4afb76ad73f] /Applejack_Wiki Wikimedia\Rdbms\DBQueryError from line 1458 of includes/libs/rdbms/database/Database.php: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading?
Query: SELECT * FROM `global_block` WHERE global_id = '87049'
Function: GlobalBlock::load
Error: 1146 Table 'applejack_gamepedia.global_block' doesn't exist (127.0.0.1)
Backtrace:
#0 includes/libs/rdbms/database/Database.php(1428): Wikimedia\Rdbms\Database->makeQueryException(string, integer, string, string)
#1 includes/libs/rdbms/database/Database.php(1198): Wikimedia\Rdbms\Database->reportQueryError(string, integer, string, string, boolean)
#2 includes/libs/rdbms/database/Database.php(1655): Wikimedia\Rdbms\Database->query(string, string)
#3 extensions/GlobalBlock/classes/GlobalBlock.php(212): Wikimedia\Rdbms\Database->select(array, array, array, string)
#4 extensions/GlobalBlock/classes/GlobalBlock.php(147): GlobalBlock->load()
#5 extensions/GlobalBlock/GlobalBlock.hooks.php(89): GlobalBlock::newFromUser(User)
#6 includes/Hooks.php(177): GlobalBlockHooks::onGetBlockedStatus(User)
#7 includes/Hooks.php(205): Hooks::callHook(string, array, array, NULL)
#8 includes/user/User.php(1886): Hooks::run(string, array)
#9 includes/user/User.php(2224): User->getBlockedStatus(boolean)
#10 includes/user/User.php(2214): User->getBlock(boolean)
#11 includes/Title.php(2572): User->isBlocked()
#12 includes/Title.php(2737): Title->checkUserBlock(string, User, array, string, boolean)
#13 includes/Title.php(2114): Title->getUserPermissionsErrorsInternal(string, User, string, boolean)
#14 extensions/ApprovedRevs/includes/ApprovedRevs_body.php(165): Title->userCan(string, User)
#15 extensions/ApprovedRevs/includes/ApprovedRevs.hooks.php(476): ApprovedRevs::checkPermission(User, Title, string)
#16 includes/Hooks.php(177): ApprovedRevsHooks::setSubtitle(Article, string)
#17 includes/Hooks.php(205): Hooks::callHook(string, array, array, NULL)
#18 includes/page/Article.php(1322): Hooks::run(string, array)
#19 includes/page/Article.php(566): Article->setOldSubtitle(string)
#20 includes/actions/ViewAction.php(68): Article->view()
#21 includes/MediaWiki.php(500): ViewAction->show()
#22 includes/MediaWiki.php(294): MediaWiki->performAction(Article, Title)
#23 includes/MediaWiki.php(861): MediaWiki->performRequest()
#24 includes/MediaWiki.php(524): MediaWiki->main()
#25 index.php(42): MediaWiki->run()
#26 {main}
