/**
  * Constructor. Parameters are:
  *   - server:      A server info structure in the format required by each
  *                  element in $wgDBServers.
  *
  *   - servers:     An array of server info structures describing a set of
  *                  database servers to distribute keys to. If this is
  *                  specified, the "server" option will be ignored.
  *
  *   - purgePeriod: The average number of object cache requests in between
  *                  garbage collection operations, where expired entries
  *                  are removed from the database. Or in other words, the
  *                  reciprocal of the probability of purging on any given
  *                  request. If this is set to zero, purging will never be
  *                  done.
  *
  *   - tableName:   The table name to use, default is "objectcache".
  *
  *   - shards:      The number of tables to use for data storage on each server.
  *                  If this is more than 1, table names will be formed in the style
  *                  objectcacheNNN where NNN is the shard index, between 0 and
  *                  shards-1. The number of digits will be the minimum number
  *                  required to hold the largest shard index. Data will be
  *                  distributed across all tables by key hash. This is for
  *                  MySQL bugs 61735 and 61736.
  *
  * @param array $params
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (isset($params['servers'])) {
         $this->serverInfos = $params['servers'];
         $this->numServers = count($this->serverInfos);
         $this->serverNames = array();
         foreach ($this->serverInfos as $i => $info) {
             $this->serverNames[$i] = isset($info['host']) ? $info['host'] : "#{$i}";
         }
     } elseif (isset($params['server'])) {
         $this->serverInfos = array($params['server']);
         $this->numServers = count($this->serverInfos);
     } else {
         $this->serverInfos = false;
         $this->numServers = 1;
     }
     if (isset($params['purgePeriod'])) {
         $this->purgePeriod = intval($params['purgePeriod']);
     }
     if (isset($params['tableName'])) {
         $this->tableName = $params['tableName'];
     }
     if (isset($params['shards'])) {
         $this->shards = intval($params['shards']);
     }
 }
Exemple #2
0
 /**
  * @param array $params Additional parameters include:
  *   - maxKeys : only allow this many keys (using oldest-first eviction)
  */
 function __construct($params = [])
 {
     parent::__construct($params);
     $this->maxCacheKeys = isset($params['maxKeys']) ? $params['maxKeys'] : INF;
     if ($this->maxCacheKeys <= 0) {
         throw new InvalidArgumentException('$maxKeys parameter must be above zero');
     }
 }
 /**
  * Constructor. Parameters are:
  *
  *   - caches:   This should have a numbered array of cache parameter
  *               structures, in the style required by $wgObjectCaches. See
  *               the documentation of $wgObjectCaches for more detail.
  *
  * @param array $params
  * @throws InvalidArgumentException
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (!isset($params['caches'])) {
         throw new InvalidArgumentException(__METHOD__ . ': the caches parameter is required');
     }
     $this->caches = array();
     foreach ($params['caches'] as $cacheInfo) {
         $this->caches[] = ObjectCache::newFromParams($cacheInfo);
     }
 }
 /**
  * $params include:
  *   - caches:      This should have a numbered array of cache parameter
  *                  structures, in the style required by $wgObjectCaches. See
  *                  the documentation of $wgObjectCaches for more detail.
  *                  BagOStuff objects can also be used as values.
  *                  The first cache is the primary one, being the first to
  *                  be read in the fallback chain. Writes happen to all stores
  *                  in the order they are defined. However, lock()/unlock() calls
  *                  only use the primary store.
  *   - replication: Either 'sync' or 'async'. This controls whether writes to
  *                  secondary stores are deferred when possible. Async writes
  *                  require the HHVM register_postsend_function() function.
  *                  Async writes can increase the chance of some race conditions
  *                  or cause keys to expire seconds later than expected. It is
  *                  safe to use for modules when cached values: are immutable,
  *                  invalidation uses logical TTLs, invalidation uses etag/timestamp
  *                  validation against the DB, or merge() is used to handle races.
  *
  * @param array $params
  * @throws InvalidArgumentException
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($params['caches']) || !is_array($params['caches'])) {
         throw new InvalidArgumentException(__METHOD__ . ': "caches" parameter must be an array of caches');
     }
     $this->caches = array();
     foreach ($params['caches'] as $cacheInfo) {
         $this->caches[] = $cacheInfo instanceof BagOStuff ? $cacheInfo : ObjectCache::newFromParams($cacheInfo);
     }
     $this->asyncWrites = isset($params['replication']) && $params['replication'] === 'async';
 }
 /**
  * Constructor. Parameters are:
  *   - writeFactory : ObjectFactory::getObjectFromSpec parameters yeilding BagOStuff.
  *                    This object will be used for writes (e.g. the master DB).
  *   - readFactory  : ObjectFactory::getObjectFromSpec parameters yeilding BagOStuff.
  *                    This object will be used for reads (e.g. a slave DB).
  *
  * @param array $params
  * @throws InvalidArgumentException
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (!isset($params['writeFactory'])) {
         throw new InvalidArgumentException(__METHOD__ . ': the "writeFactory" parameter is required');
     }
     if (!isset($params['readFactory'])) {
         throw new InvalidArgumentException(__METHOD__ . ': the "readFactory" parameter is required');
     }
     $this->writeStore = $params['writeFactory'] instanceof BagOStuff ? $params['writeFactory'] : ObjectFactory::getObjectFromSpec($params['writeFactory']);
     $this->readStore = $params['readFactory'] instanceof BagOStuff ? $params['readFactory'] : ObjectFactory::getObjectFromSpec($params['readFactory']);
 }
 /**
  * Constructor. Parameters are:
  *   - writeFactory : ObjectFactory::getObjectFromSpec array yeilding BagOStuff.
  *                    This object will be used for writes (e.g. the master DB).
  *   - readFactory  : ObjectFactory::getObjectFromSpec array yeilding BagOStuff.
  *                    This object will be used for reads (e.g. a replica DB).
  *
  * @param array $params
  * @throws InvalidArgumentException
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (!isset($params['writeFactory'])) {
         throw new InvalidArgumentException(__METHOD__ . ': the "writeFactory" parameter is required');
     }
     if (!isset($params['readFactory'])) {
         throw new InvalidArgumentException(__METHOD__ . ': the "readFactory" parameter is required');
     }
     $opts = ['reportDupes' => false];
     // redundant
     $this->writeStore = $params['writeFactory'] instanceof BagOStuff ? $params['writeFactory'] : ObjectFactory::getObjectFromSpec($opts + $params['writeFactory']);
     $this->readStore = $params['readFactory'] instanceof BagOStuff ? $params['readFactory'] : ObjectFactory::getObjectFromSpec($opts + $params['readFactory']);
     $this->attrMap = $this->mergeFlagMaps([$this->readStore, $this->writeStore]);
 }
Exemple #7
0
 public function __construct($params)
 {
     if (empty($params['url'])) {
         throw new InvalidArgumentException('URL parameter is required');
     }
     parent::__construct($params);
     if (empty($params['client'])) {
         $this->client = new MultiHttpClient([]);
     } else {
         $this->client = $params['client'];
     }
     // Make sure URL ends with /
     $this->url = rtrim($params['url'], '/') . '/';
     // Default config, R+W > N; no locks on reads though; writes go straight to state-machine
     $this->attrMap[self::ATTR_SYNCWRITES] = self::QOS_SYNCWRITES_QC;
 }
 /**
  * Constructor
  *
  * Available parameters are:
  *   - nativeSerialize:     If true, pass objects to apc_store(), and trust it
  *                          to serialize them correctly. If false, serialize
  *                          all values in PHP.
  *
  * @param array $params
  */
 public function __construct(array $params = array())
 {
     parent::__construct($params);
     if (isset($params['nativeSerialize'])) {
         $this->nativeSerialize = $params['nativeSerialize'];
     } elseif (extension_loaded('apcu') && ini_get('apc.serializer') === 'default') {
         // APCu has a memory corruption bug when the serializer is set to 'default'.
         // See T120267, and upstream bug reports:
         //  - https://github.com/krakjoe/apcu/issues/38
         //  - https://github.com/krakjoe/apcu/issues/35
         //  - https://github.com/krakjoe/apcu/issues/111
         $this->logger->warning('The APCu extension is loaded and the apc.serializer INI setting ' . 'is set to "default". This can cause memory corruption! ' . 'You should change apc.serializer to "php" instead. ' . 'See <https://github.com/krakjoe/apcu/issues/38>.');
         $this->nativeSerialize = false;
     } else {
         $this->nativeSerialize = true;
     }
 }
 /**
  * Construct a RedisBagOStuff object. Parameters are:
  *
  *   - servers: An array of server names. A server name may be a hostname,
  *     a hostname/port combination or the absolute path of a UNIX socket.
  *     If a hostname is specified but no port, the standard port number
  *     6379 will be used. Required.
  *
  *   - connectTimeout: The timeout for new connections, in seconds. Optional,
  *     default is 1 second.
  *
  *   - persistent: Set this to true to allow connections to persist across
  *     multiple web requests. False by default.
  *
  *   - password: The authentication password, will be sent to Redis in
  *     clear text. Optional, if it is unspecified, no AUTH command will be
  *     sent.
  *
  *   - automaticFailover: If this is false, then each key will be mapped to
  *     a single server, and if that server is down, any requests for that key
  *     will fail. If this is true, a connection failure will cause the client
  *     to immediately try the next server in the list (as determined by a
  *     consistent hashing algorithm). True by default. This has the
  *     potential to create consistency issues if a server is slow enough to
  *     flap, for example if it is in swap death.
  * @param array $params
  */
 function __construct($params)
 {
     parent::__construct($params);
     $redisConf = array('serializer' => 'none');
     // manage that in this class
     foreach (array('connectTimeout', 'persistent', 'password') as $opt) {
         if (isset($params[$opt])) {
             $redisConf[$opt] = $params[$opt];
         }
     }
     $this->redisPool = RedisConnectionPool::singleton($redisConf);
     $this->servers = $params['servers'];
     if (isset($params['automaticFailover'])) {
         $this->automaticFailover = $params['automaticFailover'];
     } else {
         $this->automaticFailover = true;
     }
 }
 /**
  * Construct a RedisBagOStuff object. Parameters are:
  *
  *   - servers: An array of server names. A server name may be a hostname,
  *     a hostname/port combination or the absolute path of a UNIX socket.
  *     If a hostname is specified but no port, the standard port number
  *     6379 will be used. Arrays keys can be used to specify the tag to
  *     hash on in place of the host/port. Required.
  *
  *   - connectTimeout: The timeout for new connections, in seconds. Optional,
  *     default is 1 second.
  *
  *   - persistent: Set this to true to allow connections to persist across
  *     multiple web requests. False by default.
  *
  *   - password: The authentication password, will be sent to Redis in
  *     clear text. Optional, if it is unspecified, no AUTH command will be
  *     sent.
  *
  *   - automaticFailover: If this is false, then each key will be mapped to
  *     a single server, and if that server is down, any requests for that key
  *     will fail. If this is true, a connection failure will cause the client
  *     to immediately try the next server in the list (as determined by a
  *     consistent hashing algorithm). True by default. This has the
  *     potential to create consistency issues if a server is slow enough to
  *     flap, for example if it is in swap death.
  * @param array $params
  */
 function __construct($params)
 {
     parent::__construct($params);
     $redisConf = ['serializer' => 'none'];
     // manage that in this class
     foreach (['connectTimeout', 'persistent', 'password'] as $opt) {
         if (isset($params[$opt])) {
             $redisConf[$opt] = $params[$opt];
         }
     }
     $this->redisPool = RedisConnectionPool::singleton($redisConf);
     $this->servers = $params['servers'];
     foreach ($this->servers as $key => $server) {
         $this->serverTagMap[is_int($key) ? $server : $key] = $server;
     }
     if (isset($params['automaticFailover'])) {
         $this->automaticFailover = $params['automaticFailover'];
     } else {
         $this->automaticFailover = true;
     }
 }
 /**
  * $params include:
  *   - caches: A numbered array of either ObjectFactory::getObjectFromSpec
  *      arrays yeilding BagOStuff objects or direct BagOStuff objects.
  *      If using the former, the 'args' field *must* be set.
  *      The first cache is the primary one, being the first to
  *      be read in the fallback chain. Writes happen to all stores
  *      in the order they are defined. However, lock()/unlock() calls
  *      only use the primary store.
  *   - replication: Either 'sync' or 'async'. This controls whether writes
  *      to secondary stores are deferred when possible. Async writes
  *      require setting 'asyncHandler'. HHVM register_postsend_function() function.
  *      Async writes can increase the chance of some race conditions
  *      or cause keys to expire seconds later than expected. It is
  *      safe to use for modules when cached values: are immutable,
  *      invalidation uses logical TTLs, invalidation uses etag/timestamp
  *      validation against the DB, or merge() is used to handle races.
  * @param array $params
  * @throws InvalidArgumentException
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (empty($params['caches']) || !is_array($params['caches'])) {
         throw new InvalidArgumentException(__METHOD__ . ': "caches" parameter must be an array of caches');
     }
     $this->caches = [];
     foreach ($params['caches'] as $cacheInfo) {
         if ($cacheInfo instanceof BagOStuff) {
             $this->caches[] = $cacheInfo;
         } else {
             if (!isset($cacheInfo['args'])) {
                 // B/C for when $cacheInfo was for ObjectCache::newFromParams().
                 // Callers intenting this to be for ObjectFactory::getObjectFromSpec
                 // should have set "args" per the docs above. Doings so avoids extra
                 // (likely harmless) params (factory/class/calls) ending up in "args".
                 $cacheInfo['args'] = [$cacheInfo];
             }
             $this->caches[] = ObjectFactory::getObjectFromSpec($cacheInfo);
         }
     }
     $this->asyncWrites = isset($params['replication']) && $params['replication'] === 'async' && is_callable($this->asyncHandler);
 }
 function __construct($params = array())
 {
     parent::__construct($params);
     $this->bag = array();
 }
Exemple #13
0
 /**
  * Constructor. Parameters are:
  *   - server:      A server info structure in the format required by each
  *                  element in $wgDBServers.
  *
  *   - servers:     An array of server info structures describing a set of database servers
  *                  to distribute keys to. If this is specified, the "server" option will be
  *                  ignored. If string keys are used, then they will be used for consistent
  *                  hashing *instead* of the host name (from the server config). This is useful
  *                  when a cluster is replicated to another site (with different host names)
  *                  but each server has a corresponding replica in the other cluster.
  *
  *   - purgePeriod: The average number of object cache requests in between
  *                  garbage collection operations, where expired entries
  *                  are removed from the database. Or in other words, the
  *                  reciprocal of the probability of purging on any given
  *                  request. If this is set to zero, purging will never be
  *                  done.
  *
  *   - tableName:   The table name to use, default is "objectcache".
  *
  *   - shards:      The number of tables to use for data storage on each server.
  *                  If this is more than 1, table names will be formed in the style
  *                  objectcacheNNN where NNN is the shard index, between 0 and
  *                  shards-1. The number of digits will be the minimum number
  *                  required to hold the largest shard index. Data will be
  *                  distributed across all tables by key hash. This is for
  *                  MySQL bugs 61735 and 61736.
  *   - slaveOnly:   Whether to only use replica DBs and avoid triggering
  *                  garbage collection logic of expired items. This only
  *                  makes sense if the primary DB is used and only if get()
  *                  calls will be used. This is used by ReplicatedBagOStuff.
  *   - syncTimeout: Max seconds to wait for replica DBs to catch up for WRITE_SYNC.
  *
  * @param array $params
  */
 public function __construct($params)
 {
     parent::__construct($params);
     $this->attrMap[self::ATTR_EMULATION] = self::QOS_EMULATION_SQL;
     $this->attrMap[self::ATTR_SYNCWRITES] = self::QOS_SYNCWRITES_NONE;
     if (isset($params['servers'])) {
         $this->serverInfos = [];
         $this->serverTags = [];
         $this->numServers = count($params['servers']);
         $index = 0;
         foreach ($params['servers'] as $tag => $info) {
             $this->serverInfos[$index] = $info;
             if (is_string($tag)) {
                 $this->serverTags[$index] = $tag;
             } else {
                 $this->serverTags[$index] = isset($info['host']) ? $info['host'] : "#{$index}";
             }
             ++$index;
         }
     } elseif (isset($params['server'])) {
         $this->serverInfos = [$params['server']];
         $this->numServers = count($this->serverInfos);
     } else {
         // Default to using the main wiki's database servers
         $this->serverInfos = false;
         $this->numServers = 1;
         $this->attrMap[self::ATTR_SYNCWRITES] = self::QOS_SYNCWRITES_BE;
     }
     if (isset($params['purgePeriod'])) {
         $this->purgePeriod = intval($params['purgePeriod']);
     }
     if (isset($params['tableName'])) {
         $this->tableName = $params['tableName'];
     }
     if (isset($params['shards'])) {
         $this->shards = intval($params['shards']);
     }
     if (isset($params['syncTimeout'])) {
         $this->syncTimeout = $params['syncTimeout'];
     }
     $this->replicaOnly = !empty($params['slaveOnly']);
 }
 function __construct(array $params)
 {
     parent::__construct($params);
     $this->attrMap[self::ATTR_SYNCWRITES] = self::QOS_SYNCWRITES_BE;
     // unreliable
 }
 /**
  * @param array $params Additional parameters include:
  *   - maxKeys : only allow this many keys (using oldest-first eviction)
  */
 function __construct($params = array())
 {
     parent::__construct($params);
     $this->maxCacheKeys = isset($params['maxKeys']) ? $params['maxKeys'] : INF;
     Assert::parameter($this->maxCacheKeys > 0, 'maxKeys', 'must be above zero');
 }
