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
Comments
Comment #1
ericduran commentedAgreed here, This is a badly name function. I also updated the docs to make a bit more sense.
Comment #2
Crell commentedIf 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.
Comment #3
catch@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.
Comment #4
Crell commentedWell 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?)
Comment #8
mile23db_ignore_replica()is still the only function indatabase.incthat's not deprecated.Comment #11
andypostHere 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.
Comment #12
andypostbetter title
Comment #14
andypostproper namespace
Comment #16
andypostFailed test shows that
session->isStarted()is not neededComment #17
andypostFix typo
Comment #18
andypostneeds CR link
Comment #19
andypostIn #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
Comment #20
alexpottprivate? I think we don'y need to do that.
Comment #21
andypost@alexpott thanks, good catch!
Comment #22
alexpotttbd. 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.
Comment #23
mile23Comment #25
andypostComment #26
volegerAdded CR draft https://www.drupal.org/node/2997500
Also
Need to be updated to the 8.7.x
The same thing here
Comment #27
andypostReroll + fix of links (CR & naming should point to CR of slavery)
Now it needs a legacy test & update issue summary
Comment #29
alexpottIt'd be great if someone addressed the last part of #22 ie.
Comment #30
andypost@alexpott nice idea, guess you mean kind of it
If that fine then it needs legacy test, CR and approval
Comment #31
alexpott@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
Comment #32
volegerUpdated CR https://www.drupal.org/node/2997500
Comment #33
volegerComment #34
volegerStill, the legacy test needed.
Comment #35
andypostFixed CR & summary, digging legacy test
Comment #36
andypostLind of that test covers main functionality
Comment #37
andypostExtended test to test session value
Comment #39
longwaveRerolled
Comment #40
volegerLooks good
Comment #42
catchThis 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.
Comment #43
andypostReworded and fixed lines longer 80chars
PS: no idea how to move credits from #2486549: ReplicaDatabaseIgnoreSubscriber mentions non-existent function
Comment #44
longwaveDocs update looks fine so back to RTBC.
Comment #45
alexpottUnfortunately needs a reroll.
Comment #46
longwaveStraight reroll, at least the database.replica service is next to the kill switch in core.services.yml now.
Comment #47
andypostrtbc is back
Comment #48
alexpottCommitted 788437c and pushed to 8.7.x. Thanks!
Fixed unused use on commit.
Comment #50
andypostCR published