Skip to content

Commit

Permalink
Improved stampede prevention with empty config cache under high loads (
Browse files Browse the repository at this point in the history
…#3530)

Co-authored-by: Fabrizio Balliano <[email protected]>
Co-authored-by: Milan Davídek <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2023
1 parent 0e79abc commit e5ddf69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
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

0 comments on commit e5ddf69

Please sign in to comment.