Page MenuHomePhabricator

addWiki.php throws Wikimedia\Assert\PreconditionException from line 58 of /srv/mediawiki/php-1.36.0-wmf.31/includes/dao/WikiAwareEntityTrait.php: Expected User to belong to 'altwiki', but it belongs to the local wiki on writing main page
Closed, ResolvedPublic

Description

See stacktrace below:

1[urbanecm@mwmaint1002 ~]$ mwscript extensions/WikimediaMaintenance/addWiki.php --wiki=muswiki alt wikipedia altwiki alt.wikipedia.org
2Deprecated: Premature access to service container [Called from Maintenance::finalSetup in /srv/mediawiki/php-1.36.0-wmf.31/maintenance/includes/Maintenance.php at line 1216] in /srv/mediawiki/php-1.36.0-wmf.31/includes/debug/MWDebug.php on line 376
3Deprecated: Premature access to service 'HookContainer' [Called from MediaWiki\MediaWikiServices::getInstance in /srv/mediawiki/php-1.36.0-wmf.31/includes/MediaWikiServices.php at line 248] in /srv/mediawiki/php-1.36.0-wmf.31/includes/debug/MWDebug.php on line 376
4Deprecated: Premature access to service 'ObjectFactory' [Called from Wikimedia\Services\ServiceContainer::{closure} in /srv/mediawiki/php-1.36.0-wmf.31/includes/ServiceWiring.php at line 516] in /srv/mediawiki/php-1.36.0-wmf.31/includes/debug/MWDebug.php on line 376
5Creating database altwiki for alt.wikipedia (алтай тил)
6Initialising tables
7Initialising external storage cluster26...
8Initialising external storage cluster27...
9Writing main page to Тӧс_бӱк
10Wikimedia\Assert\PreconditionException from line 58 of /srv/mediawiki/php-1.36.0-wmf.31/includes/dao/WikiAwareEntityTrait.php: Expected User to belong to 'altwiki', but it belongs to the local wiki
11#0 /srv/mediawiki/php-1.36.0-wmf.31/includes/user/User.php(2089): User->assertWiki('altwiki')
12#1 /srv/mediawiki/php-1.36.0-wmf.31/includes/Revision/RevisionStore.php(618): User->getUserId('altwiki')
13#2 /srv/mediawiki/php-1.36.0-wmf.31/includes/Revision/RevisionStore.php(552): MediaWiki\Revision\RevisionStore->insertIpChangesRow(Object(Wikimedia\Rdbms\DatabaseMysqli), Object(User), Object(MediaWiki\Revision\MutableRevisionRecord), 1)
14#3 /srv/mediawiki/php-1.36.0-wmf.31/includes/Revision/RevisionStore.php(451): MediaWiki\Revision\RevisionStore->insertRevisionInternal(Object(MediaWiki\Revision\MutableRevisionRecord), Object(Wikimedia\Rdbms\DatabaseMysqli), Object(User), Object(CommentStoreComment), Object(Title), 1, 0) #4 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/database/Database.php(4500): MediaWiki\Revision\RevisionStore->MediaWiki\Revision\{closure}(Object(Wikimedia\Rdbms\DatabaseMysqli), 'MediaWiki\\Revis...') #5 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/database/DBConnRef.php(68): Wikimedia\Rdbms\Database->doAtomicSection('MediaWiki\\Revis...', Object(Closure)) #6 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/database/DBConnRef.php(641): Wikimedia\Rdbms\DBConnRef->__call('doAtomicSection', Array) #7 /srv/mediawiki/php-1.36.0-wmf.31/includes/Revision/RevisionStore.php(453): Wikimedia\Rdbms\DBConnRef->doAtomicSection('MediaWiki\\Revis...', Object(Closure)) #8 /srv/mediawiki/php-1.36.0-wmf.31/includes/Storage/PageUpdater.php(1236): MediaWiki\Revision\RevisionStore->insertRevisionOn(Object(MediaWiki\Revision\MutableRevisionRecord), Object(Wikimedia\Rdbms\DBConnRef))#9 /srv/mediawiki/php-1.36.0-wmf.31/includes/Storage/PageUpdater.php(803): MediaWiki\Storage\PageUpdater->doCreate(Object(CommentStoreComment), Object(User), 65)
15#10 /srv/mediawiki/php-1.36.0-wmf.31/includes/page/WikiPage.php(2076): MediaWiki\Storage\PageUpdater->saveRevision(Object(CommentStoreComment), 65) #11 /srv/mediawiki/php-1.36.0-wmf.31/includes/page/WikiPage.php(1928): WikiPage->doUserEditContent(Object(WikitextContent), Object(User), Object(CommentStoreComment), 65, false, Array, 0) #12 /srv/mediawiki/php-1.36.0-wmf.31/extensions/WikimediaMaintenance/addWiki.php(165): WikiPage->doEditContent(Object(WikitextContent), '', 65) #13 /srv/mediawiki/php-1.36.0-wmf.31/maintenance/doMaintenance.php(106): AddWiki->execute() #14 /srv/mediawiki/php-1.36.0-wmf.31/extensions/WikimediaMaintenance/addWiki.php(450): require_once('/srv/mediawiki/...') #15 /srv/mediawiki/multiversion/MWScript.php(101): require_once('/srv/mediawiki/...') #16 {main}
16[5838f2e9a8b97a8b137ebb77] [no req] Wikimedia\Rdbms\DBTransactionError: Explicit transaction still active. A caller may have caught an error. Open transactions: MediaWiki\Storage\PageUpdater::doCreate
17Backtrace:
18from /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/database/Database.php(1523)
19#0 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1728): Wikimedia\Rdbms\Database->assertNoOpenTransactions()
20#1 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/loadbalancer/LoadBalancer.php(2241): Wikimedia\Rdbms\LoadBalancer::Wikimedia\Rdbms\{closure}(Wikimedia\Rdbms\DatabaseMysqli)
21#2 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/loadbalancer/LoadBalancer.php(1747): Wikimedia\Rdbms\LoadBalancer->forEachOpenMasterConnection(Closure)
22#3 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/lbfactory/LBFactory.php(249): Wikimedia\Rdbms\LoadBalancer->approveMasterChanges(array, string, integer)
23#4 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/lbfactory/LBFactoryMulti.php(222): Wikimedia\Rdbms\LBFactory::Wikimedia\Rdbms\{closure}(Wikimedia\Rdbms\LoadBalancer, string, array)
24#5 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/lbfactory/LBFactory.php(251): Wikimedia\Rdbms\LBFactoryMulti->forEachLB(Closure, array)
25#6 /srv/mediawiki/php-1.36.0-wmf.31/includes/libs/rdbms/lbfactory/LBFactory.php(310): Wikimedia\Rdbms\LBFactory->forEachLBCallMethod(string, array)
26#7 /srv/mediawiki/php-1.36.0-wmf.31/maintenance/includes/Maintenance.php(1269): Wikimedia\Rdbms\LBFactory->commitMasterChanges(string)
27#8 /srv/mediawiki/php-1.36.0-wmf.31/maintenance/doMaintenance.php(128): Maintenance->shutdown()
28#9 /srv/mediawiki/php-1.36.0-wmf.31/extensions/WikimediaMaintenance/addWiki.php(450): require_once(string)
29#10 /srv/mediawiki/multiversion/MWScript.php(101): require_once(string)
30#11 {main}
31[urbanecm@mwmaint1002 ~]$

