diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2021-06-10 05:48:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-10 05:48:22 +0300 |
commit | 3a1467fc8378b3bebce1c11d161384e3d239d263 (patch) | |
tree | b93901315894f7b8bdb576d0843242a63828bb09 /core | |
parent | 23cb53d35ead2312b8afc9a6ec91a5fe8f78723e (diff) |
Remove archive status locking since it is not needed anymore (#17657)
* Remove archive status locking since it is not needed with the status and ts_started columns in the archive_invalidation table.
* fix some tests
Diffstat (limited to 'core')
-rw-r--r-- | core/Archive/ArchiveInvalidator.php | 11 | ||||
-rw-r--r-- | core/ArchiveProcessor/Loader.php | 14 | ||||
-rw-r--r-- | core/Concurrency/Lock.php | 1 | ||||
-rw-r--r-- | core/DataAccess/ArchivingDbAdapter.php | 23 | ||||
-rw-r--r-- | core/DataAccess/LogAggregator.php | 6 | ||||
-rw-r--r-- | core/DataAccess/Model.php | 29 |
6 files changed, 18 insertions, 66 deletions
diff --git a/core/Archive/ArchiveInvalidator.php b/core/Archive/ArchiveInvalidator.php index da0612178a..397b47a759 100644 --- a/core/Archive/ArchiveInvalidator.php +++ b/core/Archive/ArchiveInvalidator.php @@ -9,10 +9,7 @@ namespace Piwik\Archive; -use Piwik\Access; use Piwik\Archive\ArchiveInvalidator\InvalidationResult; -use Piwik\ArchiveProcessor\ArchivingStatus; -use Piwik\ArchiveProcessor\Loader; use Piwik\ArchiveProcessor\Rules; use Piwik\Config; use Piwik\Container\StaticContainer; @@ -74,11 +71,6 @@ class ArchiveInvalidator private $model; /** - * @var ArchivingStatus - */ - private $archivingStatus; - - /** * @var SegmentArchiving */ private $segmentArchiving; @@ -93,10 +85,9 @@ class ArchiveInvalidator */ private $allIdSitesCache; - public function __construct(Model $model, ArchivingStatus $archivingStatus, LoggerInterface $logger) + public function __construct(Model $model, LoggerInterface $logger) { $this->model = $model; - $this->archivingStatus = $archivingStatus; $this->segmentArchiving = null; $this->logger = $logger; } diff --git a/core/ArchiveProcessor/Loader.php b/core/ArchiveProcessor/Loader.php index 703d55eda4..02b981ffa9 100644 --- a/core/ArchiveProcessor/Loader.php +++ b/core/ArchiveProcessor/Loader.php @@ -154,18 +154,8 @@ class Loader $this->logger->info("initiating archiving via core:archive for " . $this->params); } - /** @var ArchivingStatus $archivingStatus */ - $archivingStatus = StaticContainer::get(ArchivingStatus::class); - $locked = $archivingStatus->archiveStarted($this->params); - - try { - list($visits, $visitsConverted) = $this->prepareCoreMetricsArchive($visits, $visitsConverted); - list($idArchive, $visits) = $this->prepareAllPluginsArchive($visits, $visitsConverted); - } finally { - if ($locked) { - $archivingStatus->archiveFinished(); - } - } + list($visits, $visitsConverted) = $this->prepareCoreMetricsArchive($visits, $visitsConverted); + list($idArchive, $visits) = $this->prepareAllPluginsArchive($visits, $visitsConverted); if ($this->isThereSomeVisits($visits) || PluginsArchiver::doesAnyPluginArchiveWithoutVisits()) { return [[$idArchive], $visits]; diff --git a/core/Concurrency/Lock.php b/core/Concurrency/Lock.php index 9959a533c9..4e8a407493 100644 --- a/core/Concurrency/Lock.php +++ b/core/Concurrency/Lock.php @@ -8,7 +8,6 @@ */ namespace Piwik\Concurrency; -use Piwik\ArchiveProcessor\ArchivingStatus; use Piwik\Common; use Piwik\Date; diff --git a/core/DataAccess/ArchivingDbAdapter.php b/core/DataAccess/ArchivingDbAdapter.php index 2ef88751c8..660268c27b 100644 --- a/core/DataAccess/ArchivingDbAdapter.php +++ b/core/DataAccess/ArchivingDbAdapter.php @@ -9,8 +9,6 @@ namespace Piwik\DataAccess; -use Piwik\ArchiveProcessor\ArchivingStatus; -use Piwik\Concurrency\Lock; use Piwik\Config; use Piwik\Db\AdapterInterface; use Piwik\DbHelper; @@ -24,11 +22,6 @@ class ArchivingDbAdapter private $wrapped; /** - * @var Lock - */ - private $archivingLock; - - /** * @var LoggerInterface */ private $logger; @@ -38,10 +31,9 @@ class ArchivingDbAdapter */ private $maxExecutionTime; - public function __construct($wrapped, Lock $archivingLock = null, LoggerInterface $logger = null) + public function __construct($wrapped, LoggerInterface $logger = null) { $this->wrapped = $wrapped; - $this->archivingLock = $archivingLock; $this->logger = $logger; $this->maxExecutionTime = (float) Config::getInstance()->General['archiving_query_max_execution_time']; } @@ -53,7 +45,6 @@ class ArchivingDbAdapter public function exec($sql) { - $this->reexpireLock(); $sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime); $this->logSql($sql); @@ -62,7 +53,6 @@ class ArchivingDbAdapter public function query($sql) { - $this->reexpireLock(); $sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime); $this->logSql($sql); @@ -71,7 +61,6 @@ class ArchivingDbAdapter public function fetchAll($sql) { - $this->reexpireLock(); $sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime); $this->logSql($sql); @@ -80,7 +69,6 @@ class ArchivingDbAdapter public function fetchRow($sql) { - $this->reexpireLock(); $sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime); $this->logSql($sql); @@ -89,7 +77,6 @@ class ArchivingDbAdapter public function fetchOne($sql) { - $this->reexpireLock(); $sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime); $this->logSql($sql); @@ -98,7 +85,6 @@ class ArchivingDbAdapter public function fetchAssoc($sql) { - $this->reexpireLock(); $sql = DbHelper::addMaxExecutionTimeHintToQuery($sql, $this->maxExecutionTime); $this->logSql($sql); @@ -112,11 +98,4 @@ class ArchivingDbAdapter $this->logger->debug($sql); } } - - private function reexpireLock() - { - if ($this->archivingLock) { - $this->archivingLock->reexpireLock(); - } - } }
\ No newline at end of file diff --git a/core/DataAccess/LogAggregator.php b/core/DataAccess/LogAggregator.php index 7097aa7a64..e283af2691 100644 --- a/core/DataAccess/LogAggregator.php +++ b/core/DataAccess/LogAggregator.php @@ -8,7 +8,6 @@ */ namespace Piwik\DataAccess; -use Piwik\ArchiveProcessor\ArchivingStatus; use Piwik\ArchiveProcessor\Parameters; use Piwik\Common; use Piwik\Config; @@ -1240,9 +1239,6 @@ class LogAggregator public function getDb() { - /** @var ArchivingStatus $archivingStatus */ - $archivingStatus = StaticContainer::get(ArchivingStatus::class); - $archivingLock = $archivingStatus->getCurrentArchivingLock(); - return new ArchivingDbAdapter(Db::getReader(), $archivingLock, $this->logger); + return new ArchivingDbAdapter(Db::getReader(), $this->logger); } } diff --git a/core/DataAccess/Model.php b/core/DataAccess/Model.php index 09c555531d..40528f60bd 100644 --- a/core/DataAccess/Model.php +++ b/core/DataAccess/Model.php @@ -10,7 +10,6 @@ namespace Piwik\DataAccess; use Exception; use Piwik\Archive\ArchiveInvalidator; -use Piwik\ArchiveProcessor\ArchivingStatus; use Piwik\ArchiveProcessor\Parameters; use Piwik\ArchiveProcessor\Rules; use Piwik\Common; @@ -35,15 +34,9 @@ class Model */ private $logger; - /** - * @var ArchivingStatus - */ - private $archivingStatus; - public function __construct(LoggerInterface $logger = null) { $this->logger = $logger ?: StaticContainer::get('Psr\Log\LoggerInterface'); - $this->archivingStatus = StaticContainer::get(ArchivingStatus::class); } /** @@ -696,16 +689,20 @@ class Model return true; } - // if we didn't get anything, some process either got there first, OR - // the archive was started previously and failed in a way that kept it's done value - // set to DONE_IN_PROGRESS. try to acquire the lock and if acquired, archiving isn' in process - // so we can claim it. - $lock = $this->archivingStatus->acquireArchiveInProgressLock($invalidation['idsite'], $invalidation['date1'], - $invalidation['date2'], $invalidation['period'], $invalidation['name']); - if (!$lock->isLocked()) { - return false; // we couldn't claim the lock, archive is in progress + // archive was not originally started or was started within 24 hours, we assume it's ongoing and another process + // (on this machine or another) is actively archiving it. + if (empty($invalidation['ts_started']) + || $invalidation['ts_started'] > Date::now()->subDay(1)->getTimestamp() + ) { + return false; } + // archive was started over 24 hours ago, we assume it failed and take it over + Db::query("UPDATE `$table` SET `status` = ?, ts_started = NOW() WHERE idinvalidation = ?", [ + ArchiveInvalidator::INVALIDATION_STATUS_IN_PROGRESS, + $invalidation['idinvalidation'], + ]); + // remove similar invalidations w/ lesser idinvalidation values $bind = [ $invalidation['idsite'], @@ -767,7 +764,7 @@ class Model public function getNextInvalidatedArchive($idSite, $archivingStartTime, $idInvalidationsToExclude = null, $useLimit = true) { $table = Common::prefixTable('archive_invalidations'); - $sql = "SELECT idinvalidation, idarchive, idsite, date1, date2, period, `name`, report, ts_invalidated + $sql = "SELECT * FROM `$table` WHERE idsite = ? AND status != ? AND ts_invalidated <= ?"; $bind = [ |