Skip to content

[server] Keep flushedLogOffset monotonic to fix row count after failover - #3427

Merged
swuferhong merged 2 commits into
apache:mainfrom
wattt3:3386-kv-flushed-offset-monotonic
Jun 8, 2026
Merged

swuferhong merged 2 commits into
apache:mainfrom
wattt3:3386-kv-flushed-offset-monotonic

Conversation

@wattt3

@wattt3 wattt3 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #3386

FlussAdminITCase.testGetTableStatsForPrimaryKeyTableWithFailover is a flaky test(expected: 170 but was: 160).

The root cause is flushedLogOffset = exclusiveUpToLogOffset in KvTablet#flush, which does not keep flushedLogOffset monotonically increasing.

When flush is called with an exclusiveUpToLogOffset lower than the current flushedLogOffset, flushedLogOffset is rolled back to that lower value, while rowCount is not. As a result, the (flushedLogOffset, rowCount) pair becomes inconsistent.

During failover, a kv snapshot can capture this inconsistent pair, and recovery then replays the log from the stale offset and double-counts the already-applied deletes, under-reporting the row count

Brief change log

  • KvTablet#flush now only advanced flushedLogOffset when exclusiveUpToLogOffset is greater than current value.

Tests

API and Format

Documentation

@wattt3

wattt3 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Hi @swuferhong
Could you please take a look when you have time?
Thanks!

@swuferhong swuferhong left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM overall, please add a ut test in KvTabletTest: write some INSERT/DELETE, call flush(highOffset), then flush(lowOffset), and assert that flushedLogOffset does not regress, rowCount stays unchanged, and getTabletState() is self-consistent.

@wattt3

wattt3 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@swuferhong
Thank you for the review.
I add a unit test. PTAL.

@platinumhamburg platinumhamburg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, just one minor question.

@swuferhong
swuferhong merged commit 6d3ba38 into apache:main Jun 8, 2026
7 checks passed
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.

[test] Unstable test FlussAdminITCase.testGetTableStatsForPrimaryKeyTableWithFailover

3 participants