|
MediaWiki REL1_35
|
Helper class for mitigating DB replication lag in order to provide "session consistency". More...


Public Member Functions | |
| __construct (BagOStuff $store, array $client, $posIndex, $secret='') | |
| applySessionReplicationPosition (ILoadBalancer $lb) | |
| Apply the "session consistency" DB replication position to a new ILoadBalancer. | |
| getClientId () | |
| getTouched (ILoadBalancer $lb) | |
| setEnabled ( $enabled) | |
| setLogger (LoggerInterface $logger) | |
| setWaitEnabled ( $enabled) | |
| shutdown (callable $workCallback=null, $mode='sync', &$cpIndex=null) | |
| Notify the ChronologyProtector that the LBFactory is done calling shutdownLB() for now. | |
| storeSessionReplicationPosition (ILoadBalancer $lb) | |
| Save the "session consistency" DB replication position for an end-of-life ILoadBalancer. | |
Protected Member Functions | |
| getStartupMasterPositions () | |
| Load in previous master positions for the client. | |
| mergePositions ( $curValue, array $shutdownPositions, &$cpIndex=null) | |
Protected Attributes | |
| string | $clientId |
| Hash of client parameters. | |
| string[] | $clientLogInfo |
| Map of client information fields for logging. | |
| 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. | |
| int null | $waitForPosIndex |
| Expected minimum index of the last write to the position store. | |
| int | $waitForPosStoreTimeout = self::POS_STORE_WAIT_TIMEOUT |
| Max seconds to wait on positions to appear. | |
Private Member Functions | |
| getTouchedKey (BagOStuff $store, $masterName) | |
Helper class for mitigating DB replication lag in order to provide "session consistency".
This helps to ensure a consistent ordering of events as seen by an client
Kind of like Hawking's [[Chronology Protection Agency]].
Definition at line 41 of file ChronologyProtector.php.
| Wikimedia\Rdbms\ChronologyProtector::__construct | ( | BagOStuff | $store, |
| array | $client, | ||
| $posIndex, | |||
$secret = '' |
|||
| ) |
| BagOStuff | $store | |
| array | $client | Map of (ip: <IP>, agent: <user-agent> [, clientId: <hash>] ) |
| int | null | $posIndex | Write counter index |
| string | $secret | Secret string for HMAC hashing [optional] |
Definition at line 85 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$store, and BagOStuff\makeGlobalKey().
| Wikimedia\Rdbms\ChronologyProtector::applySessionReplicationPosition | ( | ILoadBalancer | $lb | ) |
Apply the "session consistency" DB replication position to a new ILoadBalancer.
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.
This method should only be called from LBFactory.
| ILoadBalancer | $lb |
Definition at line 147 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$startupPositions, Wikimedia\Rdbms\ILoadBalancer\getServerName(), Wikimedia\Rdbms\ChronologyProtector\getStartupMasterPositions(), Wikimedia\Rdbms\ILoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\ILoadBalancer\waitFor().
| Wikimedia\Rdbms\ChronologyProtector::getClientId | ( | ) |
Definition at line 114 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$clientId.
Referenced by Wikimedia\Rdbms\LBFactory\shutdown().
|
protected |
Load in previous master positions for the client.
Definition at line 297 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$startupPositions, and Wikimedia\Rdbms\ChronologyProtector\$waitForPosStoreTimeout.
Referenced by Wikimedia\Rdbms\ChronologyProtector\applySessionReplicationPosition().
| Wikimedia\Rdbms\ChronologyProtector::getTouched | ( | ILoadBalancer | $lb | ) |
| ILoadBalancer | $lb | The load balancer. Prior to 1.35, the first parameter was the master name. |
Definition at line 279 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ILoadBalancer\getServerName(), Wikimedia\Rdbms\ChronologyProtector\getTouchedKey(), and Wikimedia\Rdbms\ILoadBalancer\getWriterIndex().
|
private |
| BagOStuff | $store | |
| string | $masterName |
Definition at line 289 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$store, and BagOStuff\makeGlobalKey().
Referenced by Wikimedia\Rdbms\ChronologyProtector\getTouched(), and Wikimedia\Rdbms\ChronologyProtector\shutdown().
|
protected |
| array | bool | $curValue | |
| DBMasterPos[] | $shutdownPositions | |
| int | null | &$cpIndex |
Definition at line 371 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$shutdownPositions.
Referenced by Wikimedia\Rdbms\ChronologyProtector\shutdown().
| Wikimedia\Rdbms\ChronologyProtector::setEnabled | ( | $enabled | ) |
| bool | $enabled | Whether to no-op all method calls |
Definition at line 122 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$enabled.
| Wikimedia\Rdbms\ChronologyProtector::setLogger | ( | LoggerInterface | $logger | ) |
Definition at line 106 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$logger.
Referenced by Wikimedia\Rdbms\LBFactory\getChronologyProtector().
| Wikimedia\Rdbms\ChronologyProtector::setWaitEnabled | ( | $enabled | ) |
| bool | $enabled | Whether to check and wait on positions |
Definition at line 130 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$enabled.
| Wikimedia\Rdbms\ChronologyProtector::shutdown | ( | callable | $workCallback = null, |
$mode = 'sync', |
|||
| & | $cpIndex = null |
||
| ) |
Notify the ChronologyProtector that the LBFactory is done calling shutdownLB() for now.
May commit chronology data to persistent storage.
| callable | null | $workCallback | Work to do instead of waiting on syncing positions |
| string | $mode | One of (sync, async); whether to wait on remote datacenters |
| int | null | &$cpIndex | DB position key write counter; incremented on update |
Definition at line 202 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ChronologyProtector\$shutdownPositions, Wikimedia\Rdbms\ChronologyProtector\$store, BagOStuff\addBusyCallback(), BagOStuff\get(), BagOStuff\getQoS(), Wikimedia\Rdbms\ChronologyProtector\getTouchedKey(), BagOStuff\lock(), Wikimedia\Rdbms\ChronologyProtector\mergePositions(), BagOStuff\set(), and BagOStuff\unlock().
Referenced by Wikimedia\Rdbms\LBFactory\shutdownChronologyProtector().
| Wikimedia\Rdbms\ChronologyProtector::storeSessionReplicationPosition | ( | ILoadBalancer | $lb | ) |
Save the "session consistency" DB replication position for an end-of-life ILoadBalancer.
This saves the replication position of the master DB if this request made writes to it.
This method should only be called from LBFactory.
| ILoadBalancer | $lb |
Definition at line 172 of file ChronologyProtector.php.
References Wikimedia\Rdbms\ILoadBalancer\getReplicaResumePos(), Wikimedia\Rdbms\ILoadBalancer\getServerName(), Wikimedia\Rdbms\ILoadBalancer\getWriterIndex(), Wikimedia\Rdbms\ILoadBalancer\hasOrMadeRecentMasterChanges(), and Wikimedia\Rdbms\ILoadBalancer\hasStreamingReplicaServers().
Referenced by Wikimedia\Rdbms\LBFactory\shutdownChronologyProtector().
|
protected |
Hash of client parameters.
Definition at line 50 of file ChronologyProtector.php.
Referenced by Wikimedia\Rdbms\ChronologyProtector\getClientId().
|
protected |
Map of client information fields for logging.
Definition at line 52 of file ChronologyProtector.php.
|
protected |
Whether to no-op all method calls.
Definition at line 58 of file ChronologyProtector.php.
Referenced by Wikimedia\Rdbms\ChronologyProtector\setEnabled(), and Wikimedia\Rdbms\ChronologyProtector\setWaitEnabled().
|
protected |
Whether the client data was loaded.
Definition at line 63 of file ChronologyProtector.php.
|
protected |
Storage key name.
Definition at line 48 of file ChronologyProtector.php.
|
protected |
Definition at line 45 of file ChronologyProtector.php.
Referenced by Wikimedia\Rdbms\ChronologyProtector\setLogger().
|
protected |
Map of (DB master name => position)
Definition at line 67 of file ChronologyProtector.php.
Referenced by Wikimedia\Rdbms\ChronologyProtector\mergePositions(), and Wikimedia\Rdbms\ChronologyProtector\shutdown().
|
protected |
Map of (DB master name => 1)
Definition at line 69 of file ChronologyProtector.php.
|
protected |
Map of (DB master name => position)
Definition at line 65 of file ChronologyProtector.php.
Referenced by Wikimedia\Rdbms\ChronologyProtector\applySessionReplicationPosition(), and Wikimedia\Rdbms\ChronologyProtector\getStartupMasterPositions().
|
protected |
Definition at line 43 of file ChronologyProtector.php.
Referenced by Wikimedia\Rdbms\ChronologyProtector\__construct(), Wikimedia\Rdbms\ChronologyProtector\getTouchedKey(), and Wikimedia\Rdbms\ChronologyProtector\shutdown().
|
protected |
Whether to check and wait on positions.
Definition at line 60 of file ChronologyProtector.php.
|
protected |
Expected minimum index of the last write to the position store.
Definition at line 54 of file ChronologyProtector.php.
|
protected |
Max seconds to wait on positions to appear.
Definition at line 56 of file ChronologyProtector.php.
Referenced by Wikimedia\Rdbms\ChronologyProtector\getStartupMasterPositions().