*/
public function destroy();
+ /**
+ * Get the local (and default) database domain ID of connection handles
+ *
+ * @see DatabaseDomain
+ * @return string Database domain ID; this specifies DB name, schema, and table prefix
+ * @since 1.32
+ */
+ public function getLocalDomainID();
+
+ /**
+ * @param DatabaseDomain|string|bool $domain Database domain
+ * @return string Value of $domain if provided or the local domain otherwise
+ * @since 1.32
+ */
+ public function resolveDomainID( $domain );
+
/**
* Create a new load balancer object. The resulting object will be untracked,
* not chronology-protected, and the caller is responsible for cleaning it up.
$this->forEachLBCallMethod( 'disable' );
}
+ public function getLocalDomainID() {
+ return $this->localDomain->getId();
+ }
+
+ public function resolveDomainID( $domain ) {
+ return ( $domain !== false ) ? (string)$domain : $this->getLocalDomainID();
+ }
+
public function shutdown(
$mode = self::SHUTDOWN_CHRONPROT_SYNC,
callable $workCallback = null,
*/
public function __construct( array $params );
+ /**
+ * Get the local (and default) database domain ID of connection handles
+ *
+ * @see DatabaseDomain
+ * @return string Database domain ID; this specifies DB name, schema, and table prefix
+ * @since 1.31
+ */
+ public function getLocalDomainID();
+
+ /**
+ * @param DatabaseDomain|string|bool $domain Database domain
+ * @return string Value of $domain if provided or the local domain otherwise
+ * @since 1.32
+ */
+ public function resolveDomainID( $domain );
+
/**
* Get the index of the reader connection, which may be a replica DB
*
$this->defaultGroup = $params['defaultGroup'] ?? null;
}
- /**
- * Get the local (and default) database domain ID of connection handles
- *
- * @see DatabaseDomain
- * @return string Database domain ID; this specifies DB name, schema, and table prefix
- * @since 1.31
- */
public function getLocalDomainID() {
return $this->localDomain->getId();
}
+ public function resolveDomainID( $domain ) {
+ return ( $domain !== false ) ? (string)$domain : $this->getLocalDomainID();
+ }
+
/**
* Get a LoadMonitor instance
*
}
public function getConnectionRef( $db, $groups = [], $domain = false, $flags = 0 ) {
- $domain = ( $domain !== false ) ? $domain : $this->localDomain;
+ $domain = $this->resolveDomainID( $domain );
return new DBConnRef( $this, $this->getConnection( $db, $groups, $domain, $flags ) );
}
public function getLazyConnectionRef( $db, $groups = [], $domain = false, $flags = 0 ) {
- $domain = ( $domain !== false ) ? $domain : $this->localDomain;
+ $domain = $this->resolveDomainID( $domain );
return new DBConnRef( $this, [ $db, $groups, $domain, $flags ] );
}
public function getMaintenanceConnectionRef( $db, $groups = [], $domain = false, $flags = 0 ) {
- $domain = ( $domain !== false ) ? $domain : $this->localDomain;
+ $domain = $this->resolveDomainID( $domain );
return new MaintainableDBConnRef(
$this, $this->getConnection( $db, $groups, $domain, $flags ) );
];
}
+ /**
+ * @covers LBFactory::getLocalDomainID()
+ * @covers LBFactory::resolveDomainID()
+ */
public function testLBFactorySimpleServer() {
global $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBtype, $wgSQLiteDataDir;
$dbr = $lb->getConnection( DB_REPLICA );
$this->assertTrue( $dbr->getLBInfo( 'master' ), 'DB_REPLICA also gets the master' );
+ $this->assertSame( 'my_test_wiki', $factory->resolveDomainID( 'my_test_wiki' ) );
+ $this->assertSame( $factory->getLocalDomainID(), $factory->resolveDomainID( false ) );
+
$factory->shutdown();
$lb->closeAll();
}
];
}
+ /**
+ * @covers LoadBalancer::getLocalDomainID()
+ * @covers LoadBalancer::resolveDomainID()
+ */
public function testWithoutReplica() {
global $wgDBname;
$ld = DatabaseDomain::newFromId( $lb->getLocalDomainID() );
$this->assertEquals( $wgDBname, $ld->getDatabase(), 'local domain DB set' );
$this->assertEquals( $this->dbPrefix(), $ld->getTablePrefix(), 'local domain prefix set' );
+ $this->assertSame( 'my_test_wiki', $lb->resolveDomainID( 'my_test_wiki' ) );
+ $this->assertSame( $ld->getId(), $lb->resolveDomainID( false ) );
+ $this->assertSame( $ld->getId(), $lb->resolveDomainID( $ld ) );
$this->assertFalse( $called );
$dbw = $lb->getConnection( DB_MASTER );