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
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -1189,21 +1189,23 @@ function variable_initialize($conf = array()) {
    $variables = $cached->data;
  }
  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';
    if (!lock_acquire($name, 1)) {
      // Another request is building the variable cache.
      // Wait, then re-run this function.
    $lock_acquired = lock_acquire($name, 1);
    if (!$lock_acquired && variable_get('variable_initialize_wait_for_lock', FALSE)) {
      lock_wait($name);
      return variable_initialize($conf);
    }
    else {
      // Proceed with variable rebuild.
      // Load the variables from the table.
      $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
      if ($lock_acquired) {
        cache_set('variables', $variables, 'cache_bootstrap');
        lock_release($name);
      }
    }
  }

  foreach ($conf as $name => $value) {
    $variables[$name] = $value;
+10 −0
Original line number Diff line number Diff line
@@ -691,3 +691,13 @@
 * @see user_user_flood_control()
 */
# $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;