You are here

public function ReplicaKillSwitch::trigger in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Database/ReplicaKillSwitch.php \Drupal\Core\Database\ReplicaKillSwitch::trigger()

Denies access to replica database on the current request.

See also

https://www.drupal.org/node/2286193

File

core/lib/Drupal/Core/Database/ReplicaKillSwitch.php, line 59

Class

ReplicaKillSwitch
Provides replica server kill switch to ignore it.

Namespace

Drupal\Core\Database

Code

public function trigger() {
  $connection_info = Database::getConnectionInfo();

  // Only set ignore_replica_server if there are replica servers being used,
  // which is assumed if there are more than one.
  if (count($connection_info) > 1) {

    // Five minutes is long enough to allow the replica to break and resume
    // interrupted replication without causing problems on the Drupal site
    // from the old data.
    $duration = $this->settings
      ->get('maximum_replication_lag', 300);

    // Set session variable with amount of time to delay before using replica.
    $this->session
      ->set('ignore_replica_server', $this->time
      ->getRequestTime() + $duration);
  }
}