r55403 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55402‎ | r55403 | r55404 >
Date:00:59, 21 August 2009
Author:demon
Status:ok
Tags:
Comment:
Move dumpRev and orphanStats to subclass Maintenance. Make orphanStats bail out early if blob_orphans doesn't exist. dumpRev could use a nice description.
Modified paths:
  • /trunk/phase3/maintenance/storage/dumpRev.php (modified) (history)
  • /trunk/phase3/maintenance/storage/orphanStats.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/storage/dumpRev.php
@@ -1,56 +1,78 @@
22 <?php
33 /**
4 - * @file
 4+ * This program is free software; you can redistribute it and/or modify
 5+ * it under the terms of the GNU General Public License as published by
 6+ * the Free Software Foundation; either version 2 of the License, or
 7+ * (at your option) any later version.
 8+ *
 9+ * This program is distributed in the hope that it will be useful,
 10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 12+ * GNU General Public License for more details.
 13+ *
 14+ * You should have received a copy of the GNU General Public License along
 15+ * with this program; if not, write to the Free Software Foundation, Inc.,
 16+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 17+ * http://www.gnu.org/copyleft/gpl.html
 18+ *
519 * @ingroup Maintenance ExternalStorage
620 */
721
8 -require_once( dirname(__FILE__) . '/../commandLine.inc' );
 22+require_once( dirname(__FILE__) . '/../Maintenance.php' );
