From a7cb31718818113127d92f126f7355bf1c442632 Mon Sep 17 00:00:00 2001 From: Kevin Israel Date: Wed, 19 Aug 2015 06:26:01 -0400 Subject: [PATCH] Remove maintenance script fixSlaveDesync.php Though this script was run on Wikimedia sites years ago (see T8399), there are enough reasons to doubt it will be run again: * There is a hardcoded maximum page_id value, which would have to be changed or removed before reuse. * It scans the entire page table in a single SELECT query and stores all values of page_id and page_latest in a PHP array, which might not be feasible on a large wiki. * It writes directly to slaves. In contrast, the manual page for pt-table-sync (from Percona Toolkit) says in general, "[...] it always makes the changes on the replication master, never the replication slave directly. This is in general the only safe way to bring a replica back in sync [...]". * It only works on the page/revision/text tables. In contrast, pt-table-sync can work on any table having a primary key. * It does try to detect whether revisions are missing on the master (instead of on the slave). However, this won't work because of a bug introduced in r91243 / bb1df74f8715 (it actually queries the master twice and puts the second result set in $slaveIDs). Change-Id: I85c98821af308abf7dde8068d7cbca17d06b1362 --- RELEASE-NOTES-1.26 | 1 + autoload.php | 1 - maintenance/fixSlaveDesync.php | 246 --------------------------------- 3 files changed, 1 insertion(+), 247 deletions(-) delete mode 100644 maintenance/fixSlaveDesync.php diff --git a/RELEASE-NOTES-1.26 b/RELEASE-NOTES-1.26 index 1b468a1659..19e3eaa97d 100644 --- a/RELEASE-NOTES-1.26 +++ b/RELEASE-NOTES-1.26 @@ -154,6 +154,7 @@ changes to languages because of Phabricator reports. * BREAKING CHANGE: mediawiki.legacy.ajax has been removed, following a lengthy deprecation period. * The ScopedPHPTimeout class was removed. +* Removed maintenance script fixSlaveDesync.php. == Compatibility == diff --git a/autoload.php b/autoload.php index b67fb8f6fe..48e0b8824a 100644 --- a/autoload.php +++ b/autoload.php @@ -448,7 +448,6 @@ $wgAutoloadLocalClasses = array( 'FixBug20757' => __DIR__ . '/maintenance/storage/fixBug20757.php', 'FixDoubleRedirects' => __DIR__ . '/maintenance/fixDoubleRedirects.php', 'FixExtLinksProtocolRelative' => __DIR__ . '/maintenance/fixExtLinksProtocolRelative.php', - 'FixSlaveDesync' => __DIR__ . '/maintenance/fixSlaveDesync.php', 'FixTimestamps' => __DIR__ . '/maintenance/fixTimestamps.php', 'FixUserRegistration' => __DIR__ . '/maintenance/fixUserRegistration.php', 'ForeignAPIFile' => __DIR__ . '/includes/filerepo/file/ForeignAPIFile.php', diff --git a/maintenance/fixSlaveDesync.php b/maintenance/fixSlaveDesync.php deleted file mode 100644 index a5418ced66..0000000000 --- a/maintenance/fixSlaveDesync.php +++ /dev/null @@ -1,246 +0,0 @@ -mDescription = ""; - } - - public function getDbType() { - return Maintenance::DB_ADMIN; - } - - public function execute() { - $this->slaveIndexes = array(); - $serverCount = wfGetLB()->getServerCount(); - for ( $i = 1; $i < $serverCount; $i++ ) { - if ( wfGetLB()->isNonZeroLoad( $i ) ) { - $this->slaveIndexes[] = $i; - } - } - - if ( $this->hasArg() ) { - $this->desyncFixPage( $this->getArg() ); - } else { - $corrupt = $this->findPageLatestCorruption(); - foreach ( $corrupt as $id => $dummy ) { - $this->desyncFixPage( $id ); - } - } - } - - /** - * Find all pages that have a corrupted page_latest - * @return array - */ - private function findPageLatestCorruption() { - $desync = array(); - $n = 0; - $dbw = wfGetDB( DB_MASTER ); - $masterIDs = array(); - $res = $dbw->select( - 'page', - array( 'page_id', 'page_latest' ), - array( 'page_id<6054123' ), - __METHOD__ - ); - $this->output( "Number of pages: " . $res->numRows() . "\n" ); - foreach ( $res as $row ) { - $masterIDs[$row->page_id] = $row->page_latest; - if ( !( ++$n % 10000 ) ) { - $this->output( "$n\r" ); - } - } - $this->output( "\n" ); - - foreach ( $this->slaveIndexes as $i ) { - $db = wfGetDB( $i ); - $res = $db->select( - 'page', - array( 'page_id', 'page_latest' ), - array( 'page_id<6054123' ), - __METHOD__ - ); - foreach ( $res as $row ) { - if ( isset( $masterIDs[$row->page_id] ) && $masterIDs[$row->page_id] != $row->page_latest ) { - $desync[$row->page_id] = true; - $this->output( $row->page_id . "\t" ); - } - } - } - $this->output( "\n" ); - - return $desync; - } - - /** - * Fix a broken page entry - * @param int $pageID The page_id to fix - */ - private function desyncFixPage( $pageID ) { - # Check for a corrupted page_latest - $dbw = wfGetDB( DB_MASTER ); - $dbw->begin( __METHOD__ ); - $realLatest = $dbw->selectField( 'page', 'page_latest', array( 'page_id' => $pageID ), - __METHOD__, 'FOR UPDATE' ); - # list( $masterFile, $masterPos ) = $dbw->getMasterPos(); - $found = false; - foreach ( $this->slaveIndexes as $i ) { - $db = wfGetDB( $i ); - /* - if ( !$db->masterPosWait( $masterFile, $masterPos, 10 ) ) { - $this->output( "Slave is too lagged, aborting\n" ); - $dbw->commit( __METHOD__ ); - sleep(10); - return; - }*/ - $latest = $db->selectField( 'page', 'page_latest', array( 'page_id' => $pageID ), __METHOD__ ); - $max = $db->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ ); - if ( $latest != $realLatest && $realLatest < $max ) { - $this->output( "page_latest corrupted in page $pageID, server $i\n" ); - $found = true; - break; - } - } - if ( !$found ) { - $this->output( "page_id $pageID seems fine\n" ); - $dbw->commit( __METHOD__ ); - - return; - } - - # Find the missing revisions - $res = $dbw->select( 'revision', array( 'rev_id' ), array( 'rev_page' => $pageID ), - __METHOD__, 'FOR UPDATE' ); - $masterIDs = array(); - foreach ( $res as $row ) { - $masterIDs[] = $row->rev_id; - } - - $res = $dbw->select( 'revision', array( 'rev_id' ), array( 'rev_page' => $pageID ), __METHOD__ ); - $slaveIDs = array(); - foreach ( $res as $row ) { - $slaveIDs[] = $row->rev_id; - } - if ( count( $masterIDs ) < count( $slaveIDs ) ) { - $missingIDs = array_diff( $slaveIDs, $masterIDs ); - if ( count( $missingIDs ) ) { - $this->output( "Found " . count( $missingIDs ) - . " lost in master, copying from slave... " ); - $dbFrom = $dbw; - $found = true; - $toMaster = true; - } else { - $found = false; - } - } else { - $missingIDs = array_diff( $masterIDs, $slaveIDs ); - if ( count( $missingIDs ) ) { - $this->output( "Found " . count( $missingIDs ) - . " missing revision(s), copying from master... " ); - $dbFrom = $dbw; - $found = true; - $toMaster = false; - } else { - $found = false; - } - } - - if ( $found ) { - foreach ( $missingIDs as $rid ) { - $this->output( "$rid " ); - # Revision - $row = $dbFrom->selectRow( 'revision', '*', array( 'rev_id' => $rid ), __METHOD__ ); - if ( $toMaster ) { - $id = $dbw->selectField( 'revision', 'rev_id', array( 'rev_id' => $rid ), - __METHOD__, 'FOR UPDATE' ); - if ( $id ) { - $this->output( "Revision already exists\n" ); - $found = false; - break; - } else { - $dbw->insert( 'revision', get_object_vars( $row ), __METHOD__, 'IGNORE' ); - } - } else { - foreach ( $this->slaveIndexes as $i ) { - $db = wfGetDB( $i ); - $db->insert( 'revision', get_object_vars( $row ), __METHOD__, 'IGNORE' ); - } - } - - # Text - $row = $dbFrom->selectRow( 'text', '*', array( 'old_id' => $row->rev_text_id ), __METHOD__ ); - if ( $toMaster ) { - $dbw->insert( 'text', get_object_vars( $row ), __METHOD__, 'IGNORE' ); - } else { - foreach ( $this->slaveIndexes as $i ) { - $db = wfGetDB( $i ); - $db->insert( 'text', get_object_vars( $row ), __METHOD__, 'IGNORE' ); - } - } - } - $this->output( "done\n" ); - } - - if ( $found ) { - $this->output( "Fixing page_latest... " ); - if ( $toMaster ) { - /* - $dbw->update( - 'page', - array( 'page_latest' => $realLatest ), - array( 'page_id' => $pageID ), - __METHOD__ - ); - */ - } else { - foreach ( $this->slaveIndexes as $i ) { - $db = wfGetDB( $i ); - $db->update( - 'page', - array( 'page_latest' => $realLatest ), - array( 'page_id' => $pageID ), - __METHOD__ - ); - } - } - $this->output( "done\n" ); - } - $dbw->commit( __METHOD__ ); - } -} - -$maintClass = "FixSlaveDesync"; -require_once RUN_MAINTENANCE_IF_MAIN; -- 2.20.1