Wikibase
MediaWiki Wikibase extension
Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator Class Reference

SQL based implementation of ChangeDispatchCoordinator;. More...

+ Inheritance diagram for Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator:
+ Collaboration diagram for Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator:

Public Member Functions

 __construct ( $repoDB, string $repoSiteId, ILBFactory $LBFactory, LoggerInterface $logger)
 
 setBatchSize (int $batchSize)
 Sets the number of changes we would prefer to process in one go. More...
 
 setMessageReporter (MessageReporter $messageReporter)
 
 setRandomness (int $randomness)
 Sets the randomness level: selectClient() will randomly pick one of the $randomness most lagged eligible client wikis. More...
 
 setDispatchInterval (int $dispatchInterval)
 Sets the number of seconds we would prefer to let a client "rest" before dispatching to it again. More...
 
 setArrayRandOverride (callable $array_rand)
 Set override for array_rand(), for testing. More...
 
 setTimeOverride (callable $time)
 Set override for time(), for testing. More...
 
 setEngageClientLockOverride (callable $engageClientLockOverride)
 Set override for $db->lock, for testing. More...
 
 setIsClientLockUsedOverride (callable $isClientLockUsedOverride)
 Set override for !$db->lockIsFree, for testing. More...
 
 setReleaseClientLockOverride (callable $releaseClientLockOverride)
 Set override for $db->unlock, for testing. More...
 
 setStateTable (string $stateTable)
 
 setChangesTable (string $changesTable)
 
 selectClient ()
 Selects a client wiki and locks it. More...
 
 initState (array $clientWikiDBs)
 Initializes the dispatch table by injecting dummy records for all target wikis that are in the configuration but not yet in the dispatch table. More...
 
 lockClient (string $siteID)
 Attempt to lock the given target wiki. More...
 
 releaseClient (array $state)
 Updates the given client wiki's entry in the dispatch table and releases the global lock on that wiki. More...
 

Protected Member Functions

 engageClientLock (string $lock)
 Tries to acquire a global lock on the given client wiki. More...
 
 releaseClientLock (IDatabase $db, string $lock)
 Releases the given global lock on the given client wiki. More...
 
 isClientLockUsed (IDatabase $db, string $lock)
 Checks the given global lock on the given client wiki. More...
 

Private Member Functions

 getRepoLB ()
 
 getRepoMaster ()
 
 getRepoReplica ()
 
 now ()
 
 getCandidateClients ()
 Returns a list of possible client for the next pass. More...
 
 getClientLockName (string $siteID)
 Determines the name of the global lock that should be used to lock the given client. More...
 
 warn (string $message)
 
 log (string $message, array $context)
 
 trace (string $message)
 
 getMessageReportString (string $message, array $context)
 

Private Attributes

 $array_rand = 'array_rand'
 
 $time = 'time'
 
 $engageClientLockOverride = null
 
 $releaseClientLockOverride = null
 
 $isClientLockUsedOverride = null
 
 $batchSize = 1000
 
 $dispatchInterval = 60
 
 $randomness = 15
 
 $stateTable = 'wb_changes_dispatch'
 
 $changesTable = 'wb_changes'
 
 $messageReporter
 
 $repoDB
 
 $repoSiteId
 
 $LBFactory
 
 $stats
 
 $logger
 

Detailed Description

SQL based implementation of ChangeDispatchCoordinator;.

Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::__construct (   $repoDB,
string  $repoSiteId,
ILBFactory  $LBFactory,
LoggerInterface  $logger 
)
Parameters
string | false$repoDB
string$repoSiteIdThe repo's global wiki ID
ILBFactory$LBFactory
LoggerInterface$logger

Member Function Documentation

◆ engageClientLock()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::engageClientLock ( string  $lock)
protected

Tries to acquire a global lock on the given client wiki.

Parameters
string$lockThe name of the lock to engage.
Returns
bool whether the lock was engaged successfully.

Reimplemented in Wikibase\Repo\Store\Sql\LockManagerSqlChangeDispatchCoordinator.

◆ getCandidateClients()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::getCandidateClients ( )
private

Returns a list of possible client for the next pass.

If no suitable clients are found, the resulting list will be empty.

Returns
array
See also
selectClient()

◆ getClientLockName()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::getClientLockName ( string  $siteID)
private

Determines the name of the global lock that should be used to lock the given client.

Parameters
string$siteIDThe site ID of the wiki to lock
Returns
string the lock name to use.

◆ getMessageReportString()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::getMessageReportString ( string  $message,
array  $context 
)
private
Parameters
string$message
array$context
Returns
string

◆ getRepoLB()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::getRepoLB ( )
private
Returns
ILoadBalancer the repo's database load balancer.

◆ getRepoMaster()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::getRepoMaster ( )
private
Returns
IDatabase A connection to the repo's master database

◆ getRepoReplica()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::getRepoReplica ( )
private
Returns
IDatabase A connection to the repo's replica database

◆ initState()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::initState ( array  $clientWikiDBs)

Initializes the dispatch table by injecting dummy records for all target wikis that are in the configuration but not yet in the dispatch table.

Parameters
string[]$clientWikiDBsAssociative array mapping client wiki IDs to client wiki (logical) database names.
Exceptions
DBUnexpectedError

Implements Wikibase\Repo\Store\ChangeDispatchCoordinator.

◆ isClientLockUsed()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::isClientLockUsed ( IDatabase  $db,
string  $lock 
)
protected

Checks the given global lock on the given client wiki.