Event Timeline

Change 666373 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/core@master] PageUpdater: use UserIdentity where possible

https://gerrit.wikimedia.org/r/666373

addWiki calls redefineService() to force the 'RevisionStore' service to use an explicit target DB domain (rather false for the default local database). This conflicts with the fact that User are not cross-wiki aware, and Edits can't use UserIdentity yet.

Since addWiki() already uses redefineLocalDomain() to change the local default database to the target wiki, this should not be needed. The reason we do it apparently is T200471. So the real solution here would be to fix T200471 and remove the redefineService() call which was added in the context of T212881.

Change 666373 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/core@master] PageUpdater: use UserIdentity where possible

https://gerrit.wikimedia.org/r/666373

This patch works towards allowing edits to be made with a UserIdentity, which could be made cross-wiki aware. This by itself will however not resolve this issue, and new similar inconsistencies are likely to pop up again as long as we use the redefineService() hack described above.

uh, how do I even run this locally to try and debug?...

Change 666382 had a related patch set uploaded (by Daniel Kinzler; owner: Daniel Kinzler):
[mediawiki/core@master] Don't use getUserId in RevisionStore.

https://gerrit.wikimedia.org/r/666382

uh, how do I even run this locally to try and debug?...

It's impossible to run addWiki.php locally in its full form. You need to copy and paste the affected part of the maintenance script elsewhere (possibly a temporary maintenance script), try it there, and then copy it back and commit (or, delete everything but the part you're debugging). Yes, it's bad, yes, we should have a better way to debug addWiki, but there's sadly no other way now.

