Simpler RedisLockManager configuration

I set up a local test instance with RedisLockManager, but some things
seemed more complicated than they needed to be. So:

* Add lockManager option to $wgLocalFileRepo, which becomes the
  lockManager of the auto-generated file backend.
* Made srvsByBucket be optional. I made the same change to the identical
  code in MemcLockManager and DBLockManager, but I didn't test them.
* Improved doc comments for RedisLockManager::__construct() and
  $wgLocalFileRepo.

Change-Id: I8ce430b8e849589d4ea87c90a56ee3659da085a0
This commit is contained in:
Tim Starling 2021-11-02 12:32:22 +11:00
parent cecf964f84
commit 06fc5ddb56
5 changed files with 43 additions and 19 deletions

View file

@ -585,7 +585,15 @@ $wgImgAuthUrlPathMap = [];
*
* - name A unique name for the repository (but $wgLocalFileRepo should be 'local').
* The name should consist of alpha-numeric characters.
* - backend A file backend name (see $wgFileBackends).
*
* Optional common properties:
* - backend A file backend name (see $wgFileBackends). If not specified, or
* if the name is not present in $wgFileBackends, an FSFileBackend
* will automatically be configured.
* - lockManager If a file backend is automatically configured, this will be lock
* manager name used. A lock manager named in $wgLockManagers, or one of
* the default lock managers "fsLockManager" or "nullLockManager". Default
* "fsLockManager".
*
* For most core repos:
* - zones Associative array of zone names that each map to an array with:

View file

@ -118,11 +118,12 @@ class FileBackendGroup {
$deletedDir = $info['deletedDir'] ?? false; // deletion disabled
$thumbDir = $info['thumbDir'] ?? "{$directory}/thumb";
$transcodedDir = $info['transcodedDir'] ?? "{$directory}/transcoded";
$lockManager = $info['lockManager'] ?? 'fsLockManager';
// Get the FS backend configuration
$autoBackends[] = [
'name' => $backendName,
'class' => FSFileBackend::class,
'lockManager' => 'fsLockManager',
'lockManager' => $lockManager,
'containerPaths' => [
"{$repoName}-public" => "{$directory}",
"{$repoName}-thumb" => $thumbDir,

View file

@ -65,8 +65,9 @@ abstract class DBLockManager extends QuorumLockManager {
* - password : DB user password
* - tablePrefix : DB table prefix
* - flags : DB flags; bitfield of IDatabase::DBO_* constants
* - dbsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
* each having an odd-numbered list of DB names (peers) as values.
* - dbsByBucket : An array of up to 16 arrays, each containing the DB names
* in a bucket. Each bucket should have an odd number of servers.
* If omitted, all DBs will be in one bucket. (optional).
* - lockExpiry : Lock timeout (seconds) for dropped connections. [optional]
* This tells the DB server how long to wait before assuming
* connection failure and releasing all the locks for a session.
@ -76,9 +77,13 @@ abstract class DBLockManager extends QuorumLockManager {
parent::__construct( $config );
$this->dbServers = $config['dbServers'];
if ( isset( $config['dbsByBucket'] ) ) {
// Sanitize srvsByBucket config to prevent PHP errors
$this->srvsByBucket = array_filter( $config['dbsByBucket'], 'is_array' );
$this->srvsByBucket = array_values( $this->srvsByBucket ); // consecutive
} else {
$this->srvsByBucket = [ array_keys( $this->dbServers ) ];
}
if ( isset( $config['lockExpiry'] ) ) {
$this->lockExpiry = $config['lockExpiry'];

View file

@ -54,8 +54,9 @@ class MemcLockManager extends QuorumLockManager {
*
* @param array $config Parameters include:
* - lockServers : Associative array of server names to "<IP>:<port>" strings.
* - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
* each having an odd-numbered list of server names (peers) as values.
* - srvsByBucket : An array of up to 16 arrays, each containing the server names
* in a bucket. Each bucket should have an odd number of servers.
* If omitted, all servers will be in one bucket. [optional].
* - memcConfig : Configuration array for MemcachedBagOStuff::construct() with an
* additional 'class' parameter specifying which MemcachedBagOStuff
* subclass to use. The server names will be injected. [optional]
@ -64,9 +65,13 @@ class MemcLockManager extends QuorumLockManager {
public function __construct( array $config ) {
parent::__construct( $config );
if ( isset( $config['srvsByBucket'] ) ) {
// Sanitize srvsByBucket config to prevent PHP errors
$this->srvsByBucket = array_filter( $config['srvsByBucket'], 'is_array' );
$this->srvsByBucket = array_values( $this->srvsByBucket ); // consecutive
} else {
$this->srvsByBucket = [ array_keys( $config['lockServers'] ) ];
}
$memcConfig = $config['memcConfig'] ?? [];
$memcConfig += [ 'class' => MemcachedPhpBagOStuff::class ]; // default

View file

@ -32,7 +32,7 @@
* bucket. Each bucket maps to one or several peer servers, each running redis.
* A majority of peers must agree for a lock to be acquired.
*
* This class requires Redis 2.6 as it makes use Lua scripts for fast atomic operations.
* This class requires Redis 2.6 as it makes use of Lua scripts for fast atomic operations.
*
* @ingroup LockManager
* @since 1.22
@ -56,18 +56,23 @@ class RedisLockManager extends QuorumLockManager {
*
* @param array $config Parameters include:
* - lockServers : Associative array of server names to "<IP>:<port>" strings.
* - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
* each having an odd-numbered list of server names (peers) as values.
* - redisConfig : Configuration for RedisConnectionPool::__construct().
* - srvsByBucket : An array of up to 16 arrays, each containing the server names
* in a bucket. Each bucket should have an odd number of servers.
* If omitted, all servers will be in one bucket. (optional).
* - redisConfig : Configuration for RedisConnectionPool::singleton() (optional).
* @throws Exception
*/
public function __construct( array $config ) {
parent::__construct( $config );
$this->lockServers = $config['lockServers'];
if ( isset( $config['srvsByBucket'] ) ) {
// Sanitize srvsByBucket config to prevent PHP errors
$this->srvsByBucket = array_filter( $config['srvsByBucket'], 'is_array' );
$this->srvsByBucket = array_values( $this->srvsByBucket ); // consecutive
} else {
$this->srvsByBucket = [ array_keys( $this->lockServers ) ];
}
$config['redisConfig']['serializer'] = 'none';
$this->redisPool = RedisConnectionPool::singleton( $config['redisConfig'] );