/**
  * Checks and disables the replica database server if appropriate.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The Event to process.
  */
 public function checkReplicaServer(GetResponseEvent $event)
 {
     // Ignore replica database servers for this request.
     //
     // In Drupal's distributed database structure, new data is written to the
     // master and then propagated to the replica servers.  This means there is a
     // lag between when data is written to the master and when it is available
     // on the replica. At these times, we will want to avoid using a replica server
     // temporarily. For example, if a user posts a new node then we want to
     // disable the replica server for that user temporarily to allow the replica
     // server to catch up.
     // That way, that user will see their changes immediately while for other
     // users we still get the benefits of having a replica server, just with
     // slightly stale data.  Code that wants to disable the replica server should
     // use the db_set_ignore_replica() function to set
     // $_SESSION['ignore_replica_server'] to the timestamp after which the replica
     // can be re-enabled.
     if (isset($_SESSION['ignore_replica_server'])) {
         if ($_SESSION['ignore_replica_server'] >= REQUEST_TIME) {
             Database::ignoreTarget('default', 'replica');
         } else {
             unset($_SESSION['ignore_replica_server']);
         }
     }
 }
Example #2
0
 /**
  * Tests that connections return appropriate connection objects.
  */
 function testConnectionRoutingOverride()
 {
     // Clone the primary credentials to a replica connection.
     // Note this will result in two independent connection objects that happen
     // to point to the same place.
     $connection_info = Database::getConnectionInfo('default');
     Database::addConnectionInfo('default', 'replica', $connection_info['default']);
     Database::ignoreTarget('default', 'replica');
     $db1 = Database::getConnection('default', 'default');
     $db2 = Database::getConnection('replica', 'default');
     $this->assertIdentical($db1, $db2, 'Both targets refer to the same connection.');
 }
Example #3
0
 public static function ignoreTarget($key, $target)
 {
     BaseDatabase::ignoreTarget($key, $target);
 }