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

juliusknorr
Copy link
Member

@juliusknorr juliusknorr 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.

@juliusknorr juliusknorr changed the title enh/read replica followup feat: Track dirty table writes and long transactions Dec 18, 2023
@juliusknorr juliusknorr force-pushed the enh/read-replica-followup branch 2 times, most recently from 3969ff2 to 08c3a4d Compare December 18, 2023 09:40
@juliusknorr juliusknorr 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
@juliusknorr juliusknorr marked this pull request as ready for review December 28, 2023 07:21
@juliusknorr juliusknorr force-pushed the enh/read-replica-followup branch 2 times, most recently from f3f48a4 to 305f9dd Compare December 28, 2023 07:28
@juliusknorr juliusknorr self-assigned this Dec 28, 2023
@juliusknorr juliusknorr requested review from kesselb, a team, ArtificialOwl, icewind1991 and Altahrim and removed request for a team December 28, 2023 07:31
@juliusknorr juliusknorr added the pending documentation This pull request needs an associated documentation update label Dec 28, 2023
@juliusknorr juliusknorr linked an issue Dec 28, 2023 that may be closed by this pull request
@juliusknorr juliusknorr force-pushed the enh/read-replica-followup branch from 305f9dd to da4600a Compare December 28, 2023 11:50
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

@juliusknorr juliusknorr force-pushed the enh/read-replica-followup branch from da4600a to d1d2794 Compare December 29, 2023 10:17
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
@juliusknorr juliusknorr force-pushed the enh/read-replica-followup branch from d1d2794 to 3fecfef Compare January 3, 2024 22:31
lib/private/DB/Connection.php Show resolved Hide resolved
@juliusknorr juliusknorr force-pushed the enh/read-replica-followup branch from 3fecfef to 139c022 Compare January 11, 2024 11:54
…k to replicas if reads go to other tables

Signed-off-by: Julius Härtl <[email protected]>

debug: error log

Signed-off-by: Julius Härtl <[email protected]>
@juliusknorr juliusknorr force-pushed the enh/read-replica-followup branch from 139c022 to c17c42a Compare January 12, 2024 10:02
@juliusknorr juliusknorr merged commit 48628b9 into master Jan 12, 2024
50 checks passed
@juliusknorr juliusknorr 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