Wikibase
MediaWiki Wikibase extension
Wikibase\Repo\ChangeDispatcher Class Reference

Interactor class for dispatching change notifications to client wikis via the job queue. More...

Public Member Functions

 __construct (ChangeDispatchCoordinator $coordinator, ChangeNotificationSender $notificationSender, ChunkAccess $chunkedChangesAccess, SubscriptionLookup $subscriptionLookup)
 
 isVerbose ()
 
 setVerbose ( $verbose)
 
 getMessageReporter ()
 
 setMessageReporter (MessageReporter $messageReporter)
 
 getExceptionHandler ()
 
 setExceptionHandler (ExceptionHandler $exceptionHandler)
 
 getBatchSize ()
 
 setBatchSize ( $batchSize)
 
 getBatchChunkFactor ()
 
 setMaxChunks ( $maxChunks)
 
 getMaxChunks ()
 
 setBatchChunkFactor ( $batchChunkFactor)
 Sets the chunk factor. More...
 
 selectClient ()
 Selects a client wiki and locks it. More...
 
 getPendingChanges ( $siteID, $after)
 Returns a batch of changes for the given client wiki, starting from the given position in the wb_changes table. More...
 
 getDispatchCoordinator ()
 

Private Member Functions

 isRelevantChange (Change $change, $siteID)
 Checks whether the given Change is somehow relevant to the given wiki site. More...
 
 filterChanges ( $siteID, array $changes, $limit)
 Filters a list of changes, removing changes not relevant to the given client wiki. More...
 
 reIndexEntityIds (array $entityIds)
 
 trace ( $message)
 Log a message if verbose mode is enabled. More...
 
 log ( $message)
 

Private Attributes

 $batchSize = 1000
 
 $batchChunkFactor = 3
 
 $maxChunks = 15
 
 $verbose = false
 
 $notificationSender
 
 $coordinator
 
 $exceptionHandler
 
 $messageReporter
 
 $chunkedChangesAccess
 
 $subscriptionLookup
 

Detailed Description

Interactor class for dispatching change notifications to client wikis via the job queue.

See also
Change propagation for an overview of the change propagation mechanism.
Author
Daniel Kinzler

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Repo\ChangeDispatcher::__construct ( ChangeDispatchCoordinator  $coordinator,
ChangeNotificationSender  $notificationSender,
ChunkAccess  $chunkedChangesAccess,
SubscriptionLookup  $subscriptionLookup 
)
Parameters
ChangeDispatchCoordinator$coordinator
ChangeNotificationSender$notificationSender
ChunkAccess$chunkedChangesAccessAccess to the changes table. Should only return Change objects from loadChunk.
SubscriptionLookup$subscriptionLookup

Member Function Documentation

◆ filterChanges()

Wikibase\Repo\ChangeDispatcher::filterChanges (   $siteID,
array  $changes,
  $limit 
)
private

Filters a list of changes, removing changes not relevant to the given client wiki.

Currently, we keep EntityChanges for entities the client wiki is subscribed to, or that modify a sitelink to the client wiki.

Parameters
string$siteIDThe client wiki's global site identifier, as used by sitelinks.
Change[]$changesThe list of changes to filter.
int$limitThe max number of changes to return
Returns
array ( EntityChange[] $batch, int $seen ), where $batch is the filtered list of Change objects, and $seen is the ID of the last change considered for the batch (even if that was filtered out), for use as a continuation marker. -return array{0:EntityChange[],1:int}

◆ getBatchChunkFactor()

Wikibase\Repo\ChangeDispatcher::getBatchChunkFactor ( )
Returns
int

◆ getBatchSize()

Wikibase\Repo\ChangeDispatcher::getBatchSize ( )
Returns
int

◆ getDispatchCoordinator()

Wikibase\Repo\ChangeDispatcher::getDispatchCoordinator ( )
Returns
ChangeDispatchCoordinator

◆ getExceptionHandler()

Wikibase\Repo\ChangeDispatcher::getExceptionHandler ( )
Returns
ExceptionHandler

◆ getMaxChunks()

Wikibase\Repo\ChangeDispatcher::getMaxChunks ( )
Returns
int Maximum number of chunks or passes per wiki when selecting pending changes.

◆ getMessageReporter()

Wikibase\Repo\ChangeDispatcher::getMessageReporter ( )
Returns
MessageReporter

◆ getPendingChanges()

Wikibase\Repo\ChangeDispatcher::getPendingChanges (   $siteID,
  $after 
)

Returns a batch of changes for the given client wiki, starting from the given position in the wb_changes table.

