Skip to content
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

feat: Track dirty table writes and long transactions #42345

Merged
merged 2 commits into from
Jan 12, 2024

Conversation

juliushaertl
Copy link
Member

@juliushaertl juliushaertl commented Dec 18, 2023

  • feat: First attempt to track dirty tables after writes and switch back to replicas if reads go to other tables
  • feat: Add logging for transaction time

Summary

The main benefit of this approach is that we can switch back to read replicas for queries that are not towards dirty tables (that were written before), which makes #41998 more performant as less reads go to the primary. In addition the logging can be used to more easily track down read after write by using the debug log.

In addition logging long transactions can be a good indicator for code paths that might need rework to avoid long locks or could cause potential deadlock scenarios.

@juliushaertl juliushaertl changed the title enh/read replica followup feat: Track dirty table writes and long transactions Dec 18, 2023
@juliushaertl juliushaertl force-pushed the enh/read-replica-followup branch 2 times, most recently from 3969ff2 to 08c3a4d Compare December 18, 2023 09:40
@juliushaertl juliushaertl force-pushed the enh/read-replica-followup branch 3 times, most recently from a20123e to b0124cd Compare December 18, 2023 19:14
Base automatically changed from enh/read-replica to master December 27, 2023 20:57
@juliushaertl juliushaertl marked this pull request as ready for review December 28, 2023 07:21
@juliushaertl juliushaertl force-pushed the enh/read-replica-followup branch 2 times, most recently from f3f48a4 to 305f9dd Compare December 28, 2023 07:28
@juliushaertl juliushaertl self-assigned this Dec 28, 2023
@juliushaertl juliushaertl requested review from kesselb, a team, ArtificialOwl, icewind1991 and Altahrim and removed request for a team December 28, 2023 07:31
@juliushaertl juliushaertl added the pending documentation This pull request needs an associated documentation update label Dec 28, 2023
@juliushaertl juliushaertl linked an issue Dec 28, 2023 that may be closed by this pull request
if ($this->getTransactionNestingLevel() === 0) {
$timeTook = microtime(true) - $this->transactionActiveSince;
$this->transactionActiveSince = null;
if ($timeTook > 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be true very often. should we use a lower threshold like 10ms?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

microtime will actually return seconds if true is passed on as a parameter so a float is returned. So this would only log if greater 1 second

Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Copy link
Member

@ChristophWurst ChristophWurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo :)

lib/private/DB/Connection.php Outdated Show resolved Hide resolved
lib/private/DB/Connection.php Show resolved Hide resolved
Signed-off-by: Julius Härtl <jus@bitgrid.net>
…k to replicas if reads go to other tables

Signed-off-by: Julius Härtl <jus@bitgrid.net>

debug: error log

Signed-off-by: Julius Härtl <jus@bitgrid.net>
@juliushaertl juliushaertl merged commit 48628b9 into master Jan 12, 2024
50 checks passed
@juliushaertl juliushaertl deleted the enh/read-replica-followup branch January 12, 2024 11:11
@ChristophWurst ChristophWurst removed the pending documentation This pull request needs an associated documentation update label Feb 1, 2024
@AndyScherzinger AndyScherzinger added this to the Nextcloud 29 milestone Feb 14, 2024
@blizzz blizzz mentioned this pull request Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Primary/Secondary choosing querybuilder
4 participants