* - servers : Required. Array of server info structures.
* - loadMonitor : Name of a class used to fetch server lag and load.
* - readOnlyReason : Reason the master DB is read-only if so [optional]
+ * - srvCache : BagOStuff object [optional]
+ * - wanCache : WANObjectCache object [optional]
* @throws MWException
*/
public function __construct( array $params ) {
}
}
- $this->srvCache = ObjectCache::getLocalServerInstance();
- $this->wanCache = ObjectCache::getMainWANInstance();
-
+ if ( isset( $params['srvCache'] ) ) {
+ $this->srvCache = $params['srvCache'];
+ } else {
+ $this->srvCache = new EmptyBagOStuff();
+ }
+ if ( isset( $params['wanCache'] ) ) {
+ $this->wanCache = $params['wanCache'];
+ } else {
+ $this->wanCache = WANObjectCache::newEmpty();
+ }
if ( isset( $params['trxProfiler'] ) ) {
$this->trxProfiler = $params['trxProfiler'];
} else {
/**
* This can happen in code like:
* foreach ( $dbs as $db ) {
- * $conn = $lb->getConnection( DB_SLAVE, array(), $db );
+ * $conn = $lb->getConnection( DB_SLAVE, [], $db );
* ...
* $lb->reuseConnection( $conn );
* }
$cache->makeGlobalKey( __CLASS__, 'server-read-only', $masterServer ),
self::TTL_CACHE_READONLY,
function () use ( $wiki, $conn ) {
+ $this->trxProfiler->setSilenced( true );
try {
$dbw = $conn ?: $this->getConnection( DB_MASTER, [], $wiki );
- return (int)$dbw->serverIsReadOnly();
+ $readOnly = (int)$dbw->serverIsReadOnly();
} catch ( DBError $e ) {
- return 0;
+ $readOnly = 0;
}
+ $this->trxProfiler->setSilenced( false );
+ return $readOnly;
},
[ 'pcTTL' => $cache::TTL_PROC_LONG, 'busyValue' => 0 ]
);