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:
authorsgiehl <stefan@matomo.org>2020-05-08 15:41:26 +0300
committersgiehl <stefan@matomo.org>2020-05-08 17:41:34 +0300
commit58991fbe62be4e3d1af1e6a1772aff25934c51d3 (patch)
tree6d0c5390383dacff54849753885b70ef026a0a1e /core/Concurrency
parent1ac50c2a702bf22189a246c99b2dc9c0e7979217 (diff)
parentbd9aa9db1a95e6f1ef74b45e3723849fab2f292c (diff)
Merge remote-tracking branch 'origin/3.x-dev' into 4.x-dev
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 360c771828..2019c2955f 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.');