24 require_once __DIR__ .
'/Maintenance.php';
34 parent::__construct();
35 $this->mDescription =
"";
43 $this->slaveIndexes =
array();
44 for ( $i = 1; $i <
wfGetLB()->getServerCount(); $i++ ) {
45 if (
wfGetLB()->isNonZeroLoad( $i ) ) {
46 $this->slaveIndexes[] = $i;
54 foreach ( $corrupt
as $id => $dummy ) {
69 $res = $dbw->select(
'page',
array(
'page_id',
'page_latest' ),
array(
'page_id<6054123' ), __METHOD__ );
70 $this->
output(
"Number of pages: " .
$res->numRows() .
"\n" );
72 $masterIDs[$row->page_id] = $row->page_latest;
73 if ( !( ++
$n % 10000 ) ) {
79 foreach ( $this->slaveIndexes
as $i ) {
81 $res = $db->select(
'page',
array(
'page_id',
'page_latest' ),
array(
'page_id<6054123' ), __METHOD__ );
83 if ( isset( $masterIDs[$row->page_id] ) && $masterIDs[$row->page_id] != $row->page_latest ) {
84 $desync[$row->page_id] =
true;
85 $this->
output( $row->page_id .
"\t" );
98 # Check for a corrupted page_latest
100 $dbw->begin( __METHOD__ );
101 $realLatest = $dbw->selectField(
'page',
'page_latest',
array(
'page_id' => $pageID ),
102 __METHOD__,
'FOR UPDATE' );
103 # list( $masterFile, $masterPos ) = $dbw->getMasterPos();
105 foreach ( $this->slaveIndexes
as $i ) {
114 $latest = $db->selectField(
'page',
'page_latest',
array(
'page_id' => $pageID ), __METHOD__ );
115 $max = $db->selectField(
'revision',
'MAX(rev_id)',
false, __METHOD__ );
116 if ( $latest != $realLatest && $realLatest < $max ) {
117 $this->
output(
"page_latest corrupted in page $pageID, server $i\n" );
123 $this->
output(
"page_id $pageID seems fine\n" );
124 $dbw->commit( __METHOD__ );
128 # Find the missing revisions
129 $res = $dbw->select(
'revision',
array(
'rev_id' ),
array(
'rev_page' => $pageID ),
130 __METHOD__,
'FOR UPDATE' );
131 $masterIDs =
array();
132 foreach (
$res as $row ) {
133 $masterIDs[] = $row->rev_id;
136 $res = $dbw->select(
'revision',
array(
'rev_id' ),
array(
'rev_page' => $pageID ), __METHOD__ );
138 foreach (
$res as $row ) {
139 $slaveIDs[] = $row->rev_id;
141 if ( count( $masterIDs ) < count( $slaveIDs ) ) {
142 $missingIDs = array_diff( $slaveIDs, $masterIDs );
143 if ( count( $missingIDs ) ) {
144 $this->
output(
"Found " . count( $missingIDs ) .
" lost in master, copying from slave... " );
152 $missingIDs = array_diff( $masterIDs, $slaveIDs );
153 if ( count( $missingIDs ) ) {
154 $this->
output(
"Found " . count( $missingIDs ) .
" missing revision(s), copying from master... " );
164 foreach ( $missingIDs
as $rid ) {
167 $row = $dbFrom->selectRow(
'revision',
'*',
array(
'rev_id' => $rid ), __METHOD__ );
169 $id = $dbw->selectField(
'revision',
'rev_id',
array(
'rev_id' => $rid ),
170 __METHOD__,
'FOR UPDATE' );
172 $this->
output(
"Revision already exists\n" );
176 $dbw->insert(
'revision', get_object_vars( $row ), __METHOD__,
'IGNORE' );
179 foreach ( $this->slaveIndexes
as $i ) {
181 $db->insert(
'revision', get_object_vars( $row ), __METHOD__,
'IGNORE' );
186 $row = $dbFrom->selectRow(
'text',
'*',
array(
'old_id' => $row->rev_text_id ), __METHOD__ );
188 $dbw->insert(
'text', get_object_vars( $row ), __METHOD__,
'IGNORE' );
190 foreach ( $this->slaveIndexes
as $i ) {
192 $db->insert(
'text', get_object_vars( $row ), __METHOD__,
'IGNORE' );
196 $this->
output(
"done\n" );
200 $this->
output(
"Fixing page_latest... " );
202 # $dbw->update( 'page', array( 'page_latest' => $realLatest ), array( 'page_id' => $pageID ), __METHOD__ );
204 foreach ( $this->slaveIndexes
as $i ) {
206 $db->update(
'page',
array(
'page_latest' => $realLatest ),
array(
'page_id' => $pageID ), __METHOD__ );
209 $this->
output(
"done\n" );
211 $dbw->commit( __METHOD__ );