MediaWiki  1.23.1
SqlBagOStuff Class Reference

Class to store objects in the database. More...

Inheritance diagram for SqlBagOStuff:
Collaboration diagram for SqlBagOStuff:

Public Member Functions

 __construct ( $params)
 Constructor. More...
 
 cas ( $casToken, $key, $value, $exptime=0)
 
 createTables ()
 Create shard tables. More...
 
 delete ( $key, $time=0)
 
 deleteAll ()
 
 deleteObjectsExpiringBefore ( $timestamp, $progressCallback=false)
 Delete objects from the database which expire before a certain date. More...
 
 expireAll ()
 
 get ( $key, &$casToken=null)
 
 getMulti (array $keys)
 
 incr ( $key, $step=1)
 
 set ( $key, $value, $exptime=0)
 
- Public Member Functions inherited from BagOStuff
 add ( $key, $value, $exptime=0)
 
 clearLastError ()
 Clear the "last error" registry. More...
 
 debug ( $text)
 
 decr ( $key, $value=1)
 Decrease stored value of $key by $value while preserving its TTL. More...
 
 getLastError ()
 Get the "last error" registered; clearLastError() should be called manually. More...
 
 lock ( $key, $timeout=6)
 
 merge ( $key, closure $callback, $exptime=0, $attempts=10)
 Merge changes into the existing cache value (possibly creating a new one). More...
 
 replace ( $key, $value, $exptime=0)
 
 setDebug ( $bool)
 
 unlock ( $key)
 

Public Attributes

 $conns
 
 $lastExpireAll = 0
 
LoadBalancer $lb
 
 $numServers
 
 $purgePeriod = 100
 
 $serverInfos
 
 $serverNames
 
 $shards = 1
 
 $tableName = 'objectcache'
 
- Public Attributes inherited from BagOStuff
const ERR_NO_RESPONSE = 1
 
const ERR_NONE = 0
 Possible values for getLastError() More...
 
const ERR_UNEXPECTED = 3
 
const ERR_UNREACHABLE = 2
 

Protected Member Functions

 garbageCollect ()
 
 getDB ( $serverIndex)
 Get a connection to the specified database. More...
 
 getMaxDateTime ( $db)
 
 getTableByKey ( $key)
 Get the server index and table name for a given key. More...
 
 getTableNameByShard ( $index)
 Get the table name for a given shard index. More...
 
 handleReadError (DBError $exception, $serverIndex)
 Handle a DBError which occurred during a read operation. More...
 
 handleWriteError (DBError $exception, $serverIndex)
 Handle a DBQueryError which occurred during a write operation. More...
 
 isExpired ( $db, $exptime)
 
 markServerDown ( $exception, $serverIndex)
 Mark a server down due to a DBConnectionError exception. More...
 
 serialize (&$data)
 Serialize an object and, if possible, compress the representation. More...
 
 unserialize ( $serial)
 Unserialize and, if necessary, decompress an object. More...
 
- Protected Member Functions inherited from BagOStuff
 convertExpiry ( $exptime)
 Convert an optionally relative time to an absolute time. More...
 
 convertToRelative ( $exptime)
 Convert an optionally absolute expiry time to a relative time. More...
 
 isInteger ( $value)
 Check if a value is an integer. More...
 
 mergeViaCas ( $key, closure $callback, $exptime=0, $attempts=10)
 
 mergeViaLock ( $key, closure $callback, $exptime=0, $attempts=10)
 
 setLastError ( $err)
 Set the "last error" registry. More...
 

Protected Attributes

 $connFailureErrors = array()
 
 $connFailureTimes = array()
 
- Protected Attributes inherited from BagOStuff
 $lastError = self::ERR_NONE
 

Detailed Description

Class to store objects in the database.

Definition at line 29 of file SqlBagOStuff.php.

Constructor & Destructor Documentation

◆ __construct()

SqlBagOStuff::__construct (   $params)

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.
Parameters
$paramsarray

Definition at line 74 of file SqlBagOStuff.php.

References $params, array(), as, and tableName().

Member Function Documentation

◆ cas()

SqlBagOStuff::cas (   $casToken,
  $key,
  $value,
  $exptime = 0 
)
Parameters
$casTokenmixed
$keystring
$valuemixed
$exptimeint
Returns
bool

