diff options
author | Aaron Schulz <aschulz@wikimedia.org> | 2018-02-26 22:24:46 -0800 |
---|---|---|
committer | Aaron Schulz <aschulz@wikimedia.org> | 2019-06-28 14:31:44 -0700 |
commit | baafb5adb400098f475c20fe10e3a181e87a4795 (patch) | |
tree | a11e2fd8cb25cf431f90793819fa3d1bbceab3d1 /maintenance/storage | |
parent | ca00e47f535129e067a078c96a90c6dfbae716b0 (diff) | |
download | mediawikicore-baafb5adb400098f475c20fe10e3a181e87a4795.tar.gz mediawikicore-baafb5adb400098f475c20fe10e3a181e87a4795.zip |
Make ExternalStore wrap ExternalStoreFactory and create access class
* Inject settings and global instances as dependencies to the
ExternalStoreMedium instances. This includes the local wiki
domain, so that wfWikiId() calls are not scattered around.
* Create ExternalStoreAccess service for read/write logic.
* Deprecate the ExternalStore wrapper methods.
* Add some exception cases for bogus store URLs are used instead
of just giving PHP warnings and failing later.
* Make moveToExternal.php require the type/protocol to decide
which ExternalStoreMedium to use instead of assuming "DB".
* Convert logging calls to use LoggerInterface.
Change-Id: I40c3b5534fc8a31116c4c5eb64ee6e4903a6197a
Diffstat (limited to 'maintenance/storage')
-rw-r--r-- | maintenance/storage/checkStorage.php | 7 | ||||
-rw-r--r-- | maintenance/storage/compressOld.php | 8 | ||||
-rw-r--r-- | maintenance/storage/moveToExternal.php | 19 | ||||
-rw-r--r-- | maintenance/storage/recompressTracked.php | 4 |
4 files changed, 26 insertions, 12 deletions
diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index 173d741be86f..c2fa687432e2 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -45,6 +45,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { class CheckStorage { const CONCAT_HEADER = 'O:27:"concatenatedgziphistoryblob"'; public $oldIdMap, $errors; + /** @var ExternalStoreDB */ public $dbStore = null; public $errorDescriptions = [ @@ -223,7 +224,8 @@ class CheckStorage { // Check external normal blobs for existence if ( count( $externalNormalBlobs ) ) { if ( is_null( $this->dbStore ) ) { - $this->dbStore = new ExternalStoreDB; + $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); + $this->dbStore = $esFactory->getStore( 'DB' ); } foreach ( $externalConcatBlobs as $cluster => $xBlobIds ) { $blobIds = array_keys( $xBlobIds ); @@ -422,7 +424,8 @@ class CheckStorage { } if ( is_null( $this->dbStore ) ) { - $this->dbStore = new ExternalStoreDB; + $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); + $this->dbStore = $esFactory->getStore( 'DB' ); } foreach ( $externalConcatBlobs as $cluster => $oldIds ) { diff --git a/maintenance/storage/compressOld.php b/maintenance/storage/compressOld.php index d3e9ce2cf6b9..beb1975fad6b 100644 --- a/maintenance/storage/compressOld.php +++ b/maintenance/storage/compressOld.php @@ -188,7 +188,9 @@ class CompressOld extends Maintenance { # Store in external storage if required if ( $extdb !== '' ) { - $storeObj = new ExternalStoreDB; + $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); + /** @var ExternalStoreDB $storeObj */ + $storeObj = $esFactory->getStore( 'DB' ); $compress = $storeObj->store( $extdb, $compress ); if ( $compress === false ) { $this->error( "Unable to store object" ); @@ -232,7 +234,9 @@ class CompressOld extends Maintenance { # Set up external storage if ( $extdb != '' ) { - $storeObj = new ExternalStoreDB; + $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); + /** @var ExternalStoreDB $storeObj */ + $storeObj = $esFactory->getStore( 'DB' ); } # Get all articles by page_id diff --git a/maintenance/storage/moveToExternal.php b/maintenance/storage/moveToExternal.php index 0b95ba5e68e4..9554797f44b9 100644 --- a/maintenance/storage/moveToExternal.php +++ b/maintenance/storage/moveToExternal.php @@ -21,6 +21,8 @@ * @ingroup Maintenance ExternalStorage */ +use MediaWiki\MediaWikiServices; + define( 'REPORTING_INTERVAL', 1 ); if ( !defined( 'MEDIAWIKI' ) ) { @@ -30,21 +32,22 @@ if ( !defined( 'MEDIAWIKI' ) ) { $fname = 'moveToExternal'; - if ( !isset( $args[0] ) ) { - print "Usage: php moveToExternal.php [-s <startid>] [-e <endid>] <cluster>\n"; + if ( !isset( $args[1] ) ) { + print "Usage: php moveToExternal.php [-s <startid>] [-e <endid>] <type> <location>\n"; exit; } - $cluster = $args[0]; + $type = $args[0]; // e.g. "DB" or "mwstore" + $location = $args[1]; // e.g. "cluster12" or "global-swift" $dbw = wfGetDB( DB_MASTER ); $maxID = $options['e'] ?? $dbw->selectField( 'text', 'MAX(old_id)', '', $fname ); $minID = $options['s'] ?? 1; - moveToExternal( $cluster, $maxID, $minID ); + moveToExternal( $type, $location, $maxID, $minID ); } -function moveToExternal( $cluster, $maxID, $minID = 1 ) { +function moveToExternal( $type, $location, $maxID, $minID = 1 ) { $fname = 'moveToExternal'; $dbw = wfGetDB( DB_MASTER ); $dbr = wfGetDB( DB_REPLICA ); @@ -53,7 +56,9 @@ function moveToExternal( $cluster, $maxID, $minID = 1 ) { $blockSize = 1000; $numBlocks = ceil( $count / $blockSize ); print "Moving text rows from $minID to $maxID to external storage\n"; - $ext = new ExternalStoreDB; + + $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); + $extStore = $esFactory->getStore( $type ); $numMoved = 0; for ( $block = 0; $block < $numBlocks; $block++ ) { @@ -108,7 +113,7 @@ function moveToExternal( $cluster, $maxID, $minID = 1 ) { # print "Storing " . strlen( $text ) . " bytes to $url\n"; # print "old_id=$id\n"; - $url = $ext->store( $cluster, $text ); + $url = $extStore->store( $location, $text ); if ( !$url ) { print "Error writing to external storage\n"; exit; diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index f17b00c1c81b..e6733a184b86 100644 --- a/maintenance/storage/recompressTracked.php +++ b/maintenance/storage/recompressTracked.php @@ -69,6 +69,7 @@ class RecompressTracked { public $replicaId = false; public $noCount = false; public $debugLog, $infoLog, $criticalLog; + /** @var ExternalStoreDB */ public $store; private static $optionsWithArgs = [ @@ -109,7 +110,8 @@ class RecompressTracked { foreach ( $options as $name => $value ) { $this->$name = $value; } - $this->store = new ExternalStoreDB; + $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); + $this->store = $esFactory->getStore( 'DB' ); if ( !$this->isChild ) { $GLOBALS['wgDebugLogPrefix'] = "RCT M: "; } elseif ( $this->replicaId !== false ) { |