Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <diosmosis@users.noreply.github.com>2020-04-29 04:17:33 +0300
committerGitHub <noreply@github.com>2020-04-29 04:17:33 +0300
commit1d582249189368bcfe2bbf9c1415e058d52e4ce6 (patch)
tree992458fcebb9ce0d0f50c9ae2979e27d6b55dbdc /core/Concurrency
parent2466e9f4447e2491faea1201c838657e2385cd94 (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.php21
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.');