The changes may be filtered to only include those changes that are relevant to the given client wiki. The number of changes returned by this method is limited by $this->batchSize. Changes are returned with IDs in ascending order.

Note
due to programmatic filtering, this method may use multiple database queries to collect the changes for the next batch. The number of requests needed can be adjusted using $this->batchChunkFactor (via the 'dispatchBatchChunkFactor' setting).
Parameters
string$siteIDThe client wiki's global site identifier, as used by sitelinks.
int$afterThe last change ID processed by a previous run. All changes returned will have an ID greater than $after.
Returns
array ( Change[] $batch, int $seen ), where $batch is a list of Change objects, and $seen is the ID of the last change considered for the batch (even if that was filtered out), for use as a continuation marker. -return array{0:Change[],1:int}

◆ isRelevantChange()

Wikibase\Repo\ChangeDispatcher::isRelevantChange ( Change  $change,
  $siteID 
)
private

Checks whether the given Change is somehow relevant to the given wiki site.

In particular this check whether the Change modifies any sitelink that refers to the given wiki site.

Note
this does not check whether the entity that was changes is or is not at all connected with (resp. used on) the target wiki.
Parameters
Change$changethe change to examine.
string$siteIDthe site to consider.
Returns
bool

◆ isVerbose()

Wikibase\Repo\ChangeDispatcher::isVerbose ( )
Returns
bool

◆ log()

Wikibase\Repo\ChangeDispatcher::log (   $message)
private

◆ reIndexEntityIds()

Wikibase\Repo\ChangeDispatcher::reIndexEntityIds ( array  $entityIds)
private
Parameters
EntityId[]$entityIds
Returns
EntityId[] $entityIds re-keyed by id string.

◆ selectClient()

Wikibase\Repo\ChangeDispatcher::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 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()

◆ setBatchChunkFactor()

Wikibase\Repo\ChangeDispatcher::setBatchChunkFactor (   $batchChunkFactor)

Sets the chunk factor.

The governs how many changes getPendingChanges will load in one go: the number loaded is the batch size multiplied by the batch chunk factor. A chunk factor > 1 reduces the need to load more changes in case not all end up in the batch opf pending changes due to programmatic filtering (e.g. by whether the client site is subscribed to a given change).

For example: Consider loading a batch of 5 changes to dispatch to foowiki, but of the first 5 changes, only 3 are relevant to foowiki. A chunk factor of 1 means only 5 changes have been loaded for examination, meaning at least one more batch has to be loaded. A chunk factor of 2 means 10 changes have been loaded for examination, which makes it more likely to fine the desired 5 changes for foowiki without loading more changes.

Parameters
int$batchChunkFactor

◆ setBatchSize()

Wikibase\Repo\ChangeDispatcher::setBatchSize (   $batchSize)
Parameters
int$batchSize

◆ setExceptionHandler()

Wikibase\Repo\ChangeDispatcher::setExceptionHandler ( ExceptionHandler  $exceptionHandler)

◆ setMaxChunks()

Wikibase\Repo\ChangeDispatcher::setMaxChunks (   $maxChunks)
Parameters
int$maxChunksMaximum number of chunks or passes per wiki when selecting pending changes.

◆ setMessageReporter()

Wikibase\Repo\ChangeDispatcher::setMessageReporter ( MessageReporter  $messageReporter)

◆ setVerbose()

Wikibase\Repo\ChangeDispatcher::setVerbose (   $verbose)
Parameters
bool$verbose

◆ trace()

Wikibase\Repo\ChangeDispatcher::trace (   $message)
private

Log a message if verbose mode is enabled.

Parameters
string$message

Member Data Documentation

◆ $batchChunkFactor

Wikibase\Repo\ChangeDispatcher::$batchChunkFactor = 3
private

◆ $batchSize

Wikibase\Repo\ChangeDispatcher::$batchSize = 1000
private

◆ $chunkedChangesAccess

Wikibase\Repo\ChangeDispatcher::$chunkedChangesAccess
private

◆ $coordinator

Wikibase\Repo\ChangeDispatcher::$coordinator
private

◆ $exceptionHandler

Wikibase\Repo\ChangeDispatcher::$exceptionHandler
private

◆ $maxChunks

Wikibase\Repo\ChangeDispatcher::$maxChunks = 15
private

◆ $messageReporter

Wikibase\Repo\ChangeDispatcher::$messageReporter
private

◆ $notificationSender

Wikibase\Repo\ChangeDispatcher::$notificationSender
private

◆ $subscriptionLookup

Wikibase\Repo\ChangeDispatcher::$subscriptionLookup
private

◆ $verbose

Wikibase\Repo\ChangeDispatcher::$verbose = false
private

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