Skip to content

Improved stampede prevention with empty config cache under high loads #3530

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

Merged
merged 11 commits into from
Dec 19, 2023
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ In a nutshell:

## Requirements

- PHP 7.4+ (PHP 8.0 is supported, PHP 8.1 supported but some warnings may be shown/logged, PHP 8.2 is usable but still being tested)
- MySQL 5.6+ (8.0+ recommended) or MariaDB
- PHP 7.4 to 8.2
- MySQL 5.7+ (8.0+ recommended) or MariaDB
- optional: Redis 5.x, 6.x and 7.0.x are supported


Expand Down
9 changes: 5 additions & 4 deletions app/code/core/Mage/Core/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,18 +502,19 @@ public function getCache()
*/
public function getCacheSaveLock($waitTime = null, $ignoreFailure = false)
{
if (! Mage::app()->useCache('config')) {
if (!Mage::app()->useCache('config')) {
return;
}
$waitTime = $waitTime ?: (PHP_SAPI === 'cli' ? 60 : 3);
$waitTime = $waitTime ?: (getenv('MAGE_CONFIG_CACHE_LOCK_WAIT') ?: (PHP_SAPI === 'cli' ? 60 : 3));
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
if (!$connection->fetchOne("SELECT GET_LOCK('core_config_cache_save_lock', ?)", [$waitTime])) {
if ($ignoreFailure) {
return;
} elseif (PHP_SAPI === 'cli') {
throw new Exception('Could not get lock on cache save operation.');
} else {
require_once Mage::getBaseDir() . DS . 'errors' . DS . '503.php';
Mage::log(sprintf('Failed to get cache save lock in %d seconds.', $waitTime), Zend_Log::NOTICE);
require Mage::getBaseDir() . DS . 'errors' . DS . '503.php';
die();
}
}
Expand All @@ -526,7 +527,7 @@ public function getCacheSaveLock($waitTime = null, $ignoreFailure = false)
*/
public function releaseCacheSaveLock()
{
if (! Mage::app()->useCache('config')) {
if (!Mage::app()->useCache('config')) {
return;
}
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
Expand Down