X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Floadbalancer%2FILoadBalancer.php;h=e246b79f805de3df235be94b3b79a5aa18c61015;hb=495e8ddf7e6940777f3318a1a2e37d85bfdbdbf1;hp=c9403929a0c24802cd6876f476fc8f43e1f871c9;hpb=7bada04561bf0b9f6e3d4225991b51e87c006750;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php index c9403929a0..e246b79f80 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,6 +96,7 @@ 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] * - wanCache : WANObjectCache object [optional] * - chronologyProtector: ChronologyProtector object [optional] @@ -168,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 @@ -193,42 +200,51 @@ 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 @@ -236,14 +252,17 @@ interface ILoadBalancer { * 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 (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,30 +294,20 @@ 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 ); /** - * Return the server info structure for a given index, or false if the index is invalid. - * @param int $i - * @return array|bool + * Get DB type of the server with the specified index * - * @deprecated Since 1.30, no alternative - */ - public function getServerInfo( $i ); - - /** - * Sets the server info structure for the given index. Entry at index $i - * is created if it doesn't exist * @param int $i - * @param array $serverInfo - * - * @deprecated Since 1.30, construct new object + * @return string One of (mysql,postgres,sqlite,...) or "unknown" for bad indexes + * @since 1.30 */ - public function setServerInfo( $i, array $serverInfo ); + public function getServerType( $i ); /** * Get the current master position for chronology control purposes