923
10 -$wgDebugLogFile = '/dev/stdout';
 24+class DumpRev extends Maintenance {
 25+ public function __construct() {
 26+ parent::__construct();
 27+ $this->addArg( 'rev-id', 'Revision ID', true );
 28+ }
1129
12 -
13 -$dbr = wfGetDB( DB_SLAVE );
14 -$row = $dbr->selectRow(
15 - array( 'text', 'revision' ),
16 - array( 'old_flags', 'old_text' ),
17 - array( 'old_id=rev_text_id', 'rev_id' => $args[0] )
18 -);
19 -if ( !$row ) {
20 - print "Row not found\n";
21 - exit;
22 -}
23 -
24 -$flags = explode( ',', $row->old_flags );
25 -$text = $row->old_text;
26 -if ( in_array( 'external', $flags ) ) {
27 - print "External $text\n";
28 - if ( preg_match( '!^DB://(\w+)/(\w+)/(\w+)$!', $text, $m ) ) {
29 - $es = ExternalStore::getStoreObject( 'DB' );
30 - $blob = $es->fetchBlob( $m[1], $m[2], $m[3] );
31 - if ( strtolower( get_class( $blob ) ) == 'concatenatedgziphistoryblob' ) {
32 - print "Found external CGZ\n";
33 - $blob->uncompress();
34 - print "Items: (" . implode( ', ', array_keys( $blob->mItems ) ) . ")\n";
35 - $text = $blob->getItem( $m[3] );
 30+ public function execute() {
 31+ $dbr = wfGetDB( DB_SLAVE );
 32+ $row = $dbr->selectRow(
 33+ array( 'text', 'revision' ),
 34+ array( 'old_flags', 'old_text' ),
 35+ array( 'old_id=rev_text_id', 'rev_id' => $this->getArg() )
 36+ );
 37+ if ( !$row ) {
 38+ $this->error( "Row not found", true );
 39+ }
 40+
 41+ $flags = explode( ',', $row->old_flags );
 42+ $text = $row->old_text;
 43+ if ( in_array( 'external', $flags ) ) {
 44+ $this->output( "External $text\n" );
 45+ if ( preg_match( '!^DB://(\w+)/(\w+)/(\w+)$!', $text, $m ) ) {
 46+ $es = ExternalStore::getStoreObject( 'DB' );
 47+ $blob = $es->fetchBlob( $m[1], $m[2], $m[3] );
 48+ if ( strtolower( get_class( $blob ) ) == 'concatenatedgziphistoryblob' ) {
 49+ $this->output( "Found external CGZ\n" );
 50+ $blob->uncompress();
 51+ $this->output( "Items: (" . implode( ', ', array_keys( $blob->mItems ) ) . ")\n" );
 52+ $text = $blob->getItem( $m[3] );
 53+ } else {
 54+ $this->output( "CGZ expected at $text, got " . gettype( $blob ) . "\n" );
 55+ $text = $blob;
 56+ }
 57+ } else {
 58+ $this->output( "External plain $text\n" );
 59+ $text = ExternalStore::fetchFromURL( $text );
 60+ }
 61+ }
 62+ if ( in_array( 'gzip', $flags ) ) {
 63+ $text = gzinflate( $text );
 64+ }
 65+ if ( in_array( 'object', $flags ) ) {
 66+ $text = unserialize( $text );
 67+ }
 68+
 69+ if ( is_object( $text ) ) {
 70+ $this->error( "Unexpectedly got object of type: " . get_class( $text ) );
3671 } else {
37 - print "CGZ expected at $text, got " . gettype( $blob ) . "\n";
38 - $text = $blob;
 72+ $this->output( "Text length: " . strlen( $text ) ."\n" );
 73+ $this->output( substr( $text, 0, 100 ) . "\n" );
3974 }
40 - } else {
41 - print "External plain $text\n";
42 - $text = ExternalStore::fetchFromURL( $text );
4375 }
4476 }
45 -if ( in_array( 'gzip', $flags ) ) {
46 - $text = gzinflate( $text );
47 -}
48 -if ( in_array( 'object', $flags ) ) {
49 - $text = unserialize( $text );
50 -}
5177
52 -if ( is_object( $text ) ) {
53 - print "Unexpectedly got object of type: " . get_class( $text ) . "\n";
54 -} else {
55 - print "Text length: " . strlen( $text ) ."\n";
56 - print substr( $text, 0, 100 ) . "\n";
57 -}
 78+$maintClass = "DumpRev";
 79+require_once( DO_MAINTENANCE );
Index: trunk/phase3/maintenance/storage/orphanStats.php
@@ -2,21 +2,43 @@
33
44 /**
55 * Show some statistics on the blob_orphans table, created with trackBlobs.php
 6+ *
 7+ * This program is free software; you can redistribute it and/or modify
 8+ * it under the terms of the GNU General Public License as published by
 9+ * the Free Software Foundation; either version 2 of the License, or
 10+ * (at your option) any later version.
 11+ *
 12+ * This program is distributed in the hope that it will be useful,
 13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15+ * GNU General Public License for more details.
 16+ *
 17+ * You should have received a copy of the GNU General Public License along
 18+ * with this program; if not, write to the Free Software Foundation, Inc.,
 19+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 20+ * http://www.gnu.org/copyleft/gpl.html
 21+ *
 22+ * @ingroup Maintenance ExternalStorage
623 */
7 -require_once( dirname(__FILE__).'/../commandLine.inc' );
 24+require_once( dirname(__FILE__) . '/../Maintenance.php' );
825
9 -$stats = new OrphanStats;
10 -$stats->execute();
 26+class OrphanStats extends Maintenance {
 27+ public function __construct() {
 28+ parent::__construct();
 29+ $this->mDescription = "how some statistics on the blob_orphans table, created with trackBlobs.php";
 30+ }
1131
12 -class OrphanStats {
13 - function getDB( $cluster ) {
 32+ private function getDB( $cluster ) {
1433 $lb = wfGetLBFactory()->getExternalLB( $cluster );
1534 return $lb->getConnection( DB_SLAVE );
1635 }
1736
18 - function execute() {
 37+ public function execute() {
1938 $extDBs = array();
2039 $dbr = wfGetDB( DB_SLAVE );
 40+ if( !$dbr->tableExists( 'blob_orphans' ) ) {
 41+ $this->error( "blob_orphans doesn't seem to exist, need to run trackBlobs.php first", true );
 42+ }
2143 $res = $dbr->select( 'blob_orphans', '*', false, __METHOD__ );
2244
2345 $num = 0;
@@ -36,11 +58,14 @@
3759 }
3860 unset( $res );
3961
40 - echo "Number of orphans: $num\n";
 62+ $this->output( "Number of orphans: $num\n" );
4163 if ( $num > 0 ) {
42 - echo "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" .
 64+ $this->output( "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" .
4365 "Max size: $maxSize\n" .
44 - "Number of unique texts: " . count( $hashes ) . "\n";
 66+ "Number of unique texts: " . count( $hashes ) . "\n" );
4567 }
4668 }
4769 }
 70+
 71+$maintClass = "OrphanStats";
 72+require_once( DO_MAINTENANCE );

Status & tagging log