-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC DB read-only replicas #587
base: 6
Are you sure you want to change the base?
Conversation
114703d
to
8ff5036
Compare
07d3b24
to
3e95db2
Compare
en/02_Developer_Guides/08_Performance/07_DB_read_only_replicas.md
Outdated
Show resolved
Hide resolved
en/02_Developer_Guides/08_Performance/07_DB_read_only_replicas.md
Outdated
Show resolved
Hide resolved
en/02_Developer_Guides/08_Performance/07_DB_read_only_replicas.md
Outdated
Show resolved
Hide resolved
en/02_Developer_Guides/08_Performance/07_DB_read_only_replicas.md
Outdated
Show resolved
Hide resolved
If one or more read-only replicas have been configured, then one of the read-only replicas will be selected from the pool of available replicas to handle queries for the rest of the request cycle. However the primary database will be used instead if one of the follow criteria has been met: | ||
|
||
- The current query includes any mutable SQL such as `INSERT` or `DELETE`. The primary database will be used for the current query, as well as any future queries, including read queries, for the rest of the current request cycle. Mutable SQL is defined on [`DBConnector::isQueryMutable()`](api:SilverStripe\ORM\Connect\DBConnector::isQueryMutable()). | ||
- The HTTP request that matched a rule defined in [`Director.must_use_primary_db_rules`](api:SilverStripe\Control\Director->must_use_primary_db_rules). By default the URL paths `Security`, `dev`, and `admin` (if `silverstripe/admin` is installed) are covered by this by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The HTTP request that matched a rule defined in [`Director.must_use_primary_db_rules`](api:SilverStripe\Control\Director->must_use_primary_db_rules). By default the URL paths `Security`, `dev`, and `admin` (if `silverstripe/admin` is installed) are covered by this by default. | |
- The HTTP request matches a routing rule defined in [`Director.must_use_primary_db_rules`](api:SilverStripe\Control\Director->must_use_primary_db_rules). By default the URL paths `Security/*`, `dev/*`, and `admin/*` (if `silverstripe/admin` is installed) are covered by this by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to add the /*
so it's clear it's any path starting with those - i.e. dev/build
is included, not just dev
on its own.
en/02_Developer_Guides/08_Performance/07_DB_read_only_replicas.md
Outdated
Show resolved
Hide resolved
en/02_Developer_Guides/08_Performance/07_DB_read_only_replicas.md
Outdated
Show resolved
Hide resolved
en/02_Developer_Guides/08_Performance/07_DB_read_only_replicas.md
Outdated
Show resolved
Hide resolved
en/02_Developer_Guides/08_Performance/07_DB_read_only_replicas.md
Outdated
Show resolved
Hide resolved
45647f1
to
adb66c3
Compare
en/08_Changelogs/5.4.0.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per silverstripe/silverstripe-framework#11379 (comment) $dataQuery->execute()
now works a little differently to $dataQuery->query()->execute()
- that needs to be called out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to explicitly point out that DB::get_conn()
will give you a replica by default if you have one configured, unless you explicitly pass in DB::CONN_PRIMARY
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re the first point, it's a pretty nuanced detail which is already mentioned in the docs, though not the changelog (which does refer to the docs for more detail)
Note that the withCorrectDatabase()
call which $dataQuery->execute()
makes which $dataQuery->query()->execute()
doesn't simply means it respects DataObject.must_use_primary_db
config
From docs:
For any query that goes through a call to DataQuery::execute()
, the DataObject
subclass being queried is configured with DataObject.must_use_primary_db
set to true
. This includes most commonly used ORM methods such as DataObject::get()
, and excludes SQLSelect
methods. By default all core security related DataObject
subclasses have must_use_primary_db
set to true
.
A number of DataQuery methods now use withCorrectDatabase()
e.g. DataQuery::count()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re the first point, it's a pretty nuanced detail which is already mentioned in the docs, though not the changelog (which does refer to the docs for more detail)
I think it should be explicitly called out in the changelog, since it's a change in behaviour that some people may need to update their code to account for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
If one or more read-only replicas have been configured, then one of the read-only replicas will be selected from the pool of available replicas to handle queries for the rest of the request cycle. However the primary database will be used instead if one of the follow criteria has been met: | ||
|
||
- The current query includes any mutable SQL such as `INSERT` or `DELETE`. The primary database will be used for the current query, as well as any future queries, including read queries, for the rest of the current request cycle. Mutable SQL is defined on [`DBConnector::isQueryMutable()`](api:SilverStripe\ORM\Connect\DBConnector::isQueryMutable()). | ||
- The HTTP request that matched a rule defined in [`Director.must_use_primary_db_rules`](api:SilverStripe\Control\Director->must_use_primary_db_rules). By default the URL paths `Security`, `dev`, and `admin` (if `silverstripe/admin` is installed) are covered by this by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to add the /*
so it's clear it's any path starting with those - i.e. dev/build
is included, not just dev
on its own.
en/02_Developer_Guides/08_Performance/07_Read_only_database_replicas.md
Outdated
Show resolved
Hide resolved
adb66c3
to
9930e9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- DOC DB read-only replicas #587 (comment) still needs to be done
- Added comment to DOC DB read-only replicas #587 (comment) (sorry, forgot to start review)
e98eeb8
to
b286048
Compare
b286048
to
f712ebe
Compare
f712ebe
to
419afa1
Compare
Issue silverstripe/silverstripe-framework#11352