Skip to content

[server] Register external KV snapshots and restore replicas - #4242

Open
platinumhamburg wants to merge 8 commits into
apache:mainfrom
platinumhamburg:feature-kv-snapshot-import
Open

platinumhamburg wants to merge 8 commits into
apache:mainfrom
platinumhamburg:feature-kv-snapshot-import

Conversation

@platinumhamburg

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #4223

Brief change log

Tests

API and Format

Documentation

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Critical snapshot integrity and manifest validation are missing, and metadata versions are not validated.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity · 1 Medium severity

Open (3)
What changed in this PR

Adds external KV snapshot registration, retention, and replica restoration support.

Changes:

  • Adds portable snapshot metadata serialization.
  • Registers external snapshots in ZooKeeper with retry and retention handling.
  • Restores replicas from external snapshots and initializes log tails.
  • Adds recovery, registration, retention, and compatibility tests.
File Summary
fluss-server/​src/​test/​java/​org/​apache/​fluss/​server/​replica/​ReplicaTest.java Tests replica recovery behavior.
fluss-server/​src/​test/​java/​org/​apache/​fluss/​server/​log/​LogTabletTest.java Tests log-tail initialization.
fluss-server/​src/​test/​java/​org/​apache/​fluss/​server/​kv/​snapshot/​TestCompletedSnapshotHandleStore.java Updates test snapshot-store implementation.
fluss-server/​src/​test/​java/​org/​apache/​fluss/​server/​coordinator/​ExternalKvSnapshotITCase.java Tests external snapshot recovery end to end.
fluss-server/​src/​test/​java/​org/​apache/​fluss/​server/​coordinator/​CoordinatorServiceOrphanRpcsITCase.java Updates test-store fixtures.
fluss-server/​src/​test/​java/​org/​apache/​fluss/​server/​coordinator/​CompletedSnapshotStoreManagerTest.java Tests registration and retention scenarios.
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​zk/​ZooKeeperClient.java Adds idempotent external snapshot registration.
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​replica/​Replica.java Integrates snapshot-based KV recovery.
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​log/​LogTablet.java Supports empty log-tail initialization.
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​log/​LogManager.java Persists initialized log tails.
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​kv/​snapshot/​ZooKeeperCompletedSnapshotHandleStore.java Implements ZooKeeper-backed external registration.
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​kv/​snapshot/​CompletedSnapshotStore.java Integrates external snapshots with retention.
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​kv/​snapshot/​CompletedSnapshotJsonSerde.java Adapts server snapshots to portable metadata.
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​kv/​snapshot/​CompletedSnapshotHandleStore.java Extends the snapshot handle-store contract.
fluss-server/​src/​main/​java/​org/​apache/​fluss/​server/​coordinator/​CompletedSnapshotStoreManager.java Registers and tracks external snapshots.
fluss-common/​src/​test/​java/​org/​apache/​fluss/​metadata/​KvSnapshotFileMetadataJsonSerdeTest.java Tests metadata serialization compatibility.
fluss-common/​src/​main/​java/​org/​apache/​fluss/​metadata/​KvSnapshotFileMetadataJsonSerde.java Serializes and deserializes portable metadata.
fluss-common/​src/​main/​java/​org/​apache/​fluss/​metadata/​KvSnapshotFileMetadata.java Defines portable snapshot metadata.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Share KV snapshot file metadata across modules and register externally produced target-bucket snapshots with coordinator fencing and idempotent retries. Adopt confirmed snapshots into retention and protect persistent references when registration responses are lost.

Initialize the local log boundary from snapshot-only history through ordinary replica role notifications. Cover external snapshot production, registration, recovery, repeated notifications, online writes, failover and subsequent snapshot retention.
Use the selected KV snapshot to initialize an empty local log after its
files have been loaded, and capture the leader log boundary after recovery.
Reject conflicting log initialization and propagate snapshot lookup errors.

Release partially recovered KV state before retrying, and publish leader
identity only after recovery succeeds so failed elections can be retried.
Cover snapshot lookup and download failures, metadata retry after loading,
and protection of existing local log records.
Keep the existing leader and follower transition behavior while coordinating
KV snapshot recovery with local log initialization. Test snapshot lookup
failures independently of role transition retries, and recover from a failed
download under a subsequent leader epoch.
Serialize external snapshot identity and ordering checks, persistent handle
confirmation and retention updates in CompletedSnapshotStore. Delegate
coordinator fencing and idempotent persistence to the handle store while
preserving ordinary snapshot writes and cleanup behavior.

Describe the snapshot counter check as an allocation bound; reserving the
ID remains the caller's responsibility.
@platinumhamburg
platinumhamburg force-pushed the feature-kv-snapshot-import branch from 097aacc to 0e0ab1f Compare September 21, 2026 02:04
Resolve the recovery snapshot and log prerequisites before changing role
state or discarding the current KV. Reuse that selection for the first
recovery attempt while preserving retries through older healthy snapshots.
Avoid remote manifest lookups when the local log already covers the snapshot.

Cover metadata lookup failures with a live KV and recovery after metadata
becomes available. Clarify that obsolete snapshot cleanup may be deferred.
@platinumhamburg
platinumhamburg force-pushed the feature-kv-snapshot-import branch from 0e0ab1f to 4a1fb0a Compare September 21, 2026 02:33
Wait for KV replicas before bounded snapshot split enumeration. Keep synthetic orphan-cleanup snapshot metadata from participating in leader recovery, and let replica readiness checks retry while the leader or tablet server is temporarily unavailable.
@platinumhamburg

Copy link
Copy Markdown
Contributor Author

Addressing the three Copilot review comments:

  • Per-file integrity: External snapshot registration now requires a canonical SHA-256 for every file. The replica checks actual length and SHA-256 after download and before loading the KV tablet, so corrupted data cannot become active KV state. This is currently an internal trusted-producer path with no client or RPC entry point; the Coordinator intentionally does not perform a second full read of every remote file.
  • Manifest validation: Before persisting the ZK handle, registration checks bucket and handle identity, snapshot ID and log offset, the reserved ID boundary, digest format, nonnegative sizes, safe and unique local paths, unique remote paths, and private-file containment. Actual file existence, length, and digest are checked during replica recovery before loading RocksDB.
  • Metadata version: Deserialization now rejects missing, unsupported, and out-of-range versions before reading the remaining fields. The integer conversion edge case is covered by commit 59b9e28 and a regression test.

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.

[Server] Support importing completed KV snapshots

2 participants