2005-08-14 16:30:51 +00:00
|
|
|
<?php
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
/**
|
|
|
|
|
* Move revision's text to external storage
|
|
|
|
|
*
|
2010-12-16 19:15:12 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
|
|
|
|
* @ingroup Maintenance ExternalStorage
|
|
|
|
|
*/
|
2005-08-14 16:30:51 +00:00
|
|
|
|
2007-01-17 00:54:54 +00:00
|
|
|
define( 'REPORTING_INTERVAL', 1 );
|
2005-08-14 16:30:51 +00:00
|
|
|
|
|
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2016-02-04 00:04:12 +00:00
|
|
|
$optionsWithArgs = [ 'e', 's' ];
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/../commandLine.inc';
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once 'resolveStubs.php';
|
2005-08-14 16:30:51 +00:00
|
|
|
|
|
|
|
|
$fname = 'moveToExternal';
|
|
|
|
|
|
|
|
|
|
if ( !isset( $args[0] ) ) {
|
2007-01-17 00:54:54 +00:00
|
|
|
print "Usage: php moveToExternal.php [-s <startid>] [-e <endid>] <cluster>\n";
|
2005-08-14 16:30:51 +00:00
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cluster = $args[0];
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2005-08-14 16:30:51 +00:00
|
|
|
|
2018-10-27 12:30:02 +00:00
|
|
|
$maxID = $options['e'] ?? $dbw->selectField( 'text', 'MAX(old_id)', '', $fname );
|
2017-10-06 22:17:58 +00:00
|
|
|
$minID = $options['s'] ?? 1;
|
2005-08-14 16:30:51 +00:00
|
|
|
|
2007-01-17 00:54:54 +00:00
|
|
|
moveToExternal( $cluster, $maxID, $minID );
|
2005-08-14 16:30:51 +00:00
|
|
|
}
|
|
|
|
|
|
2007-01-17 00:54:54 +00:00
|
|
|
function moveToExternal( $cluster, $maxID, $minID = 1 ) {
|
2005-08-14 16:30:51 +00:00
|
|
|
$fname = 'moveToExternal';
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2016-09-05 19:55:19 +00:00
|
|
|
$dbr = wfGetDB( DB_REPLICA );
|
2005-08-14 16:30:51 +00:00
|
|
|
|
2007-01-17 00:54:54 +00:00
|
|
|
$count = $maxID - $minID + 1;
|
|
|
|
|
$blockSize = 1000;
|
|
|
|
|
$numBlocks = ceil( $count / $blockSize );
|
|
|
|
|
print "Moving text rows from $minID to $maxID to external storage\n";
|
2005-08-14 16:30:51 +00:00
|
|
|
$ext = new ExternalStoreDB;
|
2007-01-17 00:54:54 +00:00
|
|
|
$numMoved = 0;
|
2010-07-25 21:44:29 +00:00
|
|
|
|
2007-01-17 00:54:54 +00:00
|
|
|
for ( $block = 0; $block < $numBlocks; $block++ ) {
|
|
|
|
|
$blockStart = $block * $blockSize + $minID;
|
|
|
|
|
$blockEnd = $blockStart + $blockSize - 1;
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
if ( !( $block % REPORTING_INTERVAL ) ) {
|
2007-01-17 00:54:54 +00:00
|
|
|
print "oldid=$blockStart, moved=$numMoved\n";
|
2011-04-20 00:12:06 +00:00
|
|
|
wfWaitForSlaves();
|
2005-08-14 16:30:51 +00:00
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$res = $dbr->select( 'text', [ 'old_id', 'old_flags', 'old_text' ],
|
|
|
|
|
[
|
2007-01-17 00:54:54 +00:00
|
|
|
"old_id BETWEEN $blockStart AND $blockEnd",
|
2009-10-21 19:53:03 +00:00
|
|
|
'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ),
|
2016-02-17 09:09:32 +00:00
|
|
|
], $fname );
|
2010-10-13 22:34:25 +00:00
|
|
|
foreach ( $res as $row ) {
|
2007-01-17 00:54:54 +00:00
|
|
|
# Resolve stubs
|
|
|
|
|
$text = $row->old_text;
|
|
|
|
|
$id = $row->old_id;
|
|
|
|
|
if ( $row->old_flags === '' ) {
|
|
|
|
|
$flags = 'external';
|
2006-04-02 04:19:27 +00:00
|
|
|
} else {
|
2007-01-17 00:54:54 +00:00
|
|
|
$flags = "{$row->old_flags},external";
|
|
|
|
|
}
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2007-01-17 00:54:54 +00:00
|
|
|
if ( strpos( $flags, 'object' ) !== false ) {
|
|
|
|
|
$obj = unserialize( $text );
|
|
|
|
|
$className = strtolower( get_class( $obj ) );
|
|
|
|
|
if ( $className == 'historyblobstub' ) {
|
2010-05-22 16:50:39 +00:00
|
|
|
# resolveStub( $id, $row->old_text, $row->old_flags );
|
|
|
|
|
# $numStubs++;
|
2007-01-17 00:54:54 +00:00
|
|
|
continue;
|
|
|
|
|
} elseif ( $className == 'historyblobcurstub' ) {
|
|
|
|
|
$text = gzdeflate( $obj->getText() );
|
|
|
|
|
$flags = 'utf-8,gzip,external';
|
|
|
|
|
} elseif ( $className == 'concatenatedgziphistoryblob' ) {
|
|
|
|
|
// Do nothing
|
|
|
|
|
} else {
|
|
|
|
|
print "Warning: unrecognised object class \"$className\"\n";
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$className = false;
|
2006-04-02 04:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
2007-01-17 00:54:54 +00:00
|
|
|
if ( strlen( $text ) < 100 && $className === false ) {
|
|
|
|
|
// Don't move tiny revisions
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2005-08-14 16:30:51 +00:00
|
|
|
|
2010-05-22 16:50:39 +00:00
|
|
|
# print "Storing " . strlen( $text ) . " bytes to $url\n";
|
|
|
|
|
# print "old_id=$id\n";
|
2006-04-02 04:19:27 +00:00
|
|
|
|
2007-01-17 00:54:54 +00:00
|
|
|
$url = $ext->store( $cluster, $text );
|
|
|
|
|
if ( !$url ) {
|
|
|
|
|
print "Error writing to external storage\n";
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
$dbw->update( 'text',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'old_flags' => $flags, 'old_text' => $url ],
|
|
|
|
|
[ 'old_id' => $id ], $fname );
|
2007-01-17 00:54:54 +00:00
|
|
|
$numMoved++;
|
2005-08-14 16:30:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|