feat(devmanual): DB clusters and read/write split#11492
Merged
ChristophWurst merged 1 commit intomasterfrom Feb 2, 2024
Merged
feat(devmanual): DB clusters and read/write split#11492ChristophWurst merged 1 commit intomasterfrom
ChristophWurst merged 1 commit intomasterfrom
Conversation
2 tasks
juliusknorr
approved these changes
Feb 2, 2024
Member
juliusknorr
left a comment
There was a problem hiding this comment.
Nice writeup 💪
Two small comments inline, but looks good in general
| 2. **Avoid the read operation**. If the code allows it, avoid the read operation all together. You should know what was just written. If you need the auto increment ID, use the database's *last insert ID* feature. Proceed with this data, pass it to event listeners, etc. This approach guarantees consistency, too, but also improves overall performance. | ||
|
|
||
| .. note:: | ||
| Nextcloud can help you identify read after write without the need to set up a cluster for your development environment. If you change the loglevel to 0 (debug), dirty reads will trigger a log entry. Monitor the log when testing your code. |
Member
There was a problem hiding this comment.
Maybe add a comment that the log is based on the table so there might be e false positives
|
|
||
| There are two patterns to avoid the "dirty" read: | ||
|
|
||
| 1. **Wrap the write+read operation in a transaction**. Nextcloud's read/write split, but also other database cluster load balancers will ensure that the queries of a transactions go to one single database node of a cluster. That ensures that data written is instantly available to be read back. This approach guarantees consistency, but puts additional load on the primary node because it has to execute the read operation. |
Member
There was a problem hiding this comment.
Should we mention that depending on where the queries happen this might not be an option, as usually you'd want to keep the transaction time as low as possible?
juliusknorr
approved these changes
Feb 2, 2024
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
90e8900 to
d47461a
Compare
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
☑️ Resolves
🖼️ Screenshots
Resolves nextcloud/server#33542