Repository navigation
[server] Restore KV minRetainOffset on follower restart - #4060
Conversation
4f05624 to
162c53c
Compare
| // Followers don't initialize a KV tablet, so restore the log retention state from the | ||
| // latest committed KV snapshot. The ZooKeeper read is scheduled asynchronously because | ||
| // this method runs while holding the replica state-change lock. | ||
| restoreFollowerMinRetainOffsets(kvFollowers); |
There was a problem hiding this comment.
Could we avoid this separate ZooKeeper-backed recovery state machine by piggybacking the committed minRetainOffset on follower FetchLogResponses? The leader advances this value only after a KV snapshot is committed, and follower fetches already retry continuously (including empty long-poll responses), so every successful fetch can idempotently apply updateMinRetainOffset. The existing notification can remain the fast path, while FetchLog becomes the anti-entropy and restart-recovery path.
This follows Kafka's pattern of propagating a logical cleanup boundary by logStartOffset in FetchResponse. Fluss should use a separate optional min_retain_offset field rather than overload log_start_offset: the former is snapshot-derived deletion permission. This would remove the complex logic in this PR: pending map, ZooKeeper batch reads, scheduler/backoff, and replica-identity fencing while preserving eventual local cleanup progress.
3ec3085 to
b7e06be
Compare
| optional int64 filtered_end_offset = 9; | ||
| // The safe local log retention boundary confirmed by a committed KV snapshot. This is only | ||
| // returned for KV follower fetches and is distinct from the physical log_start_offset. | ||
| optional int64 min_retain_offset = 10; |
There was a problem hiding this comment.
The canonical RPC schema change is not mirrored to fluss-rust/crates/fluss/proto/FlussApi.proto or regenerated in fluss-rust/crates/fluss/src/proto/fluss.rs. This makes proto-up-to-date fail and leaves the Rust bindings/build inconsistent with the Java RPC schema. Please regenerate the Rust protobuf bindings and update the affected PbFetchLogRespForBucket struct literals in this PR.
| } else { | ||
| result = new FetchLogResultForBucket(tb, ApiError.fromThrowable(e)); | ||
| } | ||
| result = maybeAddMinRetainOffset(fetchParams, replica, result); |
There was a problem hiding this comment.
This is error path, we don't need to pass minRetainOffset when is error response or empty response.
| new FetchLogResultForBucket( | ||
| tb, fetchedData.getRecords(), readInfo.getHighWatermark()); | ||
| } | ||
| fetchLogResult = maybeAddMinRetainOffset(fetchParams, replica, fetchLogResult); |
There was a problem hiding this comment.
Could we propagate minRetainOffset through the same read-metadata path as highWatermark instead of attaching it afterward? Adding it to LogReadInfo, capturing it in Replica.readRecords, and passing both values into a FetchLogResultForBucket success factory or constructor would make each result complete at construction time and avoid dropping the field when a new success path or adapter rebuilds the result. The remote/lake out-of-range success paths should use the same factory because they bypass LogReadInfo; if the two values must form a consistent snapshot, they should also be read under the same synchronization boundary.
| if (serverId == leaderServerId) { | ||
| leaderKvManager = kvManager; | ||
| } else { | ||
| followerKvManager = kvManager; | ||
| } |
There was a problem hiding this comment.
Why do we need to maintain separate followerKvManager and leaderKvManager? It seems they refer the same kvManager object and there is no code using followerKvManager and leaderKvManager.
f4a027f to
c4dec0f
Compare
|
@gyang94 I appended a commit to refine the code, please take a look. |
c4dec0f to
467d19a
Compare
Propagate minRetainOffset through the regular fetch result construction path and update followers even when successful fetches contain no records. Replace FetchLogResultForBucket constructor overloads with named factories, document the monotonic concurrent update, and stabilize the restart test with a manually controlled clock. Co-Authored-By: Codex <noreply@openai.com> AI-Model: gpt-5.6-sol AI-Contributed/Feature: 5/5 AI-Contributed/UT: 0/0
467d19a to
6708cf4
Compare
|
@wuchong: Thanks for refining the code. LGTM. |
Summary
minRetainOffsetfrom the latest committed KV snapshot when KV followers are handled inmakeFollowers.Test Plan
ZooKeeperClientTest: 23 tests passed.ReplicaManagerTest: 41 tests passed.mvn -o -pl fluss-server -DskipTests -Dfast verifypassed (Checkstyle 0 violations and Spotless passed).🤖 AI-assisted changes - reviewed by human developer