diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2020-04-29 04:17:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 04:17:33 +0300 |
commit | 1d582249189368bcfe2bbf9c1415e058d52e4ce6 (patch) | |
tree | 992458fcebb9ce0d0f50c9ae2979e27d6b55dbdc /core/Concurrency | |
parent | 2466e9f4447e2491faea1201c838657e2385cd94 (diff) |
put rexpiring delay logic in Lock class (#15874)
* Only use one reader db instance per LogAggregator.
* use re-expire logic in Lock itself
* tweak
* Remove unneeded var
* fix test
Diffstat (limited to 'core/Concurrency')
-rw-r--r-- | core/Concurrency/Lock.php | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/core/Concurrency/Lock.php b/core/Concurrency/Lock.php index f26f589699..3063078865 100644 --- a/core/Concurrency/Lock.php +++ b/core/Concurrency/Lock.php @@ -8,11 +8,14 @@ */ namespace Piwik\Concurrency; +use Piwik\ArchiveProcessor\ArchivingStatus; use Piwik\Common; +use Piwik\Date; class Lock { const MAX_KEY_LEN = 70; + const DEFAULT_TTL = 60; /** * @var LockBackend @@ -24,18 +27,28 @@ class Lock private $lockKey = null; private $lockValue = null; private $defaultTtl = null; + private $lastExpireTime = null; public function __construct(LockBackend $backend, $lockKeyStart, $defaultTtl = null) { $this->backend = $backend; $this->lockKeyStart = $lockKeyStart; $this->lockKey = $this->lockKeyStart; - $this->defaultTtl = $defaultTtl; + $this->defaultTtl = $defaultTtl ?: self::DEFAULT_TTL; } public function reexpireLock() { - $this->expireLock($this->defaultTtl); + $timeBetweenReexpires = $this->defaultTtl - ($this->defaultTtl / 4); + + $now = Date::getNowTimestamp(); + if (!empty($this->lastExpireTime) && + $now <= $this->lastExpireTime + $timeBetweenReexpires + ) { + return false; + } + + return $this->expireLock($this->defaultTtl); } public function getNumberOfAcquiredLocks() @@ -81,6 +94,8 @@ class Lock if ($locked) { $this->lockValue = $lockValue; + $this->ttlUsed = $ttlInSeconds; + $this->lastExpireTime = Date::getNowTimestamp(); } return $locked; @@ -125,6 +140,8 @@ class Lock return false; } + $this->lastExpireTime = Date::getNowTimestamp(); + return true; } else { Common::printDebug('Lock is not acquired, cannot update expiration.'); |