Document read replication and transaction behaviour#574
Document read replication and transaction behaviour#574Rochet2 wants to merge 2 commits intosequelize:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the read replication documentation to clarify how pool selection behaves when running queries inside transactions.
Changes:
- Clarifies that transactional reads/writes default to using the write pool.
- Adjusts the existing description of how
useMasterandSELECTinteract with replication pools.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| If you want to modify these, you can pass pool as an options when instantiating Sequelize, as shown above. | ||
|
|
||
| Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. Read replica are switched using a basic round robin scheduling. | ||
| Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replica are switched using a basic round robin scheduling. |
There was a problem hiding this comment.
This new sentence is grammatically incorrect and ambiguous: "When all reads and writes when using transactions will be sent…". Consider rewriting as separate, clear sentences (e.g., "Within a transaction, all queries use the same connection. With replication enabled, transactions default to acquiring from the write pool, so SELECTs in that transaction also use the write pool."). This more directly explains why SELECT behaves differently in a transaction.
| Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replica are switched using a basic round robin scheduling. | |
| Each `write` or `useMaster: true` query will use the write pool. `SELECT` queries will use the read pool by default. Within a transaction, all queries use the same connection, so with replication enabled they are sent to the write pool by default. Read replicas are switched using a basic round robin scheduling. |
| If you want to modify these, you can pass pool as an options when instantiating Sequelize, as shown above. | ||
|
|
||
| Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. Read replica are switched using a basic round robin scheduling. | ||
| Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replica are switched using a basic round robin scheduling. |
There was a problem hiding this comment.
Correct grammar: "Read replica are" should be "Read replicas are".
| Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replica are switched using a basic round robin scheduling. | |
| Each `write` or `useMaster: true` query will use write pool. For `SELECT` read pool will be used. When all reads and writes when using transactions will be sent to the write pool by default. Read replicas are switched using a basic round robin scheduling. |
It appears that there is no documentation that I could find on read replication and how useMaster is not needed for select queries in a transaction for consistency. This PR should document the default behaviour of SELECT queries in a transaction when using read replication.
In V7 there will be a new setting for transactions to allow going to read pool only.
It could also be mentioned here maybe?
I also wonder (have not tested) what happens if one explicitly sets useMaster true/false inside a transaction.
Maybe something to document as well.