Index: trunk/phase3/maintenance/storage/dumpRev.php |
— | — | @@ -1,56 +1,78 @@ |
2 | 2 | <?php |
3 | 3 | /** |
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 | + * |
5 | 19 | * @ingroup Maintenance ExternalStorage |
6 | 20 | */ |
7 | 21 | |
8 | | -require_once( dirname(__FILE__) . '/../commandLine.inc' ); |
| 22 | +require_once( dirname(__FILE__) . '/../Maintenance.php' ); |
9 | 23 | |
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 | + } |
11 | 29 | |
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 ) ); |
36 | 71 | } 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" ); |
39 | 74 | } |
40 | | - } else { |
41 | | - print "External plain $text\n"; |
42 | | - $text = ExternalStore::fetchFromURL( $text ); |
43 | 75 | } |
44 | 76 | } |
45 | | -if ( in_array( 'gzip', $flags ) ) { |
46 | | - $text = gzinflate( $text ); |
47 | | -} |
48 | | -if ( in_array( 'object', $flags ) ) { |
49 | | - $text = unserialize( $text ); |
50 | | -} |
51 | 77 | |
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 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * 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 |
6 | 23 | */ |
7 | | -require_once( dirname(__FILE__).'/../commandLine.inc' ); |
| 24 | +require_once( dirname(__FILE__) . '/../Maintenance.php' ); |
8 | 25 | |
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 | + } |
11 | 31 | |
12 | | -class OrphanStats { |
13 | | - function getDB( $cluster ) { |
| 32 | + private function getDB( $cluster ) { |
14 | 33 | $lb = wfGetLBFactory()->getExternalLB( $cluster ); |
15 | 34 | return $lb->getConnection( DB_SLAVE ); |
16 | 35 | } |
17 | 36 | |
18 | | - function execute() { |
| 37 | + public function execute() { |
19 | 38 | $extDBs = array(); |
20 | 39 | $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 | + } |
21 | 43 | $res = $dbr->select( 'blob_orphans', '*', false, __METHOD__ ); |
22 | 44 | |
23 | 45 | $num = 0; |
— | — | @@ -36,11 +58,14 @@ |
37 | 59 | } |
38 | 60 | unset( $res ); |
39 | 61 | |
40 | | - echo "Number of orphans: $num\n"; |
| 62 | + $this->output( "Number of orphans: $num\n" ); |
41 | 63 | if ( $num > 0 ) { |
42 | | - echo "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" . |
| 64 | + $this->output( "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" . |
43 | 65 | "Max size: $maxSize\n" . |
44 | | - "Number of unique texts: " . count( $hashes ) . "\n"; |
| 66 | + "Number of unique texts: " . count( $hashes ) . "\n" ); |
45 | 67 | } |
46 | 68 | } |
47 | 69 | } |
| 70 | + |
| 71 | +$maintClass = "OrphanStats"; |
| 72 | +require_once( DO_MAINTENANCE ); |