Right now, I'm pretty sure only the part wrapped with the if is broken, see https://github.com/wikimedia/mediawiki-extensions-WikimediaMaintenance/blob/master/addWiki.php#L161-L173. I recommend to copy that elsewhere, and test that way (note it has to work from a different wiki context; ie. you need to have multiwiki setup locally, and make php yourTempScript.php --wiki=aawiki to make an edit on bbwiki (assuming $dbName in addWiki.php is bbwiki).

Feel free to ping me or Amir to ask for advice, we'll be happy to help :).

Change 666382 merged by jenkins-bot:
[mediawiki/core@master] Don't use getUserId in RevisionStore.

https://gerrit.wikimedia.org/r/666382

I think the best way to test it is to actually run it for real in production. In principle, the script should be re-runnable if it fails halfway through. But don't use altwiki since that wiki seems to be fully set up and working fine. Which wikis need to be created?

I think the best way to test it is to actually run it for real in production.

I bet you know it, but I note it anyway: People should not run it unless they really know what they're doing.

In principle, the script should be re-runnable if it fails halfway through.

I agree it should, but it definitely is not safe to re-run. If a wiki creation fails for any reason, it's often necessary to either manually copy&paste parts of addWiki to shell.php, or livehack addWiki . Happened to me several times, and I'm sure @Ladsgroup has his own nice experiences with the script.

By quickly looking at the script, stuff that runs in https://github.com/wikimedia/mediawiki-extensions-WikimediaMaintenance/blob/master/addWiki.php#L239 will probably fail when script is executed again, among other things.

But don't use altwiki since that wiki seems to be fully set up and working fine. Which wikis need to be created?

I live-hacked addWiki.php when I noticed the exception, to finish the wiki creation. No wiki is pending addWiki.php now. There is T275803 pending creation, but that needs DNS patch merged at the very least.

I will definitely let you know if it _isn't_ fixed next time I create a wiki :-).

Yes. This script is not idempotent (which it should be). We will hopefully create a new wiki soonish and can try again. I said before, I think this script should be extremely modular.

I think the best way to test it is to actually run it for real in production.

I bet you know it, but I note it anyway: People should not run it unless they really know what they're doing.

I'm saying that @daniel should run it, since he was asking about how to test it. Or failing that, some other developer who is very familiar with the script. If it doesn't work, edit it live on the server, insert debugging statements, whatever you need to do to isolate the problem and make it work. Probably the worst thing that could happen is that you break the new wiki such that it takes some time to clean up. It's unlikely to break anything important.

If there's no wiki ready for creation, we could make a test wiki. But I see that @Dzahn just did the DNS for T275803, so that's ready to go now.

The checklist on the ticket (updated automatically) says it can't be created yet given that some messages related to interwiki links is not deployed yet. We can create the wiki at earliest next Monday. Also I'm a little bit hesitant to test this on production. We usually test it on beat cluster. Do we have a new wiki for creation in beta cluster?

Ladsgroup assigned this task to daniel.

We just created a wiki. This is fixed. There are some warnings for now but that should go to another ticket.