Exemple #16
0
 /**
  * Constructor. Parameters are:
  *   - server:      A server info structure in the format required by each
  *                  element in $wgDBServers.
  *
  *   - servers:     An array of server info structures describing a set of database servers
  *                  to distribute keys to. If this is specified, the "server" option will be
  *                  ignored. If string keys are used, then they will be used for consistent
  *                  hashing *instead* of the host name (from the server config). This is useful
  *                  when a cluster is replicated to another site (with different host names)
  *                  but each server has a corresponding replica in the other cluster.
  *
  *   - purgePeriod: The average number of object cache requests in between
  *                  garbage collection operations, where expired entries
  *                  are removed from the database. Or in other words, the
  *                  reciprocal of the probability of purging on any given
  *                  request. If this is set to zero, purging will never be
  *                  done.
  *
  *   - tableName:   The table name to use, default is "objectcache".
  *
  *   - shards:      The number of tables to use for data storage on each server.
  *                  If this is more than 1, table names will be formed in the style
  *                  objectcacheNNN where NNN is the shard index, between 0 and
  *                  shards-1. The number of digits will be the minimum number
  *                  required to hold the largest shard index. Data will be
  *                  distributed across all tables by key hash. This is for
  *                  MySQL bugs 61735 and 61736.
  *   - slaveOnly:   Whether to only use slave DBs and avoid triggering
  *                  garbage collection logic of expired items. This only
  *                  makes sense if the primary DB is used and only if get()
  *                  calls will be used. This is used by ReplicatedBagOStuff.
  *   - syncTimeout: Max seconds to wait for slaves to catch up for WRITE_SYNC.
  *
  * @param array $params
  */
 public function __construct($params)
 {
     parent::__construct($params);
     if (isset($params['servers'])) {
         $this->serverInfos = [];
         $this->serverTags = [];
         $this->numServers = count($params['servers']);
         $index = 0;
         foreach ($params['servers'] as $tag => $info) {
             $this->serverInfos[$index] = $info;
             if (is_string($tag)) {
                 $this->serverTags[$index] = $tag;
             } else {
                 $this->serverTags[$index] = isset($info['host']) ? $info['host'] : "#{$index}";
             }
             ++$index;
         }
     } elseif (isset($params['server'])) {
         $this->serverInfos = [$params['server']];
         $this->numServers = count($this->serverInfos);
     } else {
         $this->serverInfos = false;
         $this->numServers = 1;
     }
     if (isset($params['purgePeriod'])) {
         $this->purgePeriod = intval($params['purgePeriod']);
     }
     if (isset($params['tableName'])) {
         $this->tableName = $params['tableName'];
     }
     if (isset($params['shards'])) {
         $this->shards = intval($params['shards']);
     }
     if (isset($params['syncTimeout'])) {
         $this->syncTimeout = $params['syncTimeout'];
     }
     $this->slaveOnly = !empty($params['slaveOnly']);
 }