MediaWiki  1.28.0
ChronologyProtector Class Reference

Class for ensuring a consistent ordering of events as seen by the user, despite replication. More...

Inheritance diagram for ChronologyProtector:
Collaboration diagram for ChronologyProtector:

Public Member Functions

 __construct (BagOStuff $store, array $client, $posTime=null)
 
 getTouched ($dbName)
 
 initLB (ILoadBalancer $lb)
 Initialise a ILoadBalancer to give it appropriate chronology protection. More...
 
 setEnabled ($enabled)
 
 setLogger (LoggerInterface $logger)
 
 setWaitEnabled ($enabled)
 
 shutdown (callable $workCallback=null, $mode= 'sync')
 Notify the ChronologyProtector that the LBFactory is done calling shutdownLB() for now. More...
 
 shutdownLB (ILoadBalancer $lb)
 Notify the ChronologyProtector that the ILoadBalancer is about to shut down. More...
 

Protected Member Functions

 initPositions ()
 Load in previous master positions for the client. More...
 

Protected Attributes

string $clientId
 Hash of client parameters. More...
 
bool $enabled = true
 Whether to no-op all method calls. More...
 
bool $initialized = false
 Whether the client data was loaded. More...
 
string $key
 Storage key name. More...
 
LoggerInterface $logger
 
DBMasterPos[] $shutdownPositions = []
 Map of (DB master name => position) More...
 
float[] $shutdownTouchDBs = []
 Map of (DB master name => 1) More...
 
DBMasterPos[] $startupPositions = []
 Map of (DB master name => position) More...
 
BagOStuff $store
 
bool $wait = true
 Whether to check and wait on positions. More...
 
float null $waitForPosTime
 Minimum UNIX timestamp of 1+ expected startup positions. More...
 
int $waitForPosTimeout = self::POS_WAIT_TIMEOUT
 Max seconds to wait on positions to appear. More...
 

Private Member Functions

 getTouchedKey (BagOStuff $store, $dbName)
 

Static Private Member Functions

static mergePositions ($curValue, array $shutdownPositions)
 
static minPosTime ($data)
 

Detailed Description

Class for ensuring a consistent ordering of events as seen by the user, despite replication.

Kind of like Hawking's [[Chronology Protection Agency]].

Definition at line 31 of file ChronologyProtector.php.

Constructor & Destructor Documentation

ChronologyProtector::__construct ( BagOStuff  $store,
array  $client,
  $posTime = null 
)
Parameters
BagOStuff$store
array$clientMap of (ip: <IP>, agent: <user-agent>)
float$posTimeUNIX timestamp
Since
1.27

Definition at line 70 of file ChronologyProtector.php.

References $store, key, BagOStuff\makeGlobalKey(), and store.

Member Function Documentation

ChronologyProtector::getTouched (   $dbName)
Parameters
string$dbNameDB master name (e.g. "db1052")
Returns
float|bool UNIX timestamp when client last touched the DB; false if not on record
Since
1.28

Definition at line 226 of file ChronologyProtector.php.

References getTouchedKey(), and store.

ChronologyProtector::getTouchedKey ( BagOStuff  $store,
  $dbName 
)
private
Parameters
BagOStuff$store
string$dbName
Returns
string

Definition at line 235 of file ChronologyProtector.php.

References BagOStuff\makeGlobalKey().

Referenced by getTouched(), and shutdown().

ChronologyProtector::initLB ( ILoadBalancer  $lb)

Initialise a ILoadBalancer to give it appropriate chronology protection.

If the stash has a previous master position recorded, this will try to make sure that the next query to a replica DB of that master will see changes up to that position by delaying execution. The delay may timeout and allow stale data if no non-lagged replica DBs are available.

Parameters
ILoadBalancer$lb
Returns
void

Definition at line 109 of file ChronologyProtector.php.

References ILoadBalancer\getServerCount(), ILoadBalancer\getServerName(), ILoadBalancer\getWriterIndex(), initPositions(), and ILoadBalancer\waitFor().

ChronologyProtector::initPositions ( )
protected

