Skip to content
Snippets Groups Projects
Commit 92112208 authored by Drew Webber's avatar Drew Webber
Browse files

Issue #973436 by catch, joseph.olstad, beejeebus, karschsp, pillarsdotnet,...

Issue #973436 by catch, joseph.olstad, beejeebus, karschsp, pillarsdotnet, mcdruid, DamienMcKenna, carlos8f, sun, dsobon, kentr, Damien Tournoud, pounard, Fabianx, xjm, fgm, Steven Jones, David_Rothstein, donquixote, amateescu, MustangGB, Lars Toomre, basicmagic.net, Jeremy, DanPir, nnewton, yonailo, Peter Bowey, RobLoach, gdaw, dsutter, joel_osc, nareshp, izmeez, joelpittet, torgosPizza, crea, tim.plunkett, YesCT, stefan.r, rwohleb: Overzealous locking in variable_initialize()
parent e1892643
No related branches found
No related tags found
2 merge requests!7330Issue #3306390 by poker10, catch, Fabianx, pwolanin, rvtraveller: [D7]...,!1564SA-CORE-2021-001 by larowlan, stephenacrossri, siliconmeadow, mcdruid, xjm,...
...@@ -1189,19 +1189,21 @@ function variable_initialize($conf = array()) { ...@@ -1189,19 +1189,21 @@ function variable_initialize($conf = array()) {
$variables = $cached->data; $variables = $cached->data;
} }
else { else {
// Cache miss. Avoid a stampede. // Cache miss. Avoid a stampede by acquiring a lock. If the lock fails to
// acquire, optionally just continue with uncached processing.
$name = 'variable_init'; $name = 'variable_init';
if (!lock_acquire($name, 1)) { $lock_acquired = lock_acquire($name, 1);
// Another request is building the variable cache. if (!$lock_acquired && variable_get('variable_initialize_wait_for_lock', FALSE)) {
// Wait, then re-run this function.
lock_wait($name); lock_wait($name);
return variable_initialize($conf); return variable_initialize($conf);
} }
else { else {
// Proceed with variable rebuild. // Load the variables from the table.
$variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed()); $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
cache_set('variables', $variables, 'cache_bootstrap'); if ($lock_acquired) {
lock_release($name); cache_set('variables', $variables, 'cache_bootstrap');
lock_release($name);
}
} }
} }
......
...@@ -691,3 +691,13 @@ ...@@ -691,3 +691,13 @@
* @see user_user_flood_control() * @see user_user_flood_control()
*/ */
# $conf['log_user_flood_control'] = FALSE; # $conf['log_user_flood_control'] = FALSE;
/**
* Opt out of variable_initialize() locking optimization.
*
* After lengthy discussion in https://www.drupal.org/node/973436 a change was
* made in variable_initialize() in order to avoid excessive waiting under
* certain conditions. Set this variable to TRUE in order to opt out of this
* optimization and revert to the original behaviour.
*/
# $conf['variable_initialize_wait_for_lock'] = FALSE;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment