MediaWiki REL1_28
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.
 
 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.
 
 shutdownLB (ILoadBalancer $lb)
 Notify the ChronologyProtector that the ILoadBalancer is about to shut down.
 

Protected Member Functions

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

Protected Attributes

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

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

◆ __construct()

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

◆ getTouched()

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.

◆ getTouchedKey()

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

Definition at line 235 of file ChronologyProtector.php.

References $store, and BagOStuff\makeGlobalKey().

Referenced by getTouched(), and shutdown().

◆ initLB()

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().

◆ initPositions()

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().

◆ mergePositions()

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.

◆ minPosTime()

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

Definition at line 289 of file ChronologyProtector.php.

References as.

◆ setEnabled()

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.

◆ setLogger()

ChronologyProtector::setLogger ( LoggerInterface  $logger)

Definition at line 78 of file ChronologyProtector.php.

References $logger.

Referenced by LBFactory\getChronologyProtector().

◆ setWaitEnabled()

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.

◆ shutdown()

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().

◆ shutdownLB()

ChronologyProtector::shutdownLB ( ILoadBalancer  $lb)

Member Data Documentation

◆ $clientId

string ChronologyProtector::$clientId
protected

Hash of client parameters.

Definition at line 40 of file ChronologyProtector.php.

◆ $enabled

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().

◆ $initialized

bool ChronologyProtector::$initialized = false
protected

Whether the client data was loaded.

Definition at line 51 of file ChronologyProtector.php.

◆ $key

string ChronologyProtector::$key
protected

Storage key name.

Definition at line 38 of file ChronologyProtector.php.

◆ $logger

LoggerInterface ChronologyProtector::$logger
protected

Definition at line 35 of file ChronologyProtector.php.

Referenced by setLogger().

◆ $shutdownPositions

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

Map of (DB master name => position)

Definition at line 55 of file ChronologyProtector.php.

Referenced by mergePositions(), and shutdown().

◆ $shutdownTouchDBs

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

Map of (DB master name => 1)

Definition at line 57 of file ChronologyProtector.php.

◆ $startupPositions

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

Map of (DB master name => position)

Definition at line 53 of file ChronologyProtector.php.

◆ $store

BagOStuff ChronologyProtector::$store
protected

Definition at line 33 of file ChronologyProtector.php.

Referenced by __construct(), getTouchedKey(), and shutdown().

◆ $wait

bool ChronologyProtector::$wait = true
protected

Whether to check and wait on positions.

Definition at line 48 of file ChronologyProtector.php.

◆ $waitForPosTime

float null ChronologyProtector::$waitForPosTime
protected

Minimum UNIX timestamp of 1+ expected startup positions.

Definition at line 42 of file ChronologyProtector.php.

◆ $waitForPosTimeout

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: