Skip to content

Commit

Permalink
Issue #4451: Remove all instances of master/slave terminology.
Browse files Browse the repository at this point in the history
  • Loading branch information
herbdool authored and quicksketch committed Oct 11, 2023
1 parent 3cc29b4 commit 1e95593
Show file tree
Hide file tree
Showing 36 changed files with 171 additions and 125 deletions.
3 changes: 3 additions & 0 deletions .cspell/backdrop.dic
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ Lückenbüßer
lueckenbuesser
LXSS
manytoone
marzo
maxadjustment
maxdate
menutoggle
Expand Down Expand Up @@ -338,6 +339,7 @@ nosuchindex
nosuchscheme
nosuchtable
nosuchtag
nothere
notpromoted
notpublished
nstr
Expand Down Expand Up @@ -535,6 +537,7 @@ wõrd
wordlength
wordsafe
workkeys
WQKCY
WSOD
xbeg
xchanged
Expand Down
4 changes: 2 additions & 2 deletions core/includes/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3566,12 +3566,12 @@ function language_multilingual() {
*/
function language_list($only_enabled = FALSE, $option_list = FALSE, $native_names = FALSE) {
$languages = &backdrop_static(__FUNCTION__);
// Initialize master language list.
// Initialize primary language list.
if (!isset($languages)) {
// Initialize local language list caches.
$languages = array('all' => array(), 'enabled' => array());

// Fill in master language list based on current configuration. This may be
// Fill in primary language list based on current configuration. This may be
// in the event of an early bootstrap error, so fallback to defaults.
try {
$default_langcode = config_get('system.core', 'language_default');
Expand Down
6 changes: 4 additions & 2 deletions core/includes/database/charset_converter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ class DatabaseCharsetConverter {
$success = FALSE;
foreach ($databases as $database_key => $database_values) {
foreach ($database_values as $target => $database) {
// Do not update slave databases, they will have changes replicated
// Do not update replica databases, they will have changes replicated
// to them automatically. Only update mysql/mysqli-based connections.
if ($target === 'slave' || !isset($database['driver']) || strpos($database['driver'], 'mysql') !== 0) {
$no_driver = !isset($database['driver']);
$no_mysql_driver = strpos($database['driver'], 'mysql') !== 0;
if ($target === 'replica' || $no_driver || $no_mysql_driver) {
continue;
}

Expand Down
59 changes: 41 additions & 18 deletions core/includes/database/database.inc
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ abstract class DatabaseConnection {
* 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
*/
Expand Down Expand Up @@ -352,7 +352,7 @@ abstract class DatabaseConnection {
* 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,
Expand Down Expand Up @@ -1563,8 +1563,8 @@ abstract class Database {
}
// 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';
Expand Down Expand Up @@ -1621,7 +1621,7 @@ abstract class Database {
foreach ($database_info[$index] as $target => $value) {
// 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($value['driver'])) {
$database_info[$index][$target] = $database_info[$index][$target][mt_rand(0, count($database_info[$index][$target]) - 1)];
}
Expand Down Expand Up @@ -1846,7 +1846,7 @@ abstract class Database {
/**
* 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.
*
Expand Down Expand Up @@ -2542,7 +2542,7 @@ function db_query_temporary($query, array $args = array(), array $options = arra
* A new InsertQuery object for this connection.
*/
function db_insert($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (_db_is_replica($options)) {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->insert($table, $options);
Expand All @@ -2560,7 +2560,7 @@ function db_insert($table, array $options = array()) {
* A new MergeQuery object for this connection.
*/
function db_merge($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (_db_is_replica($options)) {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->merge($table, $options);
Expand All @@ -2578,7 +2578,7 @@ function db_merge($table, array $options = array()) {
* A new UpdateQuery object for this connection.
*/
function db_update($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (_db_is_replica($options)) {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->update($table, $options);
Expand All @@ -2596,7 +2596,7 @@ function db_update($table, array $options = array()) {
* A new DeleteQuery object for this connection.
*/
function db_delete($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (_db_is_replica($options)) {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->delete($table, $options);
Expand All @@ -2614,7 +2614,7 @@ function db_delete($table, array $options = array()) {
* A new TruncateQuery object for this connection.
*/
function db_truncate($table, array $options = array()) {
if (empty($options['target']) || $options['target'] == 'slave') {
if (_db_is_replica($options)) {
$options['target'] = 'default';
}
return Database::getConnection($options['target'])->truncate($table, $options);
Expand Down Expand Up @@ -3138,18 +3138,41 @@ 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.
*/
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
// 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 Backdrop 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;
}
}

/**
* Backwards-compatible wrapper function.
*
* @deprecated since 1.20.4
*/
function db_ignore_slave() {
db_ignore_replica();
}

/**
* Check if a database has been specified as a replica.
*
* @param array $db_options
* An array of options to control how the query operates.
*
* @return bool
* TRUE if a replica, FALSE otherwise.
*/
function _db_is_replica($db_options) {
// @todo Remove deprecated terminology "slave" in Backdrop 2.0.
return empty($db_options['target']) || $db_options['target'] == 'slave' || $options['target'] == 'replica';
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"core": 0,
"display": {
"default": {
"display_title": "Master",
"display_title": "Default",
"display_plugin": "default",
"display_options": {
"query": {
Expand Down
2 changes: 1 addition & 1 deletion core/modules/contact/contact.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function contact_category_edit_form($form, &$form_state, array $category = array
// better human readability.
'#default_value' => implode("\n", explode(',', $category['recipients'])),
'#description' => t("To specify multiple recipients, separate each email address with a new line, comma, semicolon or space."),
'#placeholder' => t("webmaster@example.com\n[email protected]"),
'#placeholder' => t("admin@example.com\n[email protected]"),
'#required' => TRUE,
'#rows' => max(5, sizeof(explode(',', $category['recipients'])) + 2),
);
Expand Down
8 changes: 4 additions & 4 deletions core/modules/entity/entity.controller.inc
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ class EntityDatabaseStorageController extends DefaultEntityController implements
foreach ($entities as $id => $entity) {
$this->invokeHook('delete', $entity);
}
// Ignore slave server temporarily.
db_ignore_slave();
// Ignore replica server temporarily.
db_ignore_replica();
}
catch (Exception $e) {
$transaction->rollback();
Expand Down Expand Up @@ -776,8 +776,8 @@ class EntityDatabaseStorageController extends DefaultEntityController implements
$this->invokeHook('insert', $entity);
}

// Ignore slave server temporarily.
db_ignore_slave();
// Ignore replica server temporarily.
db_ignore_replica();
unset($entity->is_new);
unset($entity->original);

Expand Down
2 changes: 1 addition & 1 deletion core/modules/file/config/views.view.file_admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"core": "1.6",
"display": {
"default": {
"display_title": "Master",
"display_title": "Default",
"display_plugin": "default",
"display_options": {
"query": {
Expand Down
2 changes: 1 addition & 1 deletion core/modules/file/file.install
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function file_update_1000() {
'core' => '1.6',
'display' => array(
'default' => array(
'display_title' => 'Master',
'display_title' => 'Default',
'display_plugin' => 'default',
'display_options' => array(
'query' => array(
Expand Down
2 changes: 1 addition & 1 deletion core/modules/filter/config/views.view.image_library.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"core": "1.7",
"display": {
"default": {
"display_title": "Master",
"display_title": "Default",
"display_plugin": "default",
"display_options": {
"query": {
Expand Down
2 changes: 1 addition & 1 deletion core/modules/filter/filter.install
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function filter_update_1002() {
'core' => '1.7',
'display' => array(
'default' => array(
'display_title' => 'Master',
'display_title' => 'Default',
'display_plugin' => 'default',
'display_options' => array(
'query' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"core": "1.0",
"display": {
"default": {
"display_title": "Master",
"display_title": "Default",
"display_plugin": "default",
"display_options": {
"query": {
Expand Down
2 changes: 1 addition & 1 deletion core/modules/node/config/views.view.promoted.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"core": 0,
"display": {
"default": {
"display_title": "Master",
"display_title": "Default",
"display_plugin": "default",
"display_options": {
"query": {
Expand Down
8 changes: 4 additions & 4 deletions core/modules/node/node.entity.inc
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ class NodeStorageController extends EntityDatabaseStorageController {
foreach ($entities as $id => $entity) {
$this->invokeHook('delete', $entity);
}
// Ignore slave server temporarily.
db_ignore_slave();
// Ignore replica server temporarily.
db_ignore_replica();
}
catch (Exception $e) {
$transaction->rollback();
Expand Down Expand Up @@ -500,8 +500,8 @@ class NodeStorageController extends EntityDatabaseStorageController {
$this->postSave($entity, $op == 'update');
$this->invokeHook($op, $entity);

// Ignore slave server temporarily.
db_ignore_slave();
// Ignore replica server temporarily.
db_ignore_replica();
unset($entity->original);

return $return;
Expand Down
4 changes: 2 additions & 2 deletions core/modules/node/node.install
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ function node_update_1008() {
'core' => '1.0',
'display' => array(
'default' => array(
'display_title' => 'Master',
'display_title' => 'Default',
'display_plugin' => 'default',
'display_options' => array(
'query' => array(
Expand Down Expand Up @@ -1220,7 +1220,7 @@ function node_update_1018() {
array (
'default' =>
array (
'display_title' => 'Master',
'display_title' => 'Default',
'display_plugin' => 'default',
'display_options' =>
array (
Expand Down
4 changes: 2 additions & 2 deletions core/modules/node/node.module
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ function node_search_admin_validate($element, &$form_state) {
*/
function node_search_execute($keys = NULL, $conditions = NULL) {
// Build matching conditions
$query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
$query = db_select('search_index', 'i', array('target' => 'replica'))->extend('SearchQuery')->extend('PagerDefault');
$query->join('node', 'n', 'n.nid = i.sid');
$query
->condition('n.status', 1)
Expand Down Expand Up @@ -2454,7 +2454,7 @@ function node_update_index() {

// Index selected content types.
$enabled_types = _node_search_get_types();
$result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE (d.sid IS NULL OR d.reindex <> 0) AND n.type IN (:enabled_types) ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(':enabled_types' => $enabled_types), array('target' => 'slave'));
$result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE (d.sid IS NULL OR d.reindex <> 0) AND n.type IN (:enabled_types) ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(':enabled_types' => $enabled_types), array('target' => 'replica'));
$nids = $result->fetchCol();
if (!$nids) {
return;
Expand Down
6 changes: 3 additions & 3 deletions core/modules/redirect/redirect.module
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,9 @@ function redirect_save(Redirect $redirect) {
// Clear the static loading cache.
redirect_load_multiple(array(), array(), TRUE);

// Ignore slave server temporarily to give time for the
// saved redirect to be propagated to the slave.
db_ignore_slave();
// Ignore replica server temporarily to give time for the
// saved redirect to be propagated to the replica.
db_ignore_replica();
}
catch (Exception $e) {
$transaction->rollback();
Expand Down
2 changes: 1 addition & 1 deletion core/modules/search/search.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function hook_search_admin() {
*/
function hook_search_execute($keys = NULL, $conditions = NULL) {
// Build matching conditions
$query = db_select('search_index', 'i', array('target' => 'slave'))->extend('SearchQuery')->extend('PagerDefault');
$query = db_select('search_index', 'i', array('target' => 'replica'))->extend('SearchQuery')->extend('PagerDefault');
$query->join('node', 'n', 'n.nid = i.sid');
$query
->condition('n.status', 1)
Expand Down
2 changes: 1 addition & 1 deletion core/modules/search/search.extender.inc
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ class SearchQuery extends SelectQueryExtender {
$expressions = array();

// Add the sid as the only field and count them as a subquery.
$count = db_select($inner->fields('i', array('sid')), NULL, array('target' => 'slave'));
$count = db_select($inner->fields('i', array('sid')), NULL, array('target' => 'replica'));

// Add the COUNT() expression.
$count->addExpression('COUNT(*)');
Expand Down
Loading

1 comment on commit 1e95593

@backdrop-ci
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.