Use CONN_TRX_AUTO in WikiPage speculative revision ID callback
authorAaron Schulz <aschulz@wikimedia.org>
Sat, 24 Mar 2018 13:49:14 +0000 (06:49 -0700)
committerKrinkle <krinklemail@gmail.com>
Mon, 23 Apr 2018 17:24:30 +0000 (17:24 +0000)
This increases the odds of seeing newer data and not guessing a
wrong revision ID due to getting raced out between stash and save.

Change-Id: Icf0f9b9c4d559f4ddf05a4ca8679e3c4dca5620a

includes/page/WikiPage.php

index d4a17c8..cfeb331 100644 (file)
@@ -2117,7 +2117,12 @@ class WikiPage implements Page, IDBAccessObject {
                                        : DB_REPLICA; // T154554
 
                                $edit->popts->setSpeculativeRevIdCallback( function () use ( $dbIndex ) {
-                                       return 1 + (int)wfGetDB( $dbIndex )->selectField(
+                                       $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
+                                       // Use a fresh connection in order to see the latest data, by avoiding
+                                       // stale data from REPEATABLE-READ snapshots.
+                                       $db = $lb->getConnectionRef( $dbIndex, [], false, $lb::CONN_TRX_AUTO );
+
+                                       return 1 + (int)$db->selectField(
                                                'revision',
                                                'MAX(rev_id)',
                                                [],