Skip to content

Commit e5ddf69

Browse files
colinmollenhourfballianomidlan
authored
Improved stampede prevention with empty config cache under high loads (#3530)
Co-authored-by: Fabrizio Balliano <[email protected]> Co-authored-by: Milan Davídek <[email protected]>
1 parent 0e79abc commit e5ddf69

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ In a nutshell:
6868

6969
## Requirements
7070

71-
- 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)
72-
- MySQL 5.6+ (8.0+ recommended) or MariaDB
71+
- PHP 7.4 to 8.2
72+
- MySQL 5.7+ (8.0+ recommended) or MariaDB
7373
- optional: Redis 5.x, 6.x and 7.0.x are supported
7474

7575

app/code/core/Mage/Core/Model/Config.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -502,18 +502,19 @@ public function getCache()
502502
*/
503503
public function getCacheSaveLock($waitTime = null, $ignoreFailure = false)
504504
{
505-
if (! Mage::app()->useCache('config')) {
505+
if (!Mage::app()->useCache('config')) {
506506
return;
507507
}
508-
$waitTime = $waitTime ?: (PHP_SAPI === 'cli' ? 60 : 3);
508+
$waitTime = $waitTime ?: (getenv('MAGE_CONFIG_CACHE_LOCK_WAIT') ?: (PHP_SAPI === 'cli' ? 60 : 3));
509509
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
510510
if (!$connection->fetchOne("SELECT GET_LOCK('core_config_cache_save_lock', ?)", [$waitTime])) {
511511
if ($ignoreFailure) {
512512
return;
513513
} elseif (PHP_SAPI === 'cli') {
514514
throw new Exception('Could not get lock on cache save operation.');
515515
} else {
516-
require_once Mage::getBaseDir() . DS . 'errors' . DS . '503.php';
516+
Mage::log(sprintf('Failed to get cache save lock in %d seconds.', $waitTime), Zend_Log::NOTICE);
517+
require Mage::getBaseDir() . DS . 'errors' . DS . '503.php';
517518
die();
518519
}
519520
}
@@ -526,7 +527,7 @@ public function getCacheSaveLock($waitTime = null, $ignoreFailure = false)
526527
*/
527528
public function releaseCacheSaveLock()
528529
{
529-
if (! Mage::app()->useCache('config')) {
530+
if (!Mage::app()->useCache('config')) {
530531
return;
531532
}
532533
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');

0 commit comments

Comments
 (0)