Load in previous master positions for the client.

Definition at line 242 of file ChronologyProtector.php.

References $waitForPosTimeout, key, store, and use.

Referenced by initLB().

static ChronologyProtector::mergePositions (   $curValue,
array  $shutdownPositions 
)
staticprivate
Parameters
array | bool$curValue
DBMasterPos[]$shutdownPositions
Returns
array

Definition at line 308 of file ChronologyProtector.php.

References $shutdownPositions, as, and false.

static ChronologyProtector::minPosTime (   $data)
staticprivate
Parameters
array | bool$data
Returns
float|null

Definition at line 289 of file ChronologyProtector.php.

References as.

ChronologyProtector::setEnabled (   $enabled)
Parameters
bool$enabledWhether to no-op all method calls
Since
1.27

Definition at line 86 of file ChronologyProtector.php.

References $enabled.

ChronologyProtector::setLogger ( LoggerInterface  $logger)

Definition at line 78 of file ChronologyProtector.php.

References $logger.

ChronologyProtector::setWaitEnabled (   $enabled)
Parameters
bool$enabledWhether to check and wait on positions
Since
1.27

Definition at line 94 of file ChronologyProtector.php.

References $enabled.

ChronologyProtector::shutdown ( callable  $workCallback = null,
  $mode = 'sync' 
)

Notify the ChronologyProtector that the LBFactory is done calling shutdownLB() for now.

May commit chronology data to persistent storage.

Parameters
callable | null$workCallbackWork to do instead of waiting on syncing positions
string$modeOne of (sync, async); whether to wait on remote datacenters
Returns
DBMasterPos[] Empty on success; returns the (db name => position) map on failure

Definition at line 158 of file ChronologyProtector.php.

References $shutdownPositions, $store, BagOStuff\addBusyCallback(), as, BagOStuff\get(), BagOStuff\getQoS(), getTouchedKey(), key, BagOStuff\lock(), BagOStuff\set(), store, and BagOStuff\unlock().

Referenced by LBFactory\shutdownChronologyProtector().

ChronologyProtector::shutdownLB ( ILoadBalancer  $lb)

Member Data Documentation

string ChronologyProtector::$clientId
protected

Hash of client parameters.

Definition at line 40 of file ChronologyProtector.php.

bool ChronologyProtector::$enabled = true
protected

Whether to no-op all method calls.

Definition at line 46 of file ChronologyProtector.php.

Referenced by setEnabled(), and setWaitEnabled().

bool ChronologyProtector::$initialized = false
protected

Whether the client data was loaded.

Definition at line 51 of file ChronologyProtector.php.

string ChronologyProtector::$key
protected

Storage key name.

Definition at line 38 of file ChronologyProtector.php.

LoggerInterface ChronologyProtector::$logger
protected

Definition at line 35 of file ChronologyProtector.php.

Referenced by setLogger().

DBMasterPos [] ChronologyProtector::$shutdownPositions = []
protected

Map of (DB master name => position)

Definition at line 55 of file ChronologyProtector.php.

Referenced by mergePositions(), and shutdown().

float [] ChronologyProtector::$shutdownTouchDBs = []
protected

Map of (DB master name => 1)

Definition at line 57 of file ChronologyProtector.php.

DBMasterPos [] ChronologyProtector::$startupPositions = []
protected

Map of (DB master name => position)

Definition at line 53 of file ChronologyProtector.php.

BagOStuff ChronologyProtector::$store
protected

Definition at line 33 of file ChronologyProtector.php.

Referenced by __construct(), and shutdown().

bool ChronologyProtector::$wait = true
protected

Whether to check and wait on positions.

Definition at line 48 of file ChronologyProtector.php.

float null ChronologyProtector::$waitForPosTime
protected

Minimum UNIX timestamp of 1+ expected startup positions.

Definition at line 42 of file ChronologyProtector.php.

int ChronologyProtector::$waitForPosTimeout = self::POS_WAIT_TIMEOUT
protected

Max seconds to wait on positions to appear.

Definition at line 44 of file ChronologyProtector.php.

Referenced by initPositions().


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