Reimplemented from BagOStuff.

Definition at line 325 of file SqlBagOStuff.php.

References $e, $tableName, $value, array(), getDB(), getMaxDateTime(), getTableByKey(), handleWriteError(), and list.

◆ createTables()

SqlBagOStuff::createTables ( )

Create shard tables.

For use from eval.php.

Definition at line 680 of file SqlBagOStuff.php.

References $numServers, $shards, and getDB().

◆ delete()

SqlBagOStuff::delete (   $key,
  $time = 0 
)
Parameters
$keystring
$timeint
Returns
bool

Reimplemented from BagOStuff.

Definition at line 374 of file SqlBagOStuff.php.

References $e, $tableName, array(), getDB(), getTableByKey(), handleWriteError(), and list.

◆ deleteAll()

SqlBagOStuff::deleteAll ( )

Definition at line 563 of file SqlBagOStuff.php.

References $e, $numServers, $shards, getDB(), getTableNameByShard(), and handleWriteError().

◆ deleteObjectsExpiringBefore()

SqlBagOStuff::deleteObjectsExpiringBefore (   $timestamp,
  $progressCallback = false 
)

Delete objects from the database which expire before a certain date.

Parameters
$timestampstring
$progressCallbackbool|callback
Returns
bool

Reimplemented from BagOStuff.

Definition at line 491 of file SqlBagOStuff.php.

References $e, $keys, $numServers, $shards, $timestamp, array(), as, getDB(), getTableNameByShard(), handleWriteError(), TS_UNIX, and wfTimestamp().

Referenced by expireAll().

◆ expireAll()

SqlBagOStuff::expireAll ( )

Definition at line 481 of file SqlBagOStuff.php.

References deleteObjectsExpiringBefore(), and wfTimestampNow().

Referenced by garbageCollect().

◆ garbageCollect()

SqlBagOStuff::garbageCollect ( )
protected

Definition at line 464 of file SqlBagOStuff.php.

References expireAll().

Referenced by getMulti().

◆ get()

SqlBagOStuff::get (   $key,
$casToken = null 
)
Parameters
$keystring
$casToken[optional]mixed
Returns
mixed

Reimplemented from BagOStuff.

Definition at line 198 of file SqlBagOStuff.php.

References array(), and getMulti().

◆ getDB()

SqlBagOStuff::getDB (   $serverIndex)
protected

Get a connection to the specified database.

Parameters
$serverIndexinteger
Returns
DatabaseBase

Definition at line 106 of file SqlBagOStuff.php.

References $type, DB_MASTER, DBO_TRX, DatabaseBase\factory(), global, wfDebug(), wfGetDB(), and wfGetLBFactory().

Referenced by cas(), createTables(), delete(), deleteAll(), deleteObjectsExpiringBefore(), getMulti(), incr(), and set().

◆ getMaxDateTime()

SqlBagOStuff::getMaxDateTime (   $db)
protected
Returns
string

Definition at line 456 of file SqlBagOStuff.php.

Referenced by cas(), isExpired(), and set().

◆ getMulti()

SqlBagOStuff::getMulti ( array  $keys)
Parameters
$keysarray
Returns
Array

Reimplemented from BagOStuff.

Definition at line 211 of file SqlBagOStuff.php.

References $e, $keys, $res, $tableName, array(), as, BagOStuff\debug(), garbageCollect(), getDB(), getTableByKey(), handleReadError(), handleWriteError(), isExpired(), list, and unserialize().

Referenced by get().

◆ getTableByKey()

SqlBagOStuff::getTableByKey (   $key)
protected

Get the server index and table name for a given key.

Parameters
$keystring
Returns
Array: server index and table name

Definition at line 160 of file SqlBagOStuff.php.

References $hash, $serverNames, $shards, array(), ArrayUtils\consistentHashSort(), getTableNameByShard(), and key.

Referenced by cas(), delete(), getMulti(), incr(), and set().

◆ getTableNameByShard()

SqlBagOStuff::getTableNameByShard (   $index)
protected

Get the table name for a given shard index.

Parameters
$indexint
Returns
string

Definition at line 183 of file SqlBagOStuff.php.

References $tableName, and tableName().

