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

Add multiple retry on the mutex acquire if acquire fail. #45

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion data-sources/datasource.remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -851,13 +851,15 @@ public function execute(array &$param_pool = null)
$writeToCache = null;
$isCacheValid = true;
$creation = DateTimeObj::get('c');
$mutexRetrySleepTime = 1; //in secondes
$mutexRetryCount = 50;

// Execute if the cache doesn't exist, or if it is old.
if (
(!is_array($cachedData) || empty($cachedData)) // There's no cache.
|| (time() - $cachedData['creation']) > ($this->dsParamCACHE * 60) // The cache is old.
) {
if (Mutex::acquire($cache_id, $this->dsParamTIMEOUT, TMP)) {
if (Mutex::acquireOrWait($cache_id, $this->dsParamTIMEOUT, TMP, $mutexRetryCount, $mutexRetrySleepTime)) {
list($data, $info) = self::fetch($this->dsParamURL, $this->dsParamFORMAT, $this->dsParamTIMEOUT);
Mutex::release($cache_id, TMP);
$writeToCache = true;
Expand Down Expand Up @@ -924,6 +926,7 @@ public function execute(array &$param_pool = null)
$result->appendChild(
new XMLElement('error', __('The %s class failed to acquire a lock.', array('<code>Mutex</code>')))
);
Symphony::log()->pushToLog(__('The %s class failed to acquire a mutex lock after %s retry.', array('<code>datasource.remote</code>', $mutexRetryCount)), E_ERROR, true);
}

// The cache is good, use it!
Expand Down