/** @var DatabaseDomain Local DB domain ID and default for selectDB() calls */
private $localDomain;
- /** @var Database[][][] Map of (connection category => server index => IDatabase[]) */
+ /**
+ * @var IDatabase[][][]|Database[][][] Map of (connection category => server index => IDatabase[])
+ */
private $conns;
/** @var array[] Map of (server index => server config array) */
private $tableAliases = [];
/** @var string[] Map of (index alias => index) */
private $indexAliases = [];
- /** @var array[] Map of (name => callable) */
+ /** @var callable[] Map of (name => callable) */
private $trxRecurringCallbacks = [];
/** @var bool[] Map of (domain => whether to use "temp tables only" mode) */
private $tempTablesOnlyMode = [];
$serverIndex = $conn->getLBInfo( 'serverIndex' );
$refCount = $conn->getLBInfo( 'foreignPoolRefCount' );
if ( $serverIndex === null || $refCount === null ) {
- /**
- * This can happen in code like:
- * foreach ( $dbs as $db ) {
- * $conn = $lb->getConnection( $lb::DB_REPLICA, [], $db );
- * ...
- * $lb->reuseConnection( $conn );
- * }
- * When a connection to the local DB is opened in this way, reuseConnection()
- * should be ignored
- */
- return;
+ return; // non-foreign connection; no domain-use tracking to update
} elseif ( $conn instanceof DBConnRef ) {
// DBConnRef already handles calling reuseConnection() and only passes the live
// Database instance to this method. Any caller passing in a DBConnRef is broken.
// Create a live connection object
try {
- $db = Database::factory( $server['type'], $server );
+ $conn = Database::factory( $server['type'], $server );
// Log when many connection are made on requests
++$this->connectionCounter;
$currentConnCount = $this->getCurrentConnectionCount();
} catch ( DBConnectionError $e ) {
// FIXME: This is probably the ugliest thing I have ever done to
// PHP. I'm half-expecting it to segfault, just out of disgust. -- TS
- $db = $e->db;
+ $conn = $e->db;
}
- $db->setLBInfo( $server );
- $db->setLazyMasterHandle(
- $this->getLazyConnectionRef( self::DB_MASTER, [], $db->getDomainID() )
+ $conn->setLBInfo( $server );
+ $conn->setLazyMasterHandle(
+ $this->getLazyConnectionRef( self::DB_MASTER, [], $conn->getDomainID() )
);
- $db->setTableAliases( $this->tableAliases );
- $db->setIndexAliases( $this->indexAliases );
+ $conn->setTableAliases( $this->tableAliases );
+ $conn->setIndexAliases( $this->indexAliases );
if ( $server['serverIndex'] === $this->getWriterIndex() ) {
if ( $this->trxRoundId !== false ) {
- $this->applyTransactionRoundFlags( $db );
+ $this->applyTransactionRoundFlags( $conn );
}
foreach ( $this->trxRecurringCallbacks as $name => $callback ) {
- $db->setTransactionListener( $name, $callback );
+ $conn->setTransactionListener( $name, $callback );
}
}
$this->lazyLoadReplicationPositions(); // session consistency
- return $db;
+ return $conn;
}
/**
}
public function closeAll() {
+ if ( $this->ownerId === null ) {
+ /** @noinspection PhpUnusedLocalVariableInspection */
+ $scope = ScopedCallback::newScopedIgnoreUserAbort();
+ }
+
$fname = __METHOD__;
$this->forEachOpenConnection( function ( IDatabase $conn ) use ( $fname ) {
$host = $conn->getServer();
public function finalizeMasterChanges( $fname = __METHOD__, $owner = null ) {
$this->assertOwnership( $fname, $owner );
$this->assertTransactionRoundStage( [ self::ROUND_CURSORY, self::ROUND_FINALIZED ] );
+ if ( $this->ownerId === null ) {
+ /** @noinspection PhpUnusedLocalVariableInspection */
+ $scope = ScopedCallback::newScopedIgnoreUserAbort();
+ }
$this->trxRoundStage = self::ROUND_ERROR; // "failed" until proven otherwise
// Loop until callbacks stop adding callbacks on other connections
public function approveMasterChanges( array $options, $fname = __METHOD__, $owner = null ) {
$this->assertOwnership( $fname, $owner );
$this->assertTransactionRoundStage( self::ROUND_FINALIZED );
+ if ( $this->ownerId === null ) {
+ /** @noinspection PhpUnusedLocalVariableInspection */
+ $scope = ScopedCallback::newScopedIgnoreUserAbort();
+ }
$limit = $options['maxWriteDuration'] ?? 0;
);
}
$this->assertTransactionRoundStage( self::ROUND_CURSORY );
+ if ( $this->ownerId === null ) {
+ /** @noinspection PhpUnusedLocalVariableInspection */
+ $scope = ScopedCallback::newScopedIgnoreUserAbort();
+ }
// Clear any empty transactions (no writes/callbacks) from the implicit round
$this->flushMasterSnapshots( $fname );
public function commitMasterChanges( $fname = __METHOD__, $owner = null ) {
$this->assertOwnership( $fname, $owner );
$this->assertTransactionRoundStage( self::ROUND_APPROVED );
+ if ( $this->ownerId === null ) {
+ /** @noinspection PhpUnusedLocalVariableInspection */
+ $scope = ScopedCallback::newScopedIgnoreUserAbort();
+ }
$failures = [];
- /** @noinspection PhpUnusedLocalVariableInspection */
- $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
-
$restore = ( $this->trxRoundId !== false );
$this->trxRoundId = false;
$this->trxRoundStage = self::ROUND_ERROR; // "failed" until proven otherwise
"Transaction should be in the callback stage (not '{$this->trxRoundStage}')"
);
}
+ if ( $this->ownerId === null ) {
+ /** @noinspection PhpUnusedLocalVariableInspection */
+ $scope = ScopedCallback::newScopedIgnoreUserAbort();
+ }
$oldStage = $this->trxRoundStage;
$this->trxRoundStage = self::ROUND_ERROR; // "failed" until proven otherwise
"Transaction should be in the callback stage (not '{$this->trxRoundStage}')"
);
}
+ if ( $this->ownerId === null ) {
+ /** @noinspection PhpUnusedLocalVariableInspection */
+ $scope = ScopedCallback::newScopedIgnoreUserAbort();
+ }
$e = null;
public function rollbackMasterChanges( $fname = __METHOD__, $owner = null ) {
$this->assertOwnership( $fname, $owner );
+ if ( $this->ownerId === null ) {
+ /** @noinspection PhpUnusedLocalVariableInspection */
+ $scope = ScopedCallback::newScopedIgnoreUserAbort();
+ }
$restore = ( $this->trxRoundId !== false );
$this->trxRoundId = false;
) );
// Update the prefix for all local connections...
- $this->forEachOpenConnection( function ( IDatabase $db ) use ( $prefix ) {
- if ( !$db->getLBInfo( 'foreign' ) ) {
- $db->tablePrefix( $prefix );
+ $this->forEachOpenConnection( function ( IDatabase $conn ) use ( $prefix ) {
+ if ( !$conn->getLBInfo( 'foreign' ) ) {
+ $conn->tablePrefix( $prefix );
}
} );
}