Referenced by deleteAll(), deleteObjectsExpiringBefore(), and getTableByKey().

◆ handleReadError()

SqlBagOStuff::handleReadError ( DBError  $exception,
  $serverIndex 
)
protected

Handle a DBError which occurred during a read operation.

Definition at line 622 of file SqlBagOStuff.php.

References BagOStuff\ERR_UNEXPECTED, BagOStuff\ERR_UNREACHABLE, markServerDown(), BagOStuff\setLastError(), wfDebug(), and wfDebugLog().

Referenced by getMulti().

◆ handleWriteError()

SqlBagOStuff::handleWriteError ( DBError  $exception,
  $serverIndex 
)
protected

◆ incr()

SqlBagOStuff::incr (   $key,
  $step = 1 
)
Parameters
$keystring
$stepint
Returns
int|null

Reimplemented from BagOStuff.

Definition at line 397 of file SqlBagOStuff.php.

References $e, $tableName, array(), getDB(), getTableByKey(), handleWriteError(), isExpired(), list, and unserialize().

◆ isExpired()

SqlBagOStuff::isExpired (   $db,
  $exptime 
)
protected
Parameters
$exptimestring
Returns
bool

Definition at line 449 of file SqlBagOStuff.php.

References getMaxDateTime(), TS_UNIX, and wfTimestamp().

Referenced by getMulti(), and incr().

◆ markServerDown()

SqlBagOStuff::markServerDown (   $exception,
  $serverIndex 
)
protected

Mark a server down due to a DBConnectionError exception.

Definition at line 661 of file SqlBagOStuff.php.

References wfDebug().

Referenced by handleReadError(), and handleWriteError().

◆ serialize()

SqlBagOStuff::serialize ( $data)
protected

Serialize an object and, if possible, compress the representation.

On typical message and page data, this can provide a 3X decrease in storage requirements.

Parameters
$datamixed
Returns
string

Definition at line 588 of file SqlBagOStuff.php.

◆ set()

SqlBagOStuff::set (   $key,
  $value,
  $exptime = 0 
)
Parameters
$keystring
$valuemixed
$exptimeint
Returns
bool

Reimplemented from BagOStuff.

Definition at line 279 of file SqlBagOStuff.php.

References $e, $tableName, $value, array(), getDB(), getMaxDateTime(), getTableByKey(), handleWriteError(), and list.

◆ unserialize()

SqlBagOStuff::unserialize (   $serial)
protected

Unserialize and, if necessary, decompress an object.

Parameters
$serialstring
Returns
mixed

Definition at line 603 of file SqlBagOStuff.php.

References $ret, wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by getMulti(), and incr().

Member Data Documentation

◆ $connFailureErrors

SqlBagOStuff::$connFailureErrors = array()
protected

Definition at line 44 of file SqlBagOStuff.php.

◆ $connFailureTimes

SqlBagOStuff::$connFailureTimes = array()
protected

Definition at line 43 of file SqlBagOStuff.php.

◆ $conns

SqlBagOStuff::$conns

Definition at line 37 of file SqlBagOStuff.php.

◆ $lastExpireAll

SqlBagOStuff::$lastExpireAll = 0

Definition at line 38 of file SqlBagOStuff.php.

◆ $lb

LoadBalancer SqlBagOStuff::$lb

Definition at line 32 of file SqlBagOStuff.php.

◆ $numServers

SqlBagOStuff::$numServers

Definition at line 36 of file SqlBagOStuff.php.

Referenced by createTables(), deleteAll(), and deleteObjectsExpiringBefore().

◆ $purgePeriod

SqlBagOStuff::$purgePeriod = 100

Definition at line 39 of file SqlBagOStuff.php.

◆ $serverInfos

SqlBagOStuff::$serverInfos

Definition at line 34 of file SqlBagOStuff.php.

◆ $serverNames

SqlBagOStuff::$serverNames

Definition at line 35 of file SqlBagOStuff.php.

Referenced by getTableByKey().

◆ $shards

SqlBagOStuff::$shards = 1

◆ $tableName

SqlBagOStuff::$tableName = 'objectcache'

Definition at line 41 of file SqlBagOStuff.php.

Referenced by cas(), delete(), getMulti(), getTableNameByShard(), incr(), and set().


The documentation for this class was generated from the following file: