Exemplo n.º 1
0
 /**
  * Construct a new instance from configuration.
  *
  * @param array $config Parameters include:
  *   - dbServers   : Associative array of DB names to server configuration.
  *                   Configuration is an associative array that includes:
  *                     - host        : DB server name
  *                     - dbname      : DB name
  *                     - type        : DB type (mysql,postgres,...)
  *                     - user        : DB user
  *                     - password    : DB user password
  *                     - tablePrefix : DB table prefix
  *                     - flags       : DB flags (see DatabaseBase)
  *   - dbsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
  *                   each having an odd-numbered list of DB names (peers) as values.
  *                   Any DB named 'localDBMaster' will automatically use the DB master
  *                   settings for this wiki (without the need for a dbServers entry).
  *                   Only use 'localDBMaster' if the domain is a valid wiki ID.
  *   - 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.
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $this->dbServers = isset($config['dbServers']) ? $config['dbServers'] : array();
     // likely just using 'localDBMaster'
     // Sanitize srvsByBucket config to prevent PHP errors
     $this->srvsByBucket = array_filter($config['dbsByBucket'], 'is_array');
     $this->srvsByBucket = array_values($this->srvsByBucket);
     // consecutive
     if (isset($config['lockExpiry'])) {
         $this->lockExpiry = $config['lockExpiry'];
     } else {
         $met = ini_get('max_execution_time');
         $this->lockExpiry = $met ? $met : 60;
         // use some sane amount if 0
     }
     $this->safeDelay = $this->lockExpiry <= 0 ? 60 : $this->lockExpiry;
     // cover worst case
     foreach ($this->srvsByBucket as $bucket) {
         if (count($bucket) > 1) {
             // multiple peers
             // Tracks peers that couldn't be queried recently to avoid lengthy
             // connection timeouts. This is useless if each bucket has one peer.
             try {
                 $this->statusCache = ObjectCache::newAccelerator();
             } catch (Exception $e) {
                 trigger_error(__CLASS__ . " using multiple DB peers without apc, xcache, or wincache.");
             }
             break;
         }
     }
     $this->session = wfRandomString(31);
 }
Exemplo n.º 2
0
 /**
  * Construct a new instance from configuration.
  *
  * @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().
  * @throws Exception
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $this->lockServers = $config['lockServers'];
     // Sanitize srvsByBucket config to prevent PHP errors
     $this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array');
     $this->srvsByBucket = array_values($this->srvsByBucket);
     // consecutive
     $config['redisConfig']['serializer'] = 'none';
     $this->redisPool = RedisConnectionPool::singleton($config['redisConfig']);
 }
Exemplo n.º 3
0
 /**
  * Construct a new instance from configuration.
  *
  * $config paramaters include:
  *   - lockServers  : Associative array of server names to configuration.
  *                    Configuration is an associative array that includes:
  *                      - host    : IP address/hostname
  *                      - port    : TCP port
  *                      - authKey : Secret string the lock server uses
  *   - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
  *                    each having an odd-numbered list of server names (peers) as values.
  *   - connTimeout  : Lock server connection attempt timeout. [optional]
  *
  * @param Array $config
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $this->lockServers = $config['lockServers'];
     // Sanitize srvsByBucket config to prevent PHP errors
     $this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array');
     $this->srvsByBucket = array_values($this->srvsByBucket);
     // consecutive
     if (isset($config['connTimeout'])) {
         $this->connTimeout = $config['connTimeout'];
     } else {
         $this->connTimeout = 3;
         // use some sane amount
     }
     $this->session = wfRandomString(32);
     // 128 bits
 }
Exemplo n.º 4
0
 /**
  * Construct a new instance from configuration.
  *
  * @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.
  *   - memcConfig   : Configuration array for ObjectCache::newFromParams. [optional]
  *                    If set, this must use one of the memcached classes.
  * @throws Exception
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     // Sanitize srvsByBucket config to prevent PHP errors
     $this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array');
     $this->srvsByBucket = array_values($this->srvsByBucket);
     // consecutive
     $memcConfig = isset($config['memcConfig']) ? $config['memcConfig'] : ['class' => 'MemcachedPhpBagOStuff'];
     foreach ($config['lockServers'] as $name => $address) {
         $params = ['servers' => [$address]] + $memcConfig;
         $cache = ObjectCache::newFromParams($params);
         if ($cache instanceof MemcachedBagOStuff) {
             $this->bagOStuffs[$name] = $cache;
         } else {
             throw new Exception('Only MemcachedBagOStuff classes are supported by MemcLockManager.');
         }
     }
     $this->session = wfRandomString(32);
 }
Exemplo n.º 5
0
 /**
  * Construct a new instance from configuration.
  *
  * @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.
  *   - memcConfig   : Configuration array for MemcachedBagOStuff::construct() with an
  *                    additional 'class' parameter specifying which MemcachedBagOStuff
  *                    subclass to use. The server names will be injected. [optional]
  * @throws Exception
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     // Sanitize srvsByBucket config to prevent PHP errors
     $this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array');
     $this->srvsByBucket = array_values($this->srvsByBucket);
     // consecutive
     $memcConfig = isset($config['memcConfig']) ? $config['memcConfig'] : [];
     $memcConfig += ['class' => 'MemcachedPhpBagOStuff'];
     // default
     $class = $memcConfig['class'];
     if (!is_subclass_of($class, 'MemcachedBagOStuff')) {
         throw new InvalidArgumentException("{$class} is not of type MemcachedBagOStuff.");
     }
     foreach ($config['lockServers'] as $name => $address) {
         $params = ['servers' => [$address]] + $memcConfig;
         $this->cacheServers[$name] = new $class($params);
     }
     $this->statusCache = new HashBagOStuff();
 }
Exemplo n.º 6
0
 /**
  * Construct a new instance from configuration.
  *
  * @param array $config Parameters include:
  *   - dbServers   : Associative array of DB names to server configuration.
  *                   Configuration is an associative array that includes:
  *                     - host        : DB server name
  *                     - dbname      : DB name
  *                     - type        : DB type (mysql,postgres,...)
  *                     - user        : DB user
  *                     - 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.
  *   - 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.
  *   - srvCache    : A BagOStuff instance using APC or the like.
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     $this->dbServers = $config['dbServers'];
     // Sanitize srvsByBucket config to prevent PHP errors
     $this->srvsByBucket = array_filter($config['dbsByBucket'], 'is_array');
     $this->srvsByBucket = array_values($this->srvsByBucket);
     // consecutive
     if (isset($config['lockExpiry'])) {
         $this->lockExpiry = $config['lockExpiry'];
     } else {
         $met = ini_get('max_execution_time');
         $this->lockExpiry = $met ? $met : 60;
         // use some sane amount if 0
     }
     $this->safeDelay = $this->lockExpiry <= 0 ? 60 : $this->lockExpiry;
     // cover worst case
     // Tracks peers that couldn't be queried recently to avoid lengthy
     // connection timeouts. This is useless if each bucket has one peer.
     $this->statusCache = isset($config['srvCache']) ? $config['srvCache'] : new HashBagOStuff();
 }
Exemplo n.º 7
0
 /**
  * Construct a new instance from configuration.
  *
  * $config paramaters 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.
  *   - memcConfig   : Configuration array for ObjectCache::newFromParams. [optional]
  *                    If set, this must use one of the memcached classes.
  *   - wikiId       : Wiki ID string that all resources are relative to. [optional]
  *
  * @param Array $config
  */
 public function __construct(array $config)
 {
     parent::__construct($config);
     // Sanitize srvsByBucket config to prevent PHP errors
     $this->srvsByBucket = array_filter($config['srvsByBucket'], 'is_array');
     $this->srvsByBucket = array_values($this->srvsByBucket);
     // consecutive
     $memcConfig = isset($config['memcConfig']) ? $config['memcConfig'] : array('class' => 'MemcachedPhpBagOStuff');
     foreach ($config['lockServers'] as $name => $address) {
         $params = array('servers' => array($address)) + $memcConfig;
         $cache = ObjectCache::newFromParams($params);
         if ($cache instanceof MemcachedBagOStuff) {
             $this->bagOStuffs[$name] = $cache;
         } else {
             throw new MWException('Only MemcachedBagOStuff classes are supported by MemcLockManager.');
         }
     }
     $this->wikiId = isset($config['wikiId']) ? $config['wikiId'] : wfWikiID();
     $met = ini_get('max_execution_time');
     // this is 0 in CLI mode
     $this->lockExpiry = $met ? 2 * (int) $met : 2 * 3600;
     $this->session = wfRandomString(32);
 }