X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Floadbalancer%2FILoadBalancer.php;h=86c43350a0944a10328dff41aff34cb27899a309;hb=6bd1e23f4a281b05e6c171653a715c394aac36d6;hp=acb4dce5f62c7bd59e837d2b58371808b76c1e6a;hpb=10d1b7d12b5d097413cd507740c5c71781c2580b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php index acb4dce5f6..86c43350a0 100644 --- a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php @@ -76,14 +76,17 @@ use InvalidArgumentException; * @ingroup Database */ interface ILoadBalancer { - /** @var integer Request a replica DB connection */ + /** @var int Request a replica DB connection */ const DB_REPLICA = -1; - /** @var integer Request a master DB connection */ + /** @var int Request a master DB connection */ const DB_MASTER = -2; /** @var string Domain specifier when no specific database needs to be selected */ const DOMAIN_ANY = ''; + /** @var int DB handle should have DBO_TRX disabled and the caller will leave it as such */ + const CONN_TRX_AUTO = 1; + /** * Construct a manager of IDatabase connection objects * @@ -93,8 +96,8 @@ interface ILoadBalancer { * - loadMonitor : Name of a class used to fetch server lag and load. * - readOnlyReason : Reason the master DB is read-only if so [optional] * - waitTimeout : Maximum time to wait for replicas for consistency [optional] + * - maxLag: Avoid replica DB servers with more lag than this [optional] * - srvCache : BagOStuff object for server cache [optional] - * - memCache : BagOStuff object for cluster memory cache [optional] * - wanCache : WANObjectCache object [optional] * - chronologyProtector: ChronologyProtector object [optional] * - hostname : The name of the current server [optional] @@ -169,14 +172,17 @@ interface ILoadBalancer { /** * Get a connection by index * + * Avoid using CONN_TRX_AUTO with sqlite (e.g. check getServerType() first) + * * @param int $i Server index or DB_MASTER/DB_REPLICA * @param array|string|bool $groups Query group(s), or false for the generic reader * @param string|bool $domain Domain ID, or false for the current domain + * @param int $flags Bitfield of CONN_* class constants * * @throws DBError * @return Database */ - public function getConnection( $i, $groups = [], $domain = false ); + public function getConnection( $i, $groups = [], $domain = false, $flags = 0 ); /** * Mark a foreign connection as being available for reuse under a different DB domain @@ -194,56 +200,69 @@ interface ILoadBalancer { * * The handle's methods simply wrap those of a Database handle * + * Avoid using CONN_TRX_AUTO with sqlite (e.g. check getServerType() first) + * * @see ILoadBalancer::getConnection() for parameter information * * @param int $i Server index or DB_MASTER/DB_REPLICA * @param array|string|bool $groups Query group(s), or false for the generic reader * @param string|bool $domain Domain ID, or false for the current domain + * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTO) * @return DBConnRef */ - public function getConnectionRef( $i, $groups = [], $domain = false ); + public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ); /** * Get a database connection handle reference without connecting yet * * The handle's methods simply wrap those of a Database handle * + * Avoid using CONN_TRX_AUTO with sqlite (e.g. check getServerType() first) + * * @see ILoadBalancer::getConnection() for parameter information * * @param int $i Server index or DB_MASTER/DB_REPLICA * @param array|string|bool $groups Query group(s), or false for the generic reader * @param string|bool $domain Domain ID, or false for the current domain + * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTO) * @return DBConnRef */ - public function getLazyConnectionRef( $i, $groups = [], $domain = false ); + public function getLazyConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ); /** * Get a maintenance database connection handle reference for migrations and schema changes * * The handle's methods simply wrap those of a Database handle * + * Avoid using CONN_TRX_AUTO with sqlite (e.g. check getServerType() first) + * * @see ILoadBalancer::getConnection() for parameter information * * @param int $db Server index or DB_MASTER/DB_REPLICA * @param array|string|bool $groups Query group(s), or false for the generic reader * @param string|bool $domain Domain ID, or false for the current domain + * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTO) * @return MaintainableDBConnRef */ - public function getMaintenanceConnectionRef( $db, $groups = [], $domain = false ); + public function getMaintenanceConnectionRef( $db, $groups = [], $domain = false, $flags = 0 ); /** * Open a connection to the server given by the specified index - * Index must be an actual index into the array. - * If the server is already open, returns it. + * + * The index must be an actual index into the array. If a connection to the server is + * already open and not considered an "in use" foreign connection, this simply returns it. + * + * Avoid using CONN_TRX_AUTO with sqlite (e.g. check getServerType() first) * * @note If disable() was called on this LoadBalancer, this method will throw a DBAccessError. * - * @param int $i Server index or DB_MASTER/DB_REPLICA + * @param int $i Server index (does not support DB_MASTER/DB_REPLICA) * @param string|bool $domain Domain ID, or false for the current domain + * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTO) * @return Database|bool Returns false on errors * @throws DBAccessError */ - public function openConnection( $i, $domain = false ); + public function openConnection( $i, $domain = false, $flags = 0 ); /** * @return int @@ -253,7 +272,7 @@ interface ILoadBalancer { /** * Returns true if the specified index is a valid server index * - * @param string $i + * @param int $i * @return bool */ public function haveIndex( $i ); @@ -261,7 +280,7 @@ interface ILoadBalancer { /** * Returns true if the specified index is valid and has non-zero load * - * @param string $i + * @param int $i * @return bool */ public function isNonZeroLoad( $i ); @@ -275,12 +294,21 @@ interface ILoadBalancer { /** * Get the host name or IP address of the server with the specified index - * Prefer a readable name if available. - * @param string $i - * @return string + * + * @param int $i + * @return string Readable name if available or IP/host otherwise */ public function getServerName( $i ); + /** + * Get DB type of the server with the specified index + * + * @param int $i + * @return string One of (mysql,postgres,sqlite,...) or "unknown" for bad indexes + * @since 1.30 + */ + public function getServerType( $i ); + /** * Return the server info structure for a given index, or false if the index is invalid. * @param int $i