Page MenuHomePhabricator

Cannot call getMasterPos() in CI: Access denied; you need (at least one of) the SUPER, REPLICATION CLIENT privilege(s) for this operation / Query: SHOW MASTER STATUS
Closed, ResolvedPublic

Description

Blocks the real change I656ee86671; tested with fake change Ie35e654d3c which adds a test that calls $this->db->getMasterPos() without doing anything else. Console output:

16:29:11 There was 1 error:
16:29:11 
16:29:11 1) GetMasterPosTest::testGetMasterPos
16:29:11 Wikimedia\Rdbms\DBQueryError: Error 1227: Access denied; you need (at least one of) the SUPER, REPLICATION CLIENT privilege(s) for this operation (localhost:/workspace/db/quibble-mysql-ivdf35z3/socket)
16:29:11 Function: Wikimedia\Rdbms\DatabaseMysqlBase::getMasterPos
16:29:11 Query: SHOW MASTER STATUS

See also T144247, where a similar thing happened four years ago and ultimately seems to have solved itself.

Event Timeline

Might also belong in ci-test-error and/or Continuous-Integration-Infrastructure, not sure. From a codesearch for getMasterPos(), it seems plausible that this issue could have existed for a while already without being noticed (it seems the method isn’t called very often and some of the places where it is called might not be reached during CI tests).

The reason the CI job fails is the replication rights are not provided. It is a global permission to the database and is not part of the GRANT ALL we do.

The reason it surfaces is the code uses loadBalancer->waitForAll() which is the low level implementation and actually requires those rights. Other methods are smarter and manage to get there are now attached replica to wait for and would return immediately. From maintenance/includes/Maintenance.php which does batch handling as well:

$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$lbFactory->waitForReplication();

I have left some hints on the change.


We can check whether we will want Quibble to setup a replication database (and thus start a 2nd database). Though in practice I don't think that has ever been needed/requested.

We can check whether we will want Quibble to setup a replication database (and thus start a 2nd database). Though in practice I don't think that has ever been needed/requested.

I think this would be pretty useful, as I think integration and Selenium tests would end up surfacing some bugs before they hit production. I believe a fair number of developers use only a single database setup in their local environment (e.g. this is the default in the Vagrant setup as well as core's MediaWiki-Docker setup, although it's fairly easy to change to use replication) so it's harder to see issues that can happen when replication is involved.

hashar claimed this task.
hashar added a subscriber: ItamarWMDE.

I have determined the issue to come from $this->loadBalancer->waitForAll( $dbw->getMasterPos() ); which would always check for replication. Changing to the higher level method $this->lbFactory->waitForReplication(); has some short circuit logic to do not bother checking replication when it is not setup.

The change has been amended by @ItamarWMDE and that fixed it:

https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Wikibase/+/602195/7..8/client/includes/ChangeModification/ChangeVisibilityNotificationJob.php