77 parent::__construct( $config );
79 $this->dbServers = $config[
'dbServers'];
80 if ( isset( $config[
'dbsByBucket'] ) ) {
82 $this->srvsByBucket = array_filter( $config[
'dbsByBucket'],
'is_array' );
83 $this->srvsByBucket = array_values( $this->srvsByBucket );
85 $this->srvsByBucket = [ array_keys( $this->dbServers ) ];
88 if ( isset( $config[
'lockExpiry'] ) ) {
89 $this->lockExpiry = $config[
'lockExpiry'];
91 $met = ini_get(
'max_execution_time' );
92 $this->lockExpiry = $met ?: 60;
94 $this->safeDelay = ( $this->lockExpiry <= 0 )
100 $this->statusCache = $config[
'srvCache'] ??
new HashBagOStuff();
111 $status = StatusValue::newGood();
112 foreach ( $pathsByType as
$type => $paths ) {
126 return StatusValue::newGood();
158 if ( !isset( $this->conns[$lockDb] ) ) {
159 if ( $this->dbServers[$lockDb] instanceof
IDatabase ) {
161 $db = $this->dbServers[$lockDb];
162 } elseif ( is_array( $this->dbServers[$lockDb] ) ) {
164 $config = $this->dbServers[$lockDb];
165 $config[
'flags'] = ( $config[
'flags'] ?? 0 );
166 $config[
'flags'] &= ~( IDatabase::DBO_TRX | IDatabase::DBO_DEFAULT );
167 $db = Database::factory( $config[
'type'], $config );
169 throw new UnexpectedValueException(
"No database connection for server called '$lockDb'." );
172 throw new UnexpectedValueException(
"No server called '$lockDb'." );
174 # If the connection drops, try to avoid letting the DB rollback
175 # and release the locks before the file operations are finished.
176 # This won't handle the case of DB server restarts however.
178 if ( $this->lockExpiry > 0 ) {
181 $db->setSessionOptions( $options );
184 $this->conns[$lockDb] = $db;
187 return $this->conns[$lockDb];
209 return ( $this->safeDelay > 0 )
210 ? !$this->statusCache->get( $this->
getMissKey( $lockDb ) )
221 return ( $this->safeDelay > 0 )
222 ? $this->statusCache->set( $this->
getMissKey( $lockDb ), 1, $this->safeDelay )
233 return 'dblockmanager:downservers:' . str_replace(
' ',
'_', $lockDb );
241 foreach ( $this->conns as $db ) {
242 $db->close( __METHOD__ );
Class representing a cache/ephemeral data store.
Version of LockManager based on using named/row DB locks.
__destruct()
Make sure remaining locks get cleared.
cacheRecordFailure( $lockDb)
Log a lock request failure to the cache.
IDatabase[] $conns
Map Database connections (DB name => Database)
freeLocksOnServer( $lockSrv, array $pathsByType)
Get a connection to a lock server and release locks on $paths.Subclasses must effectively implement t...
getMissKey( $lockDb)
Get a cache key for recent query misses for a DB.
getConnection( $lockDb)
Get (or reuse) a connection to a lock DB.
initConnection( $lockDb, IDatabase $db)
Do additional initialization for new lock DB connection.
getLocksOnServer( $lockSrv, array $pathsByType)
array[] IDatabase[] $dbServers
Map of (DB names => server config or IDatabase)
__construct(array $config)
Construct a new instance from configuration.
doGetLocksOnServer( $lockSrv, array $paths, $type)
cacheCheckFailures( $lockDb)
Checks if the DB has not recently had connection/query errors.
Simple store for keeping values in an associative array for the current process.
Version of LockManager that uses a quorum from peer servers for locks.
releaseAllLocks()
Release all locks that this session is holding.