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-10553: lock replace entry flow to avoid race condition in case 2… #9135

Merged
merged 3 commits into from Jan 28, 2020

Conversation

@inbal-ben-david
Copy link
Contributor

inbal-ben-david commented Jan 27, 2020

… flavors are ready ar the same time

@@ -22,6 +22,19 @@ public static function replaceEntry(entry $replacedEntry, entry $replacingEntry
return;
}

$lock = kLock::create("replacement_" . $replacedEntry->getId() . "_" . $replacingEntry->getId());
if ($lock && !$lock->lock())

This comment has been minimized.

Copy link
@MosheMaorKaltura

MosheMaorKaltura Jan 28, 2020

Contributor

Consider setting the lock timeout higher the default of 2 seconds since the replacement process may be longer


if($replacingEntry->getSyncFlavorsOnceReady())
{
KalturaLog::debug("Function already ran from a different process");

This comment has been minimized.

Copy link
@MosheMaorKaltura

MosheMaorKaltura Jan 28, 2020

Contributor

Use ' + add entry ID + flavor id to the message so it will be more useful in debug

@@ -156,6 +156,7 @@ public static function handleFlavorReady(BatchJob $dbBatchJob, $flavorAssetId)

if(kReplacementHelper::shouldSyncFlavorInfo($currentFlavorAsset, $currentFlavorAsset->getentry()))
{
KalturaLog::info("Syncing flavor " . $currentFlavorAsset->getId() . " and copying content");

This comment has been minimized.

Copy link
@MosheMaorKaltura
$lock->unlock();
}

if($entry->getSyncFlavorsOnceReady())

This comment has been minimized.

Copy link
@MosheMaorKaltura

MosheMaorKaltura Jan 28, 2020

Contributor

You should get the value while you are locked. and only then unlock

@@ -709,6 +709,7 @@ public function objectChanged(BaseObject $object, array $modifiedColumns)

if(kReplacementHelper::shouldSyncFlavorInfo($object, $entry))
{
KalturaLog::info("Syncing flavor " . $object->getId());

This comment has been minimized.

Copy link
@MosheMaorKaltura
{
return true;
}
else
{
$lock = kLock::create("replacement_" . $entry->getReplacedEntryId() . "_" . $entry->getId());

This comment has been minimized.

Copy link
@MosheMaorKaltura
@@ -22,6 +22,19 @@ public static function replaceEntry(entry $replacedEntry, entry $replacingEntry
return;
}

$lock = kLock::create("replacement_" . $replacedEntry->getId() . "_" . $replacingEntry->getId());

This comment has been minimized.

Copy link
@MosheMaorKaltura
$lock = kLock::create("replacement_" . $replacedEntry->getId() . "_" . $replacingEntry->getId());
if ($lock && !$lock->lock())
{
KalturaLog::debug("Could not add a lock");

This comment has been minimized.

Copy link
@MosheMaorKaltura
$lock = kLock::create("replacement_" . $replacedEntry->getId() . "_" . $replacingEntry->getId());
if ($lock && !$lock->lock())
{
KalturaLog::debug("Could not add a lock");

This comment has been minimized.

Copy link
@MosheMaorKaltura

MosheMaorKaltura Jan 28, 2020

Contributor

The message is confusing, rephrase - could not lock + print the lock key as informative info

@inbal-ben-david inbal-ben-david merged commit 1dfa3b3 into Orion-15.16.0 Jan 28, 2020
@inbal-ben-david inbal-ben-david deleted the Orion-15.16.0-PLAT-10553 branch Jan 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.