Ladsgroup has uploaded a new change for review. https://gerrit.wikimedia.org/r/325640
Change subject: [very WIP] [Draft] [DNM] [I can't emphasize enough] Add RedisLockSqlChangeDispatchCoordinator ...................................................................... [very WIP] [Draft] [DNM] [I can't emphasize enough] Add RedisLockSqlChangeDispatchCoordinator Bug: T151993 Change-Id: Iafe661cb4c39f3ebf393e2daf4a88a51f7d8bdfc --- A repo/includes/Store/Sql/RedisLockSqlChangeDispatchCoordinator.php M repo/includes/Store/Sql/SqlChangeDispatchCoordinator.php 2 files changed, 90 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/40/325640/1 diff --git a/repo/includes/Store/Sql/RedisLockSqlChangeDispatchCoordinator.php b/repo/includes/Store/Sql/RedisLockSqlChangeDispatchCoordinator.php new file mode 100644 index 0000000..ccb8601 --- /dev/null +++ b/repo/includes/Store/Sql/RedisLockSqlChangeDispatchCoordinator.php @@ -0,0 +1,87 @@ +<?php + +namespace Wikibase\Store\Sql; + +use Database; +use RedisLockManager; + + +/** + * Redis based implementation of ChangeDispatchCoordinator; + * + * @license GPL-2.0+ + * @author Amir Sarabadani <ladsgr...@gmail.com> + */ +class RedisLockSqlChangeDispatchCoordinator extends SqlChangeDispatchCoordinator { + + /** + * @var RedisLockManager + */ + private $lockManager; + + /** + * RedisLockSqlChangeDispatchCoordinator constructor. + * + * @param RedisLockManager $lockManager + * @param string|false $repoDB + * @param string $repoSiteId The repo's global wiki ID + */ + public function __construct( RedisLockManager $lockManager, $repoDB, $repoSiteId ) { + $this->lockManager = $lockManager; + parent::__construct( $repoDB, $repoSiteId ); + } + + /** + * @see SqlChangeDispatchCoordinator::engageClientLock() + * + * @param Database $db The database connection to work on. + * @param string $lock The name of the lock to engage. + * + * @return bool whether the lock was engaged successfully. + */ + private function engageClientLock( Database $db, $lock ) { + + return $this->lockManager->lock( [ $lock ] )->isOK(); + } + + /** + * @see SqlChangeDispatchCoordinator::releaseClient() + * + * @param Database $db The database connection to work on. + * @param string $lock The name of the lock to release. + * + * @return bool whether the lock was released successfully. + */ + private function releaseClientLock( Database $db, $lock ) { + + return $this->lockManager->unlock( [ $lock ] )->isOK(); + } + + /** + * @see SqlChangeDispatchCoordinator::isClientLockUsed() + * + * @param Database $db The database connection to work on. + * @param string $lock The name of the lock to check. + * + * @return bool true if the given lock is currently held by another process, false otherwise. + */ + private function isClientLockUsed( Database $db, $lock ) { + + return !$db->lockIsFree( $lock, __METHOD__ ); + } + + /** + * @return RedisLockManager + */ + public function getLockManager() { + return $this->lockManager; + } + + /** + * @param RedisLockManager $lockManager + */ + public function setLockManager( RedisLockManager $lockManager ) { + $this->lockManager = $lockManager; + } + +} diff --git a/repo/includes/Store/Sql/SqlChangeDispatchCoordinator.php b/repo/includes/Store/Sql/SqlChangeDispatchCoordinator.php index d49f0f4..ea710ca 100644 --- a/repo/includes/Store/Sql/SqlChangeDispatchCoordinator.php +++ b/repo/includes/Store/Sql/SqlChangeDispatchCoordinator.php @@ -25,7 +25,7 @@ /** * @var callable Override for the array_rand function */ - private $array_rand = 'array_rand'; + protected $array_rand = 'array_rand'; /** * @var callable Override for the time function @@ -291,7 +291,7 @@ * * @see selectClient() */ - private function getCandidateClients() { + protected function getCandidateClients() { $db = $this->getRepoMaster(); // XXX: subject to clock skew. Use DB based "now" time? @@ -544,7 +544,7 @@ * Tries to acquire a global lock on the given client wiki. * * @param Database $db The database connection to work on. - * @param string $lock The name of the lock to engage. + * @param string $lock The name of the lock to release. * * @return bool whether the lock was engaged successfully. */ -- To view, visit https://gerrit.wikimedia.org/r/325640 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iafe661cb4c39f3ebf393e2daf4a88a51f7d8bdfc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits