Problem/Motivation

Following #2275877: Replace "master/slave" terminology with "primary/replica" i realized that db_ignore_slave/replica() isn't particularly descriptive.

What that function does is ensure that subsequent queries for the current user session (for a period of time) go to the primary database, not the replica.

Proposed resolution

We always have a primary database, we don't always have a replica.
Introduce service that will make next request always use primary database.

Remaining tasks

Agree on naming & commit

User interface changes

No

API changes

- Deprecate db_ignore_replica()
- Add database.replica_kill_switch service with trigger() method to ensure that replica database will not be used in subsequent request

Data model changes

No

CommentFileSizeAuthor
#46 2286235-46.patch16.42 KBlongwave
#43 2286235-replica-43.patch16.42 KBandypost
#43 interdiff.txt1.98 KBandypost
#39 2286235-39.patch16.39 KBlongwave
#37 2286235-replica-37.patch16.39 KBandypost
#37 interdiff.txt1.14 KBandypost
#36 2286235-replica-36.patch15.9 KBandypost
#36 interdiff.txt2.19 KBandypost
#30 2286235-replica-30.patch14.72 KBandypost
#30 interdiff.txt9.02 KBandypost
#27 2286235-27.patch11.53 KBandypost
#27 interdiff.txt1.78 KBandypost
#21 2286235-replica-21.patch11.42 KBandypost
#21 2286235-interdiff-17.txt623 bytesandypost
#17 2286235-replica-17.patch11.42 KBandypost
#17 2286235-interdiff-16.txt1.22 KBandypost
#16 2286235-replica-16.patch11.42 KBandypost
#16 2286235-interdiff-14.txt903 bytesandypost
#14 2286235-replica-14.patch11.45 KBandypost
#14 2286235-interdiff-11.txt1.12 KBandypost
#11 2286235-replica-11.patch11.27 KBandypost
#1 2286235-1-db_ignore_replica.patch3.83 KBericduran
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ericduran’s picture

Status: Active » Needs review
FileSize
3.83 KB

Agreed here, This is a badly name function. I also updated the docs to make a bit more sense.

Crell’s picture

Status: Needs review » Needs work

If we're going to mess with the function name, let's just eliminate it entirely and move that functionality to \Database. It's just about the only function in database.inc that isn't entirely vestigial at this point; let's get rid of it.

catch’s picture

@Crell are you sure this should go in \Database - it has a dependency on both Settings and session, and doesn't interact with the database at all.

Crell’s picture

Well it should come out of a floating function. I'm not sure where else to put it. I checked and you're right; the Database class has only ignoreTarget(), which is set per-request from an event listener. I'm not sure what a proper OOP location for it would be other than another service (which maybe then subsumes the event listener, too?)

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

db_ignore_replica() is still the only function in database.inc that's not deprecated.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Title: Change db_ignore_replica() to refer to the primary/default target » Deprecate db_ignore_replica()
Version: 8.5.x-dev » 8.6.x-dev
Status: Needs work » Needs review
Issue tags: +KharkivGSW18
FileSize
11.27 KB

Here is a service implementation

Thinking a bit more about ... I think this could store this value inside protected variable instead of session but looks no way cos we need this value in next request for the same user.

andypost’s picture

Title: Deprecate db_ignore_replica() » Deprecate db_ignore_replica() and convert it to service

better title

Status: Needs review » Needs work

The last submitted patch, 11: 2286235-replica-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

andypost’s picture

Status: Needs work » Needs review
FileSize
1.12 KB
11.45 KB

proper namespace

Status: Needs review » Needs work

The last submitted patch, 14: 2286235-replica-14.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

andypost’s picture

Status: Needs work » Needs review
FileSize
903 bytes
11.42 KB

Failed test shows that session->isStarted() is not needed

andypost’s picture

FileSize
1.22 KB
11.42 KB

Fix typo

andypost’s picture

+++ b/core/includes/database.inc
@@ -1032,18 +1032,13 @@ function db_change_field($table, $field, $field_new, $spec, $keys_new = []) {
+  @trigger_error('db_ignore_replica() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\ReplicaKillSwitch::trigger(). See tbd.', E_USER_DEPRECATED);

needs CR link

andypost’s picture

In #2848820-16: Replace all calls to db_transaction, which is deprecated it becomes clear that starting transaction & ignoring replicate server for next request (session used) while menu link manager rebuilds, looks it needs to research other places

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php
@@ -26,6 +27,13 @@ class MenuRouterRebuildSubscriber implements EventSubscriberInterface {
+  private $replicaKillSwitch;

private? I think we don'y need to do that.

andypost’s picture

Status: Needs work » Needs review
FileSize
623 bytes
11.42 KB

@alexpott thanks, good catch!

alexpott’s picture

Status: Needs review » Needs work
+++ b/core/includes/database.inc
@@ -1033,18 +1033,13 @@ function db_change_field($table, $field, $field_new, $spec, $keys_new = []) {
+  @trigger_error('db_ignore_replica() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\ReplicaKillSwitch::trigger(). See tbd.', E_USER_DEPRECATED);

tbd. Needs a change record.

Sometimes I wonder about whether everything should be a service. I'm not sure. db_ignore_replica() is the only non deprecated function in database.inc - which is kinda amazing and it would be good to move somewhere.

One thing that would be nice is to make the same service listen to the event and set the session. This keeps on the logic in the same place. I think I'd remove the ReplicaDatabaseIgnoreSubscriber and make the new service subscriber to the same event. That way in terms of numbers services this change is a wash.

Mile23’s picture

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

voleger’s picture

Added CR draft https://www.drupal.org/node/2997500
Also

  1. +++ b/core/includes/database.inc
    @@ -1033,18 +1033,13 @@ function db_change_field($table, $field, $field_new, $spec, $keys_new = []) {
    + * @deprecated as of Drupal 8.6.x, will be removed in Drupal 9.0.0. Use
    ...
     function db_ignore_replica() {
    

    Need to be updated to the 8.7.x

  2. +++ b/core/includes/database.inc
    @@ -1033,18 +1033,13 @@ function db_change_field($table, $field, $field_new, $spec, $keys_new = []) {
    +  @trigger_error('db_ignore_replica() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\ReplicaKillSwitch::trigger(). See tbd.', E_USER_DEPRECATED);
    

    The same thing here

andypost’s picture

Reroll + fix of links (CR & naming should point to CR of slavery)
Now it needs a legacy test & update issue summary

Status: Needs review » Needs work

The last submitted patch, 27: 2286235-27.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

alexpott’s picture

It'd be great if someone addressed the last part of #22 ie.

One thing that would be nice is to make the same service listen to the event and set the session. This keeps on the logic in the same place. I think I'd remove the ReplicaDatabaseIgnoreSubscriber and make the new service subscriber to the same event. That way in terms of numbers services this change is a wash.

andypost’s picture

@alexpott nice idea, guess you mean kind of it

If that fine then it needs legacy test, CR and approval

alexpott’s picture

Issue tags: +Needs change record

@andypost yep that looks great. Now we got all the database replica ignoring stuff in the same place. Thanks! Yep a change record would be good. Fortunately event listeners are not API but the deprecation of db_ignore_replica and the new service need one - there's one already so lets make sure it is accurate and there is no harm in mentioning that the old event listener has been removed. +1 for a legacy test

voleger’s picture

voleger’s picture

Issue tags: -Needs change record
voleger’s picture

Issue tags: +Need tests

Still, the legacy test needed.

andypost’s picture

Fixed CR & summary, digging legacy test

andypost’s picture

Lind of that test covers main functionality

Status: Needs review » Needs work

The last submitted patch, 37: 2286235-replica-37.patch, failed testing. View results

longwave’s picture

voleger’s picture

Status: Needs review » Reviewed & tested by the community

Looks good

The last submitted patch, 21: 2286235-replica-21.patch, failed testing. View results

catch’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Database/ReplicaKillSwitch.php
@@ -0,0 +1,113 @@
+    // use the db_set_ignore_replica() function to set

This has been copied from the old docs, but it mentions a function that doesn't exist. We should incorporate the patch and issue credits from #2486549: ReplicaDatabaseIgnoreSubscriber mentions non-existent function here I think.

andypost’s picture

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Docs update looks fine so back to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Unfortunately needs a reroll.

longwave’s picture

Straight reroll, at least the database.replica service is next to the kill switch in core.services.yml now.

andypost’s picture

Status: Needs review » Reviewed & tested by the community

rtbc is back

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 788437c and pushed to 8.7.x. Thanks!

diff --git a/core/includes/database.inc b/core/includes/database.inc
index bd19a95c1e..e5927fa65b 100644
--- a/core/includes/database.inc
+++ b/core/includes/database.inc
@@ -11,7 +11,6 @@
 
 use Drupal\Core\Database\Database;
 use Drupal\Core\Database\Query\Condition;
-use Drupal\Core\Site\Settings;
 
 /**
  * @addtogroup database

Fixed unused use on commit.

  • alexpott committed 788437c on 8.7.x
    Issue #2286235 by andypost, longwave, ericduran, alexpott, voleger,...
andypost’s picture

CR published

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.