}
/**
- * Returns a database to be used by current maintenance script. It can be set by setDB().
- * If not set, wfGetDB() will be used.
- * This function has the same parameters as wfGetDB()
+ * Returns a database to be used by current maintenance script.
+ *
+ * This uses the main LBFactory instance by default unless overriden via setDB().
+ *
+ * This function has the same parameters as LoadBalancer::getConnection().
*
* @param int $db DB index (DB_REPLICA/DB_MASTER)
* @param string|string[] $groups default: empty array
- * @param string|bool $wiki default: current wiki
+ * @param string|bool $dbDomain default: current wiki
* @return IMaintainableDatabase
*/
- protected function getDB( $db, $groups = [], $wiki = false ) {
+ protected function getDB( $db, $groups = [], $dbDomain = false ) {
if ( $this->mDb === null ) {
- return wfGetDB( $db, $groups, $wiki );
+ return MediaWikiServices::getInstance()
+ ->getDBLoadBalancerFactory()
+ ->getMainLB( $dbDomain )
+ ->getMaintenanceConnectionRef( $db, $groups, $dbDomain );
}
+
return $this->mDb;
}
/**
* Sets database object to be returned by getDB().
*
- * @param IDatabase $db
+ * @param IMaintainableDatabase $db
*/
- public function setDB( IDatabase $db ) {
+ public function setDB( IMaintainableDatabase $db ) {
$this->mDb = $db;
}
use MediaWiki\MediaWikiServices;
use Wikimedia\Rdbms\LoadBalancer;
-use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\IMaintainableDatabase;
/**
* @ingroup Dump
/**
* The dependency-injected database to use.
*
- * @var IDatabase|null
+ * @var IMaintainableDatabase|null
*
* @see self::setDB
*/
* @todo Fixme: the --server parameter is currently not respected, as it
* doesn't seem terribly easy to ask the load balancer for a particular
* connection by name.
- * @return IDatabase
+ * @return IMaintainableDatabase
*/
function backupDb() {
if ( $this->forcedDb !== null ) {
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$this->lb = $lbFactory->newMainLB();
- $db = $this->lb->getConnection( DB_REPLICA, 'dump' );
+ $db = $this->lb->getMaintenanceConnectionRef( DB_REPLICA, 'dump' );
// Discourage the server from disconnecting us if it takes a long time
// to read out the big ol' batch query.
* Force the dump to use the provided database connection for database
* operations, wherever possible.
*
- * @param IDatabase|null $db (Optional) the database connection to use. If null, resort to
- * use the globally provided ways to get database connections.
+ * @param IMaintainableDatabase $db The database connection to use
*/
- function setDB( IDatabase $db = null ) {
+ function setDB( IMaintainableDatabase $db ) {
parent::setDB( $db );
$this->forcedDb = $db;
}
}
try {
- $this->db = $this->lb->getConnection( DB_REPLICA, 'dump' );
+ $this->db = $this->lb->getMaintenanceConnectionRef( DB_REPLICA, 'dump' );
} catch ( Exception $e ) {
throw new MWException( __METHOD__
. " rotating DB failed to obtain new database (" . $e->getMessage() . ")" );
}
if ( $d > 1 ) {
# Set DBO_DEBUG (equivalent of $wgDebugDumpSql)
- wfGetDB( DB_MASTER )->setFlag( DBO_DEBUG );
- wfGetDB( DB_REPLICA )->setFlag( DBO_DEBUG );
+ $this->getDB( DB_MASTER )->setFlag( DBO_DEBUG );
+ $this->getDB( DB_REPLICA )->setFlag( DBO_DEBUG );
}
}
$index = DB_MASTER;
}
- /** @var IDatabase $db DB handle for the appropriate cluster/wiki */
- $db = $lb->getConnection( $index, [], $wiki );
+ $db = $lb->getMaintenanceConnectionRef( $index, [], $wiki );
if ( $replicaDB != '' && $db->getLBInfo( 'master' ) !== null ) {
$this->fatalError( "The server selected ({$db->getServer()}) is not a replica DB." );
}
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$lb = $lbFactory->getExternalLB( $cluster );
- return $lb->getConnection( DB_REPLICA );
+ return $lb->getMaintenanceConnectionRef( DB_REPLICA );
}
public function execute() {
* @ingroup Maintenance ExternalStorage
*/
+use Wikimedia\Rdbms\IMaintainableDatabase;
use MediaWiki\Logger\LegacyLogger;
use MediaWiki\MediaWikiServices;
use MediaWiki\Shell\Shell;
-use Wikimedia\Rdbms\IDatabase;
$optionsWithArgs = RecompressTracked::getOptionsWithArgs();
require __DIR__ . '/../commandLine.inc';
/**
* Dispatch a command to the next available replica DB.
* This may block until a replica DB finishes its work and becomes available.
+ * @param array ...$args
*/
function dispatch( ...$args ) {
$pipes = $this->replicaPipes;
/**
* Gets a DB master connection for the given external cluster name
* @param string $cluster
- * @return IDatabase
+ * @return IMaintainableDatabase
*/
function getExtDB( $cluster ) {
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$lb = $lbFactory->getExternalLB( $cluster );
- return $lb->getConnection( DB_MASTER );
+ return $lb->getMaintenanceConnectionRef( DB_MASTER );
}
/**
$pos = $dbw->getMasterPos();
$dbr->masterPosWait( $pos, 100000 );
- $textClause = $this->getTextClause( $this->clusters );
+ $textClause = $this->getTextClause();
$startId = 0;
$endId = $dbr->selectField( 'text', 'MAX(old_id)', '', __METHOD__ );
$rowsInserted = 0;
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$lb = $lbFactory->getExternalLB( $cluster );
try {
- $extDB = $lb->getConnection( DB_REPLICA );
+ $extDB = $lb->getMaintenanceConnectionRef( DB_REPLICA );
} catch ( DBConnectionError $e ) {
- if ( strpos( $e->error, 'Unknown database' ) !== false ) {
+ if ( strpos( $e->getMessage(), 'Unknown database' ) !== false ) {
echo "No database on $cluster\n";
} else {
echo "Error on $cluster: " . $e->getMessage() . "\n";
foreach ( $res as $row ) {
gmp_setbit( $actualBlobs, $row->blob_id );
+ $startId = $row->blob_id;
}
- $startId = $row->blob_id;
++$batchesDone;
if ( $batchesDone >= $this->reportingInterval ) {