r13831 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r13830‎ | r13831 | r13832 >
Date:03:23, 24 April 2006
Author:tstarling
Status:old
Tags:
Comment:
various improvements
Modified paths:
  • /trunk/phase3/maintenance/storage/checkStorage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/storage/checkStorage.php
@@ -17,31 +17,8 @@
1818
1919 //----------------------------------------------------------------------------------
2020
21 -function checkError( $msg, $ids ) {
22 - global $oldIdMap;
23 - if ( is_array( $ids ) && count( $ids ) == 1 ) {
24 - $ids = reset( $ids );
25 - }
26 - if ( is_array( $ids ) ) {
27 - $revIds = array();
28 - foreach ( $ids as $id ) {
29 - $revIds = array_merge( $revIds, array_keys( $oldIdMap, $id ) );
30 - }
31 - print "$msg in text rows " . implode( ', ', $ids ) .
32 - ", revisions " . implode( ', ', $revIds ) . "\n";
33 - } else {
34 - $id = $ids;
35 - $revIds = array_keys( $oldIdMap, $id );
36 - if ( count( $revIds ) == 1 ) {
37 - print "$msg in old_id $id, rev_id {$revIds[0]}\n";
38 - } else {
39 - print "$msg in old_id $id, revisions " . implode( ', ', $revIds ) . "\n";
40 - }
41 - }
42 -}
43 -
4421 function checkStorage() {
45 - global $oldIdMap;
 22+ global $oldIdMap, $brokenRevisions;
4623
4724 $fname = 'checkStorage';
4825 $dbr =& wfGetDB( DB_SLAVE );
@@ -51,10 +28,11 @@
5229 $objectStats = array();
5330 $knownFlags = array( 'external', 'gzip', 'object', 'utf-8' );
5431 $dbStore = null;
 32+ $brokenRevisions = array();
5533
5634 for ( $chunkStart = 1 ; $chunkStart < $maxRevId; $chunkStart += $chunkSize ) {
5735 $chunkEnd = $chunkStart + $chunkSize - 1;
58 - //print "$chunkStart to $chunkEnd of $maxRevId\n";
 36+ //print "$chunkStart of $maxRevId\n";
5937
6038 // Fetch revision rows
6139 $oldIdMap = array();
@@ -65,6 +43,10 @@
6644 }
6745 $dbr->freeResult( $res );
6846
 47+ if ( !count( $oldIdMap ) ) {
 48+ continue;
 49+ }
 50+
6951 // Fetch old_flags
7052 $missingTextRows = array_flip( $oldIdMap );
7153 $externalRevs = array();
@@ -100,7 +82,6 @@
10183
10284 // Check for unrecognised flags
10385 if ( count( array_diff( $flagArray, $knownFlags ) ) ) {
104 - print_r( array_diff( $flagArray, $knownFlags ) );
10586 checkError( "Warning: invalid flags field \"$flags\"", $id );
10687 }
10788 }
@@ -182,7 +163,7 @@
183164 continue;
184165 }
185166
186 - $className = $matches[2];
 167+ $className = strtolower( $matches[2] );
187168 if ( strlen( $className ) != $matches[1] ) {
188169 checkError( "Error: invalid object header, wrong class name length", $oldId );
189170 continue;
@@ -247,7 +228,7 @@
248229 checkError( "Error: invalid flags \"{$row->old_flags}\" on concat bulk row {$row->old_id}",
249230 $concatBlobs[$row->old_id] );
250231 }
251 - } elseif ( substr( $row->header, 0, strlen( CONCAT_HEADER ) ) != CONCAT_HEADER ) {
 232+ } elseif ( strcasecmp( substr( $row->header, 0, strlen( CONCAT_HEADER ) ), CONCAT_HEADER ) ) {
252233 checkError( "Error: Incorrect object header for concat bulk row {$row->old_id}",
253234 $concatBlobs[$row->old_id] );
254235 } # else good
@@ -264,7 +245,9 @@
265246 // next chunk
266247 }
267248
268 - print "\n\nFlag statistics:\n";
 249+ print "\n\n" . count( $brokenRevisions ) . " broken revisions\n";
 250+
 251+ print "\nFlag statistics:\n";
269252 $total = array_sum( $flagStats );
270253 foreach ( $flagStats as $flag => $count ) {
271254 printf( "%-30s %10d %5.2f%%\n", $flag, $count, $count / $total * 100 );
@@ -277,6 +260,30 @@
278261 }
279262
280263
 264+function checkError( $msg, $ids ) {
 265+ global $oldIdMap, $brokenRevisions;
 266+ if ( is_array( $ids ) && count( $ids ) == 1 ) {
 267+ $ids = reset( $ids );
 268+ }
 269+ if ( is_array( $ids ) ) {
 270+ $revIds = array();
 271+ foreach ( $ids as $id ) {
 272+ $revIds = array_merge( $revIds, array_keys( $oldIdMap, $id ) );
 273+ }
 274+ print "$msg in text rows " . implode( ', ', $ids ) .
 275+ ", revisions " . implode( ', ', $revIds ) . "\n";
 276+ } else {
 277+ $id = $ids;
 278+ $revIds = array_keys( $oldIdMap, $id );
 279+ if ( count( $revIds ) == 1 ) {
 280+ print "$msg in old_id $id, rev_id {$revIds[0]}\n";
 281+ } else {
 282+ print "$msg in old_id $id, revisions " . implode( ', ', $revIds ) . "\n";
 283+ }
 284+ }
 285+ $brokenRevisions = $brokenRevisions + array_flip( $revIds );
 286+}
 287+
281288 function checkExternalConcatBlobs( $externalConcatBlobs ) {
282289 static $dbStore = null;
283290 $fname = 'checkExternalConcatBlobs';
@@ -297,10 +304,10 @@
298305 array( 'blob_id', "LEFT(blob_text, $headerLength) AS header" ),
299306 array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
300307 while ( $row = $extDb->fetchObject( $res ) ) {
301 - if ( $row->header != CONCAT_HEADER ) {
302 - checkError( "Error: invalid header on target of two-part ES URL",
303 - $oldIds[$row->blob_id] );
304 - }
 308+ if ( strcasecmp( $row->header, CONCAT_HEADER ) ) {
 309+ checkError( "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL",
 310+ $oldIds[$row->blob_id] );
 311+ }
305312 unset( $oldIds[$row->blob_id] );
306313
307314 }
@@ -308,7 +315,7 @@
309316
310317 // Print errors for missing blobs rows
311318 foreach ( $oldIds as $blobId => $oldIds ) {
312 - checkError( "Error: missing target $blobId for two-part ES URL", $oldIds );
 319+ checkError( "Error: missing target $cluster/$blobId for two-part ES URL", $oldIds );
313320 }
314321 }
315322 }

Status & tagging log