protected $wanCache;
/** @var string Local domain */
- protected $domain;
+ protected $localDomain;
/** @var string Local hostname of the app server */
protected $hostname;
/** @var mixed */
/** @var callable[] */
protected $replicationWaitCallbacks = [];
+ /** @var bool Whether this PHP instance is for a CLI script */
+ protected $cliMode;
+ /** @var string Agent name for query profiling */
+ protected $agent;
+
const SHUTDOWN_NO_CHRONPROT = 0; // don't save DB positions at all
const SHUTDOWN_CHRONPROT_ASYNC = 1; // save DB positions, but don't wait on remote DCs
const SHUTDOWN_CHRONPROT_SYNC = 2; // save DB positions, waiting on all DCs
* @param array $conf
*/
public function __construct( array $conf ) {
- $this->domain = isset( $conf['domain'] ) ? $conf['domain'] : '';
+ $this->localDomain = isset( $conf['localDomain'] ) ? $conf['localDomain'] : '';
+
if ( isset( $conf['readOnlyReason'] ) && is_string( $conf['readOnlyReason'] ) ) {
$this->readOnlyReason = $conf['readOnlyReason'];
}
$this->errorLogger = isset( $conf['errorLogger'] )
? $conf['errorLogger']
: function ( Exception $e ) {
- trigger_error( E_WARNING, $e->getMessage() );
+ trigger_error( E_WARNING, get_class( $e ) . ': ' . $e->getMessage() );
};
$this->hostname = isset( $conf['hostname'] )
? $conf['hostname']
: new TransactionProfiler();
$this->ticket = mt_rand();
+ $this->cliMode = isset( $params['cliMode'] ) ? $params['cliMode'] : PHP_SAPI === 'cli';
+ $this->agent = isset( $params['agent'] ) ? $params['agent'] : '';
}
/**
$failed = [];
foreach ( $lbs as $i => $lb ) {
if ( $masterPositions[$i] ) {
- // The DBMS may not support getMasterPos() or the whole
- // load balancer might be fake (e.g. $wgAllDBsAreLocalhost).
+ // The DBMS may not support getMasterPos()
if ( !$lb->waitForAll( $masterPositions[$i], $opts['timeout'] ) ) {
$failed[] = $lb->getServerName( $lb->getWriterIndex() );
}
isset( $_GET['cpPosTime'] ) ? $_GET['cpPosTime'] : null
);
$chronProt->setLogger( $this->replLogger );
- if ( PHP_SAPI === 'cli' ) {
+ if ( $this->cliMode ) {
$chronProt->setEnabled( false );
}
*/
final protected function baseLoadBalancerParams() {
return [
- 'localDomain' => $this->domain,
+ 'localDomain' => $this->localDomain,
'readOnlyReason' => $this->readOnlyReason,
'srvCache' => $this->srvCache,
'wanCache' => $this->wanCache,
'connLogger' => $this->connLogger,
'replLogger' => $this->replLogger,
'errorLogger' => $this->errorLogger,
- 'hostname' => $this->hostname
+ 'hostname' => $this->hostname,
+ 'cliMode' => $this->cliMode,
+ 'agent' => $this->agent
];
}
}
/**
- * Define a new local domain (for testing)
- *
- * Caller should make sure no local connection are open to the old local domain
+ * Set a new table prefix for the existing local domain ID for testing
*
- * @param string $domain
+ * @param string $prefix
* @since 1.28
*/
- public function setDomainPrefix( $domain ) {
- $this->domain = $domain;
+ public function setDomainPrefix( $prefix ) {
+ list( $dbName, ) = explode( '-', $this->localDomain, 2 );
+ $this->localDomain = "{$dbName}-{$prefix}";
+
+ $this->forEachLB( function( LoadBalancer $lb ) use ( $prefix ) {
+ $lb->setDomainPrefix( $prefix );
+ } );
}
/**
public function closeAll() {
$this->forEachLBCallMethod( 'closeAll', [] );
}
+
+ /**
+ * @param string $agent Agent name for query profiling
+ * @since 1.28
+ */
+ public function setAgentName( $agent ) {
+ $this->agent = $agent;
+ }
}