74 parent::__construct( $config );
76 $this->dbServers = $config[
'dbServers'];
78 $this->srvsByBucket = array_filter( $config[
'dbsByBucket'],
'is_array' );
79 $this->srvsByBucket = array_values( $this->srvsByBucket );
81 if ( isset( $config[
'lockExpiry'] ) ) {
82 $this->lockExpiry = $config[
'lockExpiry'];
84 $met = ini_get(
'max_execution_time' );
85 $this->lockExpiry = $met ?: 60;
87 $this->safeDelay = ( $this->lockExpiry <= 0 )
93 $this->statusCache = $config[
'srvCache'] ??
new HashBagOStuff();
104 foreach ( $pathsByType as
$type => $paths ) {
146 if ( !isset( $this->conns[$lockDb] ) ) {
147 if ( $this->dbServers[$lockDb] instanceof
IDatabase ) {
149 $db = $this->dbServers[$lockDb];
150 } elseif ( is_array( $this->dbServers[$lockDb] ) ) {
152 $config = $this->dbServers[$lockDb];
153 $config[
'flags'] = ( $config[
'flags'] ?? 0 );
155 $db = Database::factory( $config[
'type'], $config );
157 throw new UnexpectedValueException(
"No server called '$lockDb'." );
159 # If the connection drops, try to avoid letting the DB rollback
160 # and release the locks before the file operations are finished.
161 # This won't handle the case of DB server restarts however.
163 if ( $this->lockExpiry > 0 ) {
166 $db->setSessionOptions( $options );
169 $this->conns[$lockDb] = $db;
172 return $this->conns[$lockDb];
193 return ( $this->safeDelay > 0 )
194 ? !$this->statusCache->get( $this->
getMissKey( $lockDb ) )
205 return ( $this->safeDelay > 0 )
206 ? $this->statusCache->set( $this->
getMissKey( $lockDb ), 1, $this->safeDelay )
217 return 'dblockmanager:downservers:' . str_replace(
' ',
'_', $lockDb );
225 foreach ( $this->conns as $db ) {