Skip to content

[server] Incrementally clean historical KV state - #4199

Draft
luoyuxia wants to merge 8 commits into
apache:mainfrom
luoyuxia:fip28-incremental-historical-kv-cleanup
Draft

[server] Incrementally clean historical KV state#4199
luoyuxia wants to merge 8 commits into
apache:mainfrom
luoyuxia:fip28-incremental-historical-kv-cleanup

Conversation

@luoyuxia

@luoyuxia luoyuxia commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: #4159.

Depends on #4120. This is a stacked PR; until #4120 merges, review commit f6914503a only.

Historical writes retain local KV values and tombstones until their WAL offsets are covered by the lake snapshot. This change makes entries below the confirmed lake progress eligible for incremental reclamation, without waiting for the lake and local log end offsets to become equal or rebuilding the entire RocksDB instance.

Cleanup is best effort: the cleanup offset controls eligibility, while physical deletion occurs during normal RocksDB compactions. The implementation does not schedule an additional full-range compaction when the offset advances.

Brief change log

  • Preserve the previous values resolved by the initial historical lookup and reuse them during apply, so concurrent compaction cannot change merge, delete, or changelog semantics.
  • Tag historical values and tombstones with the WAL offset that produced them on leader writes, pre-write-buffer flushes, and WAL recovery.
  • Maintain a monotonic, exclusive historical cleanup offset from confirmed lake progress, publishing the required lake snapshot before exposing a newer offset and restoring it safely during leader recovery.
  • Generalize the row-TTL compaction-filter factory so historical cleanup can use the stored WAL-offset tag and remove entries whose tag is lower than the cleanup offset.
  • Decode tagged local lookup results while keeping lake values in their existing plain layout, and add tests for resolved previous values, offset tagging, cleanup boundaries, repeated progress notifications, recovery, and lookup behavior.

Tests

  • Targeted fluss-server unit tests: KvValueLayoutTest, RowTtlCompactionFilterTest, HistoricalKvCompactionFilterTest, KvTabletTest, and HistoricalPartitionManagerTest (56 tests passed).
  • ./mvnw -pl fluss-server spotless:check
  • Checkstyle and RAT validation passed for the affected modules.
  • git diff --check
  • ./mvnw verify was attempted. It stopped in fluss-server after 1,303 tests because the local disk was 95% full: five ReplicaFetcherThreadTest cases hit the 85% RocksDB disk guard, and two unrelated ReplicaTest local-log metric assertions failed. The historical-KV and compaction-filter tests passed in that run.

API and Format

No public API changes.

The internal RocksDB value format for historical KV state now carries an 8-byte WAL-offset tag; a historical tombstone consists only of that tag. Lake values remain in the plain value layout.

Documentation

No user-facing documentation changes. The design and trade-offs are described in #4159 and this PR.

Generative AI disclosure

  • Yes — Codex (GPT-5), reviewed by the author.

luoyuxia and others added 7 commits September 1, 2026 11:46
Route writes for expired partitions through internal historical targets while preserving original partition metadata across PUT_KV and PRODUCE_LOG.

Tier historical KV and log records back to their original Paimon partitions, fail writes to confirmed missing targets, and safely clean fully tiered historical KV overlays with leader-epoch and offset guards.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-5
AI-Contributed/Feature: 1469/1469
AI-Contributed/UT: 2215/2215
Simplify historical write routing, request handling, and Paimon tiering integration while removing redundant tests.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-5
AI-Contributed/Feature: 446/446
AI-Contributed/UT: 576/576
Bind historical write state to the active KV overlay and defer idle cleanup until its deadline after lake progress catches up.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-5
AI-Contributed/Feature: 234/234
AI-Contributed/UT: 129/129
Return a retriable KV storage error while local historical KV state is being initialized or rebuilt. Clarify cleanup-state naming and terminology, and extend the Paimon integration test through post-recovery writes and restarted tiering.

Co-Authored-By: Codex <noreply@openai.com>

AI-Model: gpt-5
AI-Contributed/Feature: 244/244
AI-Contributed/UT: 239/239
Refresh registered Paimon partition-bucket file sets when the required lake snapshot changes, allowing unchanged local lookup files to remain reusable.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-5

AI-Contributed/Feature: 161/215
AI-Contributed/UT: 95/125
Exclude the plugin-facing LakeTableLookuper interface from the aggregate per-class coverage rule.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-5
AI-Contributed/Feature: 3/3
AI-Contributed/UT: 0/0
Remove the coupled historical KV cleanup mechanism, defer lake lookup refresh I/O until lookup initialization, and simplify historical write version and routing checks. Reroute missing original targets when no request remains in flight, abort only the affected target when handoff is unsafe, and document the remaining retirement ambiguity.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-5.6-sol
AI-Contributed/Feature: 56/56
AI-Contributed/UT: 2/2
@luoyuxia
luoyuxia force-pushed the fip28-incremental-historical-kv-cleanup branch from a6bd609 to ac5dde1 Compare September 2, 2026 08:52
Preserve historical write lookup results so compaction between lookup and apply cannot change merge, delete, or changelog semantics.

Tag historical values and tombstones with their producing WAL offsets, advance an exclusive cleanup offset after publishing the covering lake snapshot, and reuse the RocksDB compaction filter for best-effort cleanup.

Perform lake lookups between the local probe and apply lock sections, then expose the complete request-scoped result through an in-memory historical value lookup.

Co-Authored-By: Codex <noreply@openai.com>
AI-Model: gpt-5
AI-Contributed/Feature: 480/480
AI-Contributed/UT: 102/102
@luoyuxia
luoyuxia force-pushed the fip28-incremental-historical-kv-cleanup branch from ac5dde1 to f691450 Compare September 2, 2026 11:42
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.

1 participant