Skip to content

only flush binlog if buffered position has not advanced#581

Merged
morgo merged 8 commits intoblock:mainfrom
eduardo-landin-mestre:elandin-issue-565
Feb 1, 2026
Merged

only flush binlog if buffered position has not advanced#581
morgo merged 8 commits intoblock:mainfrom
eduardo-landin-mestre:elandin-issue-565

Conversation

@eduardo-landin-mestre
Copy link
Contributor

@eduardo-landin-mestre eduardo-landin-mestre commented Jan 27, 2026

A Pull Request should be associated with an Issue.

We wish to have discussions in Issues. A single issue may be targeted by multiple PRs.
If you're offering a new feature or fixing anything, we'd like to know beforehand in Issues,
and potentially we'll be able to point development in a particular direction.
Further notes in https://github.com/block/spirit/blob/main/.github/CONTRIBUTING.md

Fixes #565

As suggested, these changes decrease the frequency with which spirit flushes binary logs by:

  • only calling FLUSH BINARY LOGS if the buffered position hasn't advanced

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces the frequency of binary log flushing in the BlockWait function to improve performance and reduce contention during replication.

Changes:

  • Modified BlockWait to only flush binary logs when the buffered position has not advanced between iterations
  • Increased the sleep duration between iterations from 100ms to 1 second
  • Added tracking of the previous buffered position to detect when progress has stalled

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@morgo morgo requested a review from Copilot February 1, 2026 22:33
@morgo morgo marked this pull request as ready for review February 1, 2026 22:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

i++
}
}()
time.Sleep(3 * time.Second) // should be enough for BlockWait to block for 1 iteration before catching up, but not guaranteed
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

This test has timing-dependent behavior as acknowledged in the comment "but not guaranteed". The 3-second sleep is meant to allow BlockWait to start and run for at least one iteration, but there's no deterministic way to ensure this happens. If the system is slow or under load, the test could be flaky. Consider using synchronization primitives like channels or wait groups to ensure the test behavior is deterministic, or document this as a known limitation if determinism is not feasible.

Copilot uses AI. Check for mistakes.
morgo and others added 3 commits February 1, 2026 15:37
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
100ns is effectively nothing. So I might as well set it to nothing.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@morgo morgo self-requested a review February 1, 2026 22:47
@morgo morgo enabled auto-merge February 1, 2026 22:48
@morgo morgo merged commit f1b9e7d into block:main Feb 1, 2026
13 checks passed
@morgo
Copy link
Collaborator

morgo commented Feb 1, 2026

I removed the 100ns sleep in the goroutine insert loop. 100ms is effectively nothing, so I've just made it nothing (as a busy loop).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BlockWait is too aggressive in flushing binary logs

3 participants