Index: trunk/phase3/maintenance/fixSlaveDesync.php |
— | — | @@ -0,0 +1,93 @@ |
| 2 | +<? |
| 3 | + |
| 4 | +$wgUseRootUser = true; |
| 5 | +require_once( 'commandLine.inc' ); |
| 6 | + |
| 7 | +//$wgDebugLogFile = '/dev/stdout'; |
| 8 | + |
| 9 | +$numServers = count( $wgDBservers ); |
| 10 | +/* |
| 11 | +foreach ( $wgLoadBalancer->mServers as $i => $server ) { |
| 12 | + $wgLoadBalancer->mServers[$i]['flags'] |= DBO_DEBUG; |
| 13 | +}*/ |
| 14 | +define( 'REPORTING_INTERVAL', 1000 ); |
| 15 | + |
| 16 | +if ( isset( $args[0] ) ) { |
| 17 | + desyncFixPage( $args[0] ); |
| 18 | +} else { |
| 19 | + $dbw =& wfGetDB( DB_MASTER ); |
| 20 | + $maxPage = $dbw->selectField( 'page', 'MAX(page_id)', false, 'fixDesync.php' ); |
| 21 | + for ( $i=1; $i <= $maxPage; $i++ ) { |
| 22 | + desyncFixPage( $i ); |
| 23 | + if ( !($i % REPORTING_INTERVAL) ) { |
| 24 | + print "$i\n"; |
| 25 | + } |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +function desyncFixPage( $pageID ) { |
| 30 | + global $numServers; |
| 31 | + $fname = 'desyncFixPage'; |
| 32 | + |
| 33 | + # Check for a corrupted page_latest |
| 34 | + $dbw =& wfGetDB( DB_MASTER ); |
| 35 | + $realLatest = $dbw->selectField( 'page', 'page_latest', array( 'page_id' => $pageID ), $fname ); |
| 36 | + for ( $i = 1; $i < $numServers; $i++ ) { |
| 37 | + $db =& wfGetDB( $i ); |
| 38 | + $latest = $db->selectField( 'page', 'page_latest', array( 'page_id' => $pageID ), $fname ); |
| 39 | + $max = $db->selectField( 'revision', 'MAX(rev_id)', false, $fname ); |
| 40 | + if ( $latest != $realLatest && $realLatest < $max ) { |
| 41 | + print "page_latest corrupted in page $pageID, server $i\n"; |
| 42 | + break; |
| 43 | + } |
| 44 | + } |
| 45 | + if ( $i == $numServers ) { |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + # Find the missing revision |
| 50 | + $res = $dbw->select( 'revision', array( 'rev_id' ), array( 'rev_page' => $pageID ), $fname ); |
| 51 | + $masterIDs = array(); |
| 52 | + while ( $row = $dbw->fetchObject( $res ) ) { |
| 53 | + $masterIDs[] = $row->rev_id; |
| 54 | + } |
| 55 | + $dbw->freeResult( $res ); |
| 56 | + |
| 57 | + $res = $db->select( 'revision', array( 'rev_id' ), array( 'rev_page' => $pageID ), $fname ); |
| 58 | + $slaveIDs = array(); |
| 59 | + while ( $row = $db->fetchObject( $res ) ) { |
| 60 | + $slaveIDs[] = $row->rev_id; |
| 61 | + } |
| 62 | + $db->freeResult( $res ); |
| 63 | + $missingIDs = array_diff( $masterIDs, $slaveIDs ); |
| 64 | + |
| 65 | + if ( count( $missingIDs ) ) { |
| 66 | + print "Found " . count( $missingIDs ) . " missing revision(s), copying from master... "; |
| 67 | + foreach ( $missingIDs as $rid ) { |
| 68 | + print "$rid "; |
| 69 | + # Revision |
| 70 | + $row = $dbw->selectRow( 'revision', '*', array( 'rev_id' => $rid ), $fname ); |
| 71 | + for ( $i = 1; $i < $numServers; $i++ ) { |
| 72 | + $db =& wfGetDB( $i ); |
| 73 | + $db->insert( 'revision', get_object_vars( $row ), $fname, 'IGNORE' ); |
| 74 | + } |
| 75 | + |
| 76 | + # Text |
| 77 | + $row = $dbw->selectRow( 'text', '*', array( 'old_id' => $row->rev_text_id ), $fname ); |
| 78 | + for ( $i = 1; $i < $numServers; $i++ ) { |
| 79 | + $db =& wfGetDB( $i ); |
| 80 | + $db->insert( 'text', get_object_vars( $row ), $fname, 'IGNORE' ); |
| 81 | + } |
| 82 | + } |
| 83 | + print "done\n"; |
| 84 | + } |
| 85 | + |
| 86 | + print "Fixing page_latest... "; |
| 87 | + for ( $i = 1; $i < $numServers; $i++ ) { |
| 88 | + $db =& wfGetDB( $i ); |
| 89 | + $db->update( 'page', array( 'page_latest' => $realLatest ), array( 'page_id' => $pageID ), $fname ); |
| 90 | + } |
| 91 | + print "done\n"; |
| 92 | +} |
| 93 | + |
| 94 | +?> |
Property changes on: trunk/phase3/maintenance/fixSlaveDesync.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 95 | + native |
Added: svn:keywords |
2 | 96 | + Author Date Id Revision |