Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAT-10769: save the last updatedAt #9437

Merged
merged 2 commits into from
May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
*/
class KAsyncStoragePeriodicPurge extends KStorageFileSyncsBase
{
const GAP = 'gap';
const RELATIVE_TIME_RANGE = 'relativeTimeRange';
const LOCK_EXPIRY_TIMEOUT = 'lockExpiryTimeout';
const RELATIVE_TIME_RANGE = 'relativeTimeRange';
const RELATIVE_TIME_DELETION_LIMIT = 'relativeTimeDeletionLimit';

protected $gap;
protected $relativeTimeRange;
protected $lockExpiryTimeout;
protected $relativeTimeRange;
protected $relativeTimeDeletionLimit;

/* (non-PHPdoc)
* @see KBatchBase::getType()
Expand All @@ -26,16 +26,15 @@ public static function getType()

protected function getParamsOperation()
{
$this->gap = $this->getAdditionalParams(self::GAP);
$this->relativeTimeRange = $this->getAdditionalParams(self::RELATIVE_TIME_RANGE);
$this->lockExpiryTimeout = $this->getAdditionalParams(self::LOCK_EXPIRY_TIMEOUT);
$this->relativeTimeRange = $this->getAdditionalParams(self::RELATIVE_TIME_RANGE);
$this->relativeTimeDeletionLimit = $this->getAdditionalParams(self::RELATIVE_TIME_DELETION_LIMIT);
}

protected function lockFileSyncs($filter)
{
$filter->updatedAtLessThanOrEqual = time() - $this->gap;
$filter->updatedAtGreaterThanOrEqual = $filter->updatedAtLessThanOrEqual - $this->relativeTimeRange;
return self::$kClient->fileSync->lockFileSyncs($filter, $this->maxCount, $this->lockExpiryTimeout);
return self::$kClient->fileSync->lockFileSyncs($filter, $this->getId(), $this->relativeTimeDeletionLimit,
$this->relativeTimeRange, $this->lockExpiryTimeout, $this->maxCount);
}

protected function processOperation($engine)
Expand Down
27 changes: 20 additions & 7 deletions plugins/file_sync/services/FileSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ protected static function getCache()
return $keysCache;
}

protected static function setRange($filter, $lastUpdatedAt, $relativeTimeDeletionLimit, $relativeTimeRange)
protected static function setRange($filter, $lastUpdatedAt, $relativeTimeLimit, $relativeTimeRange)
{
$absoluteDeletionTimeLimit = time() - $relativeTimeDeletionLimit;
$absoluteTimeLimit = time() - $relativeTimeLimit;

if($lastUpdatedAt)
{
KalturaLog::info("Last updatedAt is [{$lastUpdatedAt}]");
$filter->updatedAtGreaterThanOrEqual = $lastUpdatedAt + 1;
$filter->updatedAtLessThanOrEqual = min($filter->updatedAtGreaterThanOrEqual + $relativeTimeRange, $absoluteDeletionTimeLimit);
$filter->updatedAtLessThanOrEqual = min($filter->updatedAtGreaterThanOrEqual + $relativeTimeRange, $absoluteTimeLimit);
}
else
{
KalturaLog::info('Use default updatedAt');
$filter->updatedAtLessThanOrEqual = $absoluteDeletionTimeLimit;
$filter->updatedAtLessThanOrEqual = $absoluteTimeLimit;
$filter->updatedAtGreaterThanOrEqual = $filter->updatedAtLessThanOrEqual - $relativeTimeRange;
}

Expand Down Expand Up @@ -199,15 +199,25 @@ function updateAction($id, KalturaFileSync $fileSync)
*
* @action lockFileSyncs
* @param KalturaFileSyncFilter $filter
* @param int $workerId The id of the file sync import worker
* @param int $relativeTimeLimit Seconds from now that will be ignored
* @param int $relativeTimeRange Seconds of the query
* @param int $lockExpiryTimeout The expiry timeout of the lock
* @param int $maxCount The maximum number of file syncs that should be returned
* @param int $lockExpiryTimeOut The expiry timeout of the lock
* @return KalturaLockFileSyncsResponse
*/
function lockFileSyncsAction(KalturaFileSyncFilter $filter, $maxCount, $lockExpiryTimeOut)
function lockFileSyncsAction(KalturaFileSyncFilter $filter, $workerId, $relativeTimeLimit, $relativeTimeRange, $lockExpiryTimeout, $maxCount)
{
// need to explicitly disable the cache since this action may not perform any queries
kApiCache::disableConditionalCache();

// Get last updatedAt
$keysCache = self::getCache();
$lastUpdatedAt = $keysCache->get(self::LAST_FILESYNC_UPDATE_AT_PREFIX . $workerId);

// Set range on filter
self::setRange($filter, $lastUpdatedAt, $relativeTimeLimit, $relativeTimeRange);

$lockCache = self::getLockCache();

$baseCriteria = $filter->buildFileSyncNotLinkedCriteria(FileSyncPeer::UPDATED_AT);
Expand All @@ -220,12 +230,15 @@ function lockFileSyncsAction(KalturaFileSyncFilter $filter, $maxCount, $lockExpi

if ($fileSyncs)
{
FileSync::lockFileSyncs($fileSyncs, $lockCache, self::LOCK_KEY_PREFIX, $lockExpiryTimeOut,
FileSync::lockFileSyncs($fileSyncs, $lockCache, self::LOCK_KEY_PREFIX, $lockExpiryTimeout,
$lockedFileSyncs, $limitReached, $maxCount);

FileSync::createFileSyncsPath($lockedFileSyncs);
}

// Set last updatedAt
$keysCache->set(self::LAST_FILESYNC_UPDATE_AT_PREFIX . $workerId, $filter->updatedAtLessThanOrEqual);

// build the response object
$result = new KalturaLockFileSyncsResponse;
$result->fileSyncs = KalturaFileSyncArray::fromDbArray($lockedFileSyncs, $this->getResponseProfile());
Expand Down
2 changes: 1 addition & 1 deletion release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Add the following to batch.ini:
params.maxExecutionTime = @MAX_EXECUTION_TIME@
params.sleepInterval = @SLEEP_INTERVAL@
params.lockExpiryTimeout = @LOCK_EXPIRY_TIMEOUT@
params.gap = @GAP@
params.relativeTimeDeletionLimit = @RELATIVE_TIME_DELETION_LIMIT@
params.relativeTimeRange = @RELATIVE_TIME_RANGE@
filter.statusEqual = 3
filter.dcIn = @DC@
Expand Down