Parameters
IDatabase$dbThe database connection to work on.
string$lockThe name of the lock to check.
Returns
bool true if the given lock is currently held by another process, false otherwise.

Reimplemented in Wikibase\Repo\Store\Sql\LockManagerSqlChangeDispatchCoordinator.

◆ lockClient()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::lockClient ( string  $siteID)

Attempt to lock the given target wiki.

If it can't be locked because another dispatch process is working on it, this method returns false.

Parameters
string$siteIDThe ID of the client wiki to lock.
Exceptions
MWExceptionif there are no client wikis to chose from.
Exception
Returns
bool|array An associative array containing the state of the selected client wiki (see selectClient()) or false if the client wiki could not be locked.
See also
selectClient()

Implements Wikibase\Repo\Store\ChangeDispatchCoordinator.

◆ log()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::log ( string  $message,
array  $context 
)
private

◆ now()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::now ( )
private
Returns
int The current time as a timestamp, in seconds since Epoch.

◆ releaseClient()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::releaseClient ( array  $state)

Updates the given client wiki's entry in the dispatch table and releases the global lock on that wiki.

Parameters
array$stateAssociative array representing the client wiki's state before the update pass, as returned by selectWiki().
Exceptions
Exception
See also
selectWiki()

Implements Wikibase\Repo\Store\ChangeDispatchCoordinator.

◆ releaseClientLock()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::releaseClientLock ( IDatabase  $db,
string  $lock 
)
protected

Releases the given global lock on the given client wiki.

Parameters
IDatabase$dbThe database connection to work on.
string$lockThe name of the lock to release.
Returns
bool whether the lock was released successfully.

Reimplemented in Wikibase\Repo\Store\Sql\LockManagerSqlChangeDispatchCoordinator.

◆ selectClient()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::selectClient ( )

Selects a client wiki and locks it.

If no suitable client wiki can be found, this method returns null.

Note: this implementation will try a wiki from the list returned by getCandidateClients() at random. If all have been tried and failed, it returns null.

Returns
array|null An associative array containing the state of the selected client wiki (or null, if no target could be locked). Fields are:
  • chd_site: the client wiki's global site ID
  • chd_db: the client wiki's logical database name
  • chd_seen: the last change ID processed for that client wiki
  • chd_touched: timestamp giving the last time that client wiki was updated
  • chd_lock: the name of a global lock currently active for that client wiki
Exceptions
MWExceptionif no available client wiki could be found.
See also
releaseWiki()

Implements Wikibase\Repo\Store\ChangeDispatchCoordinator.

◆ setArrayRandOverride()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setArrayRandOverride ( callable  $array_rand)

Set override for array_rand(), for testing.

Parameters
callable$array_rand

◆ setBatchSize()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setBatchSize ( int  $batchSize)

Sets the number of changes we would prefer to process in one go.

Clients that are lagged by fewer changes than this may be skipped by selectClient().

Parameters
int$batchSize

◆ setChangesTable()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setChangesTable ( string  $changesTable)
Parameters
string$changesTable

◆ setDispatchInterval()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setDispatchInterval ( int  $dispatchInterval)

Sets the number of seconds we would prefer to let a client "rest" before dispatching to it again.

Clients that have received updates less than $dispatchInterval seconds ago may be skipped by selectClient().

Parameters
int$dispatchInterval

◆ setEngageClientLockOverride()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setEngageClientLockOverride ( callable  $engageClientLockOverride)

Set override for $db->lock, for testing.

Parameters
callable$engageClientLockOverride

◆ setIsClientLockUsedOverride()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setIsClientLockUsedOverride ( callable  $isClientLockUsedOverride)

Set override for !$db->lockIsFree, for testing.

Parameters
callable$isClientLockUsedOverride

◆ setMessageReporter()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setMessageReporter ( MessageReporter  $messageReporter)

◆ setRandomness()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setRandomness ( int  $randomness)

Sets the randomness level: selectClient() will randomly pick one of the $randomness most lagged eligible client wikis.

Parameters
int$randomness

◆ setReleaseClientLockOverride()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setReleaseClientLockOverride ( callable  $releaseClientLockOverride)

Set override for $db->unlock, for testing.

Parameters
callable$releaseClientLockOverride

◆ setStateTable()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setStateTable ( string  $stateTable)
Parameters
string$stateTable

◆ setTimeOverride()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::setTimeOverride ( callable  $time)

Set override for time(), for testing.

Parameters
callable$time

◆ trace()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::trace ( string  $message)
private

◆ warn()

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::warn ( string  $message)
private

Member Data Documentation

◆ $array_rand

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$array_rand = 'array_rand'
private

◆ $batchSize

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$batchSize = 1000
private

◆ $changesTable

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$changesTable = 'wb_changes'
private

◆ $dispatchInterval

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$dispatchInterval = 60
private

◆ $engageClientLockOverride

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$engageClientLockOverride = null
private

◆ $isClientLockUsedOverride

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$isClientLockUsedOverride = null
private

◆ $LBFactory

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$LBFactory
private

◆ $logger

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$logger
private

◆ $messageReporter

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$messageReporter
private

◆ $randomness

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$randomness = 15
private

◆ $releaseClientLockOverride

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$releaseClientLockOverride = null
private

◆ $repoDB

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$repoDB
private

◆ $repoSiteId

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$repoSiteId
private

◆ $stateTable

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$stateTable = 'wb_changes_dispatch'
private

◆ $stats

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$stats
private

◆ $time

Wikibase\Repo\Store\Sql\SqlChangeDispatchCoordinator::$time = 'time'
private

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