Commit b1b3b2b8 authored by webchick's avatar webchick
Browse files

Issue #2275877 by Mixologic, duellj, Les Lim, Xano, David Strauss: Replace...

Issue #2275877 by Mixologic, duellj, Les Lim, Xano, David Strauss: Replace master/slave terminology with primary/replica.
parent 7fdb267c
......@@ -134,8 +134,8 @@ Drupal 7.0, 2011-01-05
* Fully rewritten database layer utilizing PHP 5's PDO abstraction layer.
* Drupal now requires MySQL >= 5.0.15 or PostgreSQL >= 8.3.
* Added query builders for INSERT, UPDATE, DELETE, MERGE, and SELECT queries.
* Support for master/slave replication, transactions, multi-insert queries,
and other features.
* Support for primary/replica replication, transactions, multi-insert
queries, and other features.
* Added support for the SQLite database engine.
* Default to InnoDB engine, rather than MyISAM, on MySQL when available.
This offers increased scalability and data integrity.
......
......@@ -308,11 +308,11 @@ services:
- [initLanguageManager]
tags:
- { name: service_collector, tag: string_translator, call: addTranslator }
database.slave:
database.replica:
class: Drupal\Core\Database\Connection
factory_class: Drupal\Core\Database\Database
factory_method: getConnection
arguments: [slave]
arguments: [replica]
typed_data_manager:
class: Drupal\Core\TypedData\TypedDataManager
parent: default_plugin_manager
......@@ -707,8 +707,8 @@ services:
batch.storage:
class: Drupal\Core\Batch\BatchStorage
arguments: ['@database']
slave_database_ignore__subscriber:
class: Drupal\Core\EventSubscriber\SlaveDatabaseIgnoreSubscriber
replica_database_ignore__subscriber:
class: Drupal\Core\EventSubscriber\ReplicaDatabaseIgnoreSubscriber
tags:
- {name: event_subscriber}
country_manager:
......
......@@ -296,7 +296,7 @@ function db_query_temporary($query, array $args = array(), array $options = arra
* A new Insert object for this connection.
*/
function db_insert($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->insert($table, $options);
......@@ -314,7 +314,7 @@ function db_insert($table, array $options = array()) {
* A new Merge object for this connection.
*/
function db_merge($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->merge($table, $options);
......@@ -332,7 +332,7 @@ function db_merge($table, array $options = array()) {
* A new Update object for this connection.
*/
function db_update($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->update($table, $options);
......@@ -350,7 +350,7 @@ function db_update($table, array $options = array()) {
* A new Delete object for this connection.
*/
function db_delete($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->delete($table, $options);
......@@ -368,7 +368,7 @@ function db_delete($table, array $options = array()) {
* A new Truncate object for this connection.
*/
function db_truncate($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (empty($options['target']) || $options['target'] == 'replica') {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->truncate($table, $options);
......@@ -924,18 +924,21 @@ function db_change_field($table, $field, $field_new, $spec, $keys_new = array())
*/
/**
* Sets a session variable specifying the lag time for ignoring a slave server.
* Sets a session variable specifying the lag time for ignoring a replica
* server (A replica server is traditionally referred to as
* a "slave" in database server documentation).
* @see http://drupal.org/node/2275877
*/
function db_ignore_slave() {
function db_ignore_replica() {
$connection_info = Database::getConnectionInfo();
// Only set ignore_slave_server if there are slave servers being used, which
// is assumed if there are more than one.
// 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 slave to break and resume
// 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 = Settings::get('maximum_replication_lag', 300);
// Set session variable with amount of time to delay before using slave.
$_SESSION['ignore_slave_server'] = REQUEST_TIME + $duration;
// Set session variable with amount of time to delay before using replica.
$_SESSION['ignore_replica_server'] = REQUEST_TIME + $duration;
}
}
......@@ -219,7 +219,7 @@ protected static function schemaDefinition() {
*
* @throws PDOException
*
* @todo Ignore slave targets for data manipulation operations.
* @todo Ignore replica targets for data manipulation operations.
*/
public function delete($name) {
$options = array('return' => Database::RETURN_AFFECTED) + $this->options;
......
......@@ -35,8 +35,8 @@ abstract class Connection implements \Serializable {
* The key representing this connection.
*
* The key is a unique string which identifies a database connection. A
* connection can be a single server or a cluster of master and slaves (use
* target to pick between master and slave).
* connection can be a single server or a cluster of primary and replicas
* (use target to pick between primary and replica).
*
* @var string
*/
......@@ -188,7 +188,7 @@ public function destroy() {
* A given query can be customized with a number of option flags in an
* associative array:
* - target: The database "target" against which to execute a query. Valid
* values are "default" or "slave". The system will first try to open a
* values are "default" or "replica". The system will first try to open a
* connection to a database specified with the user-supplied key. If one
* is not available, it will silently fall back to the "default" target.
* If multiple databases connections are specified with the same target,
......
......@@ -159,8 +159,8 @@ final public static function getConnection($target = 'default', $key = NULL) {
}
// If the requested target does not exist, or if it is ignored, we fall back
// to the default target. The target is typically either "default" or
// "slave", indicating to use a slave SQL server if one is available. If
// it's not available, then the default/master server is the correct server
// "replica", indicating to use a replica SQL server if one is available. If
// it's not available, then the default/primary server is the correct server
// to use.
if (!empty(self::$ignoreTargets[$key][$target]) || !isset(self::$databaseInfo[$key][$target])) {
$target = 'default';
......@@ -212,7 +212,7 @@ final public static function setActiveConnection($key = 'default') {
final public static function parseConnectionInfo(array $info) {
// If there is no "driver" property, then we assume it's an array of
// possible connections for this target. Pick one at random. That allows
// us to have, for example, multiple slave servers.
// us to have, for example, multiple replica servers.
if (empty($info['driver'])) {
$info = $info[mt_rand(0, count($info) - 1)];
}
......@@ -431,7 +431,7 @@ public static function closeConnection($target = NULL, $key = NULL) {
/**
* Instructs the system to temporarily ignore a given key/target.
*
* At times we need to temporarily disable slave queries. To do so, call this
* At times we need to temporarily disable replica queries. To do so, call this
* method with the database key and the target to disable. That database key
* will then always fall back to 'default' for that key, even if it's defined.
*
......
......@@ -611,8 +611,8 @@ public function delete(array $entities) {
try {
parent::delete($entities);
// Ignore slave server temporarily.
db_ignore_slave();
// Ignore replica server temporarily.
db_ignore_replica();
}
catch (\Exception $e) {
$transaction->rollback();
......@@ -669,8 +669,8 @@ public function save(EntityInterface $entity) {
$return = parent::save($entity);
// Ignore slave server temporarily.
db_ignore_slave();
// Ignore replica server temporarily.
db_ignore_replica();
return $return;
}
catch (\Exception $e) {
......
......@@ -135,8 +135,8 @@ public function delete(array $entities) {
try {
parent::delete($entities);
// Ignore slave server temporarily.
db_ignore_slave();
// Ignore replica server temporarily.
db_ignore_replica();
}
catch (\Exception $e) {
$transaction->rollback();
......@@ -167,8 +167,8 @@ public function save(EntityInterface $entity) {
try {
$return = parent::save($entity);
// Ignore slave server temporarily.
db_ignore_slave();
// Ignore replica server temporarily.
db_ignore_replica();
return $return;
}
catch (\Exception $e) {
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\Core\EventSubscriber\SlaveDatabaseIgnoreSubscriber.
* Contains \Drupal\Core\EventSubscriber\ReplicaDatabaseIgnoreSubscriber.
*/
namespace Drupal\Core\EventSubscriber;
......@@ -15,36 +15,36 @@
/**
* System subscriber for controller requests.
*/
class SlaveDatabaseIgnoreSubscriber implements EventSubscriberInterface {
class ReplicaDatabaseIgnoreSubscriber implements EventSubscriberInterface {
/**
* Checks and disables the slave database server if appropriate.
* Checks and disables the replica database server if appropriate.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The Event to process.
*/
public function checkSlaveServer(GetResponseEvent $event) {
// Ignore slave database servers for this request.
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 slave servers. This means there is a
// 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 slave. At these times, we will want to avoid using a slave server
// 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 slave server for that user temporarily to allow the slave
// 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 slave server, just with
// slightly stale data. Code that wants to disable the slave server should
// use the db_set_ignore_slave() function to set
// $_SESSION['ignore_slave_server'] to the timestamp after which the slave
// 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_slave_server'])) {
if ($_SESSION['ignore_slave_server'] >= REQUEST_TIME) {
Database::ignoreTarget('default', 'slave');
if (isset($_SESSION['ignore_replica_server'])) {
if ($_SESSION['ignore_replica_server'] >= REQUEST_TIME) {
Database::ignoreTarget('default', 'replica');
}
else {
unset($_SESSION['ignore_slave_server']);
unset($_SESSION['ignore_replica_server']);
}
}
}
......@@ -53,7 +53,7 @@ public function checkSlaveServer(GetResponseEvent $event) {
* {@inheritdoc}
*/
static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = array('checkSlaveServer');
$events[KernelEvents::REQUEST][] = array('checkReplicaServer');
return $events;
}
......
......@@ -23,7 +23,7 @@ display:
options:
disable_sql_rewrite: false
distinct: false
slave: false
replica: false
query_comment: false
query_tags: { }
provider: views
......
......@@ -29,7 +29,7 @@ display:
options:
disable_sql_rewrite: false
distinct: false
slave: false
replica: false
query_comment: false
query_tags: { }
exposed_form:
......
......@@ -20,7 +20,7 @@ display:
options:
disable_sql_rewrite: false
distinct: false
slave: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
......
......@@ -24,7 +24,7 @@ display:
options:
disable_sql_rewrite: false
distinct: false
slave: false
replica: false
query_comment: false
query_tags: { }
provider: views
......
......@@ -95,8 +95,8 @@ public function save(EntityInterface $entity) {
}
}
// Ignore slave server temporarily.
db_ignore_slave();
// Ignore replica server temporarily.
db_ignore_replica();
unset($entity->original);
return $return;
......
......@@ -16,7 +16,7 @@ display:
query_comment: false
disable_sql_rewrite: false
distinct: false
slave: false
replica: false
query_tags: { }
provider: views
title: 'Monthly archive'
......
......@@ -24,7 +24,7 @@ display:
options:
disable_sql_rewrite: false
distinct: false
slave: false
replica: false
query_comment: false
query_tags: { }
provider: views
......
......@@ -137,7 +137,7 @@ display:
options:
disable_sql_rewrite: false
distinct: false
slave: false
replica: false
query_comment: false
query_tags: { }
provider: views
......
......@@ -16,7 +16,7 @@ display:
query_comment: false
disable_sql_rewrite: false
distinct: false
slave: false
replica: false
query_tags: { }
provider: views
use_ajax: true
......
......@@ -182,7 +182,7 @@ public function execute() {
// Build matching conditions.
$query = $this->database
->select('search_index', 'i', array('target' => 'slave'))
->select('search_index', 'i', array('target' => 'replica'))
->extend('Drupal\search\SearchQuery')
->extend('Drupal\Core\Database\Query\PagerSelectExtender');
$query->join('node_field_data', 'n', 'n.nid = i.sid');
......@@ -325,7 +325,7 @@ public function updateIndex() {
// per cron run.
$limit = (int) $this->searchSettings->get('index.cron_limit');
$result = $this->database->queryRange("SELECT n.nid, MAX(sd.reindex) FROM {node} n LEFT JOIN {search_dataset} sd ON sd.sid = n.nid AND sd.type = :type WHERE sd.sid IS NULL OR sd.reindex <> 0 GROUP BY n.nid ORDER BY MAX(sd.reindex) is null DESC, MAX(sd.reindex) ASC, n.nid ASC", 0, $limit, array(':type' => $this->getPluginId()), array('target' => 'slave'));
$result = $this->database->queryRange("SELECT n.nid, MAX(sd.reindex) FROM {node} n LEFT JOIN {search_dataset} sd ON sd.sid = n.nid AND sd.type = :type WHERE sd.sid IS NULL OR sd.reindex <> 0 GROUP BY n.nid ORDER BY MAX(sd.reindex) is null DESC, MAX(sd.reindex) ASC, n.nid ASC", 0, $limit, array(':type' => $this->getPluginId()), array('target' => 'replica'));
$nids = $result->fetchCol();
if (!$nids) {
return;
......
......@@ -39,7 +39,7 @@ display:
options:
disable_sql_rewrite: false
distinct: false
slave: false
replica: false
query_comment: ''
query_tags: { }
row:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment