You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fluss.apache.org by "platinumhamburg (via GitHub)" <gi...@apache.org> on 2025/09/22 11:12:24 UTC
[PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
platinumhamburg opened a new pull request, #1738:
URL: https://github.com/apache/fluss/pull/1738
<!--
*Thank you very much for contributing to Fluss - we are happy that you want to help us improve Fluss. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [GitHub issue](https://github.com/apache/fluss/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no issue.
- Name the pull request in the format "[component] Title of the pull request", where *[component]* should be replaced by the name of the component being changed. Typically, this corresponds to the component label assigned to the issue (e.g., [kv], [log], [client], [flink]). Skip *[component]* if you are unsure about which is the best component.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes.
- Each pull request should address only one issue, not mix up code from multiple issues.
**(The sections below can be removed for hotfixes or typos)**
-->
### Purpose
<!-- Linking this pull request to the issue -->
Linked issue: close #1304
<!-- What is the purpose of the change -->
### Brief change log
<!-- Please describe the changes made in this pull request and explain how they address the issue -->
### Tests
<!-- List UT and IT cases to verify this change -->
### API and Format
<!-- Does this change affect API or storage format -->
### Documentation
<!-- Does this change introduce a new feature -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on PR #1738:
URL: https://github.com/apache/fluss/pull/1738#issuecomment-3342343374
> Hi @platinumhamburg , I left a comment about the snapshot cleanup, and a minor comment in the review. Please let me know your thoughts.
Hi @wuchong , I agree that your suggestion is a better approach to handle the ZooKeeper query exception. I've modified my implementation accordingly and fixed another minor issue. Thanks for reviewing this again.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "wuchong (via GitHub)" <gi...@apache.org>.
wuchong commented on PR #1738:
URL: https://github.com/apache/fluss/pull/1738#issuecomment-3343285805
@platinumhamburg thanks for the updates. LGTM.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "wuchong (via GitHub)" <gi...@apache.org>.
wuchong commented on code in PR #1738:
URL: https://github.com/apache/fluss/pull/1738#discussion_r2382982515
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -219,8 +227,56 @@ public void handleSnapshotResult(
updateMinRetainOffset.accept(snapshotResult.getLogOffset());
} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
- snapshotsCleaner.cleanSnapshot(completedSnapshot, () -> {}, ioExecutor);
- handleSnapshotFailure(snapshotId, snapshotLocation, t);
+
+ // Fix for issue: https://github.com/apache/fluss/issues/1304
+ // Tablet server try to commit kv snapshot to coordinator server,
+ // coordinator server commit the kv snapshot to zk, then failover.
+ // Tablet server will got exception from coordinator server, but mistake it as a fail
+ // commit although coordinator server has committed to zk, then discard the commited kv
+ // snapshot.
+ //
+ // Idempotent check: Double check ZK to verify if the snapshot actually exists before
+ // cleanup
+ boolean shouldCleanSnapshot = true;
+ try {
+ if (zooKeeperClient != null) {
+ Optional<BucketSnapshot> zkSnapshot =
+ zooKeeperClient.getTableBucketSnapshot(tableBucket, snapshotId);
+ if (zkSnapshot.isPresent()) {
+ // Snapshot exists in ZK, indicating the commit was actually successful,
+ // just response was lost
+ LOG.warn(
+ "Snapshot {} for TableBucket {} already exists in ZK. "
+ + "The commit was successful but response was lost due to coordinator failover. "
+ + "Skipping cleanup and treating as successful.",
+ snapshotId,
+ tableBucket);
+
+ // Update local state as if the commit was successful
+ rocksIncrementalSnapshot.notifySnapshotComplete(snapshotId);
+ logOffsetOfLatestSnapshot = snapshotResult.getLogOffset();
+ snapshotSize = snapshotResult.getSnapshotSize();
+ updateMinRetainOffset.accept(snapshotResult.getLogOffset());
+
+ shouldCleanSnapshot = false;
+ return; // Snapshot commit succeeded, return directly
+ }
+ }
+ } catch (Exception zkException) {
+ LOG.warn(
+ "Failed to query ZK for snapshot {} of TableBucket {}. "
+ + "Assuming commit failed and proceeding with cleanup.",
Review Comment:
No, we should not treat this as either a successful or a failed snapshot.
When the ZooKeeper request fails, we cannot determine the actual status, the snapshot might have succeeded or failed on the ZK side.
Therefore, we must:
- Not clean up the snapshot files, and
- Not update the local state.
Leaving the snapshot in its current state avoids the risk of discarding a successfully committed snapshot that the connector may already be reading, which would cause data loss or job failure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on code in PR #1738:
URL: https://github.com/apache/fluss/pull/1738#discussion_r2371740438
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -219,8 +227,56 @@ public void handleSnapshotResult(
updateMinRetainOffset.accept(snapshotResult.getLogOffset());
} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
- snapshotsCleaner.cleanSnapshot(completedSnapshot, () -> {}, ioExecutor);
- handleSnapshotFailure(snapshotId, snapshotLocation, t);
+
+ // Fix for issue: https://github.com/apache/fluss/issues/1304
+ // Tablet server try to commit kv snapshot to coordinator server,
+ // coordinator server commit the kv snapshot to zk, then failover.
+ // Tablet server will got exception from coordinator server, but mistake it as a fail
+ // commit although coordinator server has committed to zk, then discard the commited kv
+ // snapshot.
+ //
+ // Idempotent check: Double check ZK to verify if the snapshot actually exists before
+ // cleanup
+ boolean shouldCleanSnapshot = true;
+ try {
+ if (zooKeeperClient != null) {
+ Optional<BucketSnapshot> zkSnapshot =
+ zooKeeperClient.getTableBucketSnapshot(tableBucket, snapshotId);
+ if (zkSnapshot.isPresent()) {
+ // Snapshot exists in ZK, indicating the commit was actually successful,
+ // just response was lost
+ LOG.warn(
+ "Snapshot {} for TableBucket {} already exists in ZK. "
+ + "The commit was successful but response was lost due to coordinator failover. "
+ + "Skipping cleanup and treating as successful.",
+ snapshotId,
+ tableBucket);
+
+ // Update local state as if the commit was successful
+ rocksIncrementalSnapshot.notifySnapshotComplete(snapshotId);
+ logOffsetOfLatestSnapshot = snapshotResult.getLogOffset();
+ snapshotSize = snapshotResult.getSnapshotSize();
+ updateMinRetainOffset.accept(snapshotResult.getLogOffset());
+
+ shouldCleanSnapshot = false;
+ return; // Snapshot commit succeeded, return directly
+ }
+ }
+ } catch (Exception zkException) {
+ LOG.warn(
+ "Failed to query ZK for snapshot {} of TableBucket {}. "
+ + "Assuming commit failed and proceeding with cleanup.",
Review Comment:
I tend to think that if we are definitely sure the snapshot is successful, we should handle it as failed, as this will always ensure a correct result; otherwise, it may not.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on code in PR #1738:
URL: https://github.com/apache/fluss/pull/1738#discussion_r2371709821
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -219,8 +227,56 @@ public void handleSnapshotResult(
updateMinRetainOffset.accept(snapshotResult.getLogOffset());
} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
- snapshotsCleaner.cleanSnapshot(completedSnapshot, () -> {}, ioExecutor);
- handleSnapshotFailure(snapshotId, snapshotLocation, t);
+
+ // Fix for issue: https://github.com/apache/fluss/issues/1304
+ // Tablet server try to commit kv snapshot to coordinator server,
+ // coordinator server commit the kv snapshot to zk, then failover.
+ // Tablet server will got exception from coordinator server, but mistake it as a fail
+ // commit although coordinator server has committed to zk, then discard the commited kv
+ // snapshot.
+ //
+ // Idempotent check: Double check ZK to verify if the snapshot actually exists before
+ // cleanup
+ boolean shouldCleanSnapshot = true;
+ try {
+ if (zooKeeperClient != null) {
+ Optional<BucketSnapshot> zkSnapshot =
+ zooKeeperClient.getTableBucketSnapshot(tableBucket, snapshotId);
+ if (zkSnapshot.isPresent()) {
+ // Snapshot exists in ZK, indicating the commit was actually successful,
+ // just response was lost
+ LOG.warn(
+ "Snapshot {} for TableBucket {} already exists in ZK. "
+ + "The commit was successful but response was lost due to coordinator failover. "
+ + "Skipping cleanup and treating as successful.",
+ snapshotId,
+ tableBucket);
+
+ // Update local state as if the commit was successful
+ rocksIncrementalSnapshot.notifySnapshotComplete(snapshotId);
+ logOffsetOfLatestSnapshot = snapshotResult.getLogOffset();
+ snapshotSize = snapshotResult.getSnapshotSize();
+ updateMinRetainOffset.accept(snapshotResult.getLogOffset());
+
+ shouldCleanSnapshot = false;
+ return; // Snapshot commit succeeded, return directly
+ }
+ }
+ } catch (Exception zkException) {
+ LOG.warn(
+ "Failed to query ZK for snapshot {} of TableBucket {}. "
+ + "Assuming commit failed and proceeding with cleanup.",
Review Comment:
Should we treat this as a successful snapshot? If so, we would need to update certain local variables, which could introduce side effects and potentially lead to inconsistency exceptions. On the other hand, if we consider it a failed snapshot, no inconsistencies would occur, no orphaned files would be left behind, and the inconsistency would be automatically corrected by the mechanism introduced in https://github.com/apache/fluss/pull/1482 and https://github.com/apache/fluss/pull/1470 at a later time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on PR #1738:
URL: https://github.com/apache/fluss/pull/1738#issuecomment-3324106521
@wuchong Thank you for your review. I have addressed all the comments above, except for the handling of undetermined snapshots, which I still treat as failures. I've explained the reasoning behind this decision above. Please review again when you have time.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "wuchong (via GitHub)" <gi...@apache.org>.
wuchong merged PR #1738:
URL: https://github.com/apache/fluss/pull/1738
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on code in PR #1738:
URL: https://github.com/apache/fluss/pull/1738#discussion_r2384445187
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -219,8 +227,56 @@ public void handleSnapshotResult(
updateMinRetainOffset.accept(snapshotResult.getLogOffset());
} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
- snapshotsCleaner.cleanSnapshot(completedSnapshot, () -> {}, ioExecutor);
- handleSnapshotFailure(snapshotId, snapshotLocation, t);
+
+ // Fix for issue: https://github.com/apache/fluss/issues/1304
+ // Tablet server try to commit kv snapshot to coordinator server,
+ // coordinator server commit the kv snapshot to zk, then failover.
+ // Tablet server will got exception from coordinator server, but mistake it as a fail
+ // commit although coordinator server has committed to zk, then discard the commited kv
+ // snapshot.
+ //
+ // Idempotent check: Double check ZK to verify if the snapshot actually exists before
+ // cleanup
+ boolean shouldCleanSnapshot = true;
+ try {
+ if (zooKeeperClient != null) {
+ Optional<BucketSnapshot> zkSnapshot =
+ zooKeeperClient.getTableBucketSnapshot(tableBucket, snapshotId);
+ if (zkSnapshot.isPresent()) {
+ // Snapshot exists in ZK, indicating the commit was actually successful,
+ // just response was lost
+ LOG.warn(
+ "Snapshot {} for TableBucket {} already exists in ZK. "
+ + "The commit was successful but response was lost due to coordinator failover. "
+ + "Skipping cleanup and treating as successful.",
+ snapshotId,
+ tableBucket);
+
+ // Update local state as if the commit was successful
+ rocksIncrementalSnapshot.notifySnapshotComplete(snapshotId);
+ logOffsetOfLatestSnapshot = snapshotResult.getLogOffset();
+ snapshotSize = snapshotResult.getSnapshotSize();
+ updateMinRetainOffset.accept(snapshotResult.getLogOffset());
+
+ shouldCleanSnapshot = false;
+ return; // Snapshot commit succeeded, return directly
+ }
+ }
+ } catch (Exception zkException) {
+ LOG.warn(
+ "Failed to query ZK for snapshot {} of TableBucket {}. "
+ + "Assuming commit failed and proceeding with cleanup.",
Review Comment:
> No, we should not treat this as either a successful or a failed snapshot.
>
> When the ZooKeeper request fails, we cannot determine the actual status, the snapshot might have succeeded or failed on the ZK side.
>
> Therefore, we must:
>
> * Not clean up the snapshot files, and
> * Not update the local state.
>
> Leaving the snapshot in its current state avoids the risk of discarding a successfully committed snapshot that the connector may already be reading, which would cause data loss or job failure.
This is indeed a better way to handle the exception. I'll update the implementation to reflect this approach.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "platinumhamburg (via GitHub)" <gi...@apache.org>.
platinumhamburg commented on code in PR #1738:
URL: https://github.com/apache/fluss/pull/1738#discussion_r2371740438
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -219,8 +227,56 @@ public void handleSnapshotResult(
updateMinRetainOffset.accept(snapshotResult.getLogOffset());
} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
- snapshotsCleaner.cleanSnapshot(completedSnapshot, () -> {}, ioExecutor);
- handleSnapshotFailure(snapshotId, snapshotLocation, t);
+
+ // Fix for issue: https://github.com/apache/fluss/issues/1304
+ // Tablet server try to commit kv snapshot to coordinator server,
+ // coordinator server commit the kv snapshot to zk, then failover.
+ // Tablet server will got exception from coordinator server, but mistake it as a fail
+ // commit although coordinator server has committed to zk, then discard the commited kv
+ // snapshot.
+ //
+ // Idempotent check: Double check ZK to verify if the snapshot actually exists before
+ // cleanup
+ boolean shouldCleanSnapshot = true;
+ try {
+ if (zooKeeperClient != null) {
+ Optional<BucketSnapshot> zkSnapshot =
+ zooKeeperClient.getTableBucketSnapshot(tableBucket, snapshotId);
+ if (zkSnapshot.isPresent()) {
+ // Snapshot exists in ZK, indicating the commit was actually successful,
+ // just response was lost
+ LOG.warn(
+ "Snapshot {} for TableBucket {} already exists in ZK. "
+ + "The commit was successful but response was lost due to coordinator failover. "
+ + "Skipping cleanup and treating as successful.",
+ snapshotId,
+ tableBucket);
+
+ // Update local state as if the commit was successful
+ rocksIncrementalSnapshot.notifySnapshotComplete(snapshotId);
+ logOffsetOfLatestSnapshot = snapshotResult.getLogOffset();
+ snapshotSize = snapshotResult.getSnapshotSize();
+ updateMinRetainOffset.accept(snapshotResult.getLogOffset());
+
+ shouldCleanSnapshot = false;
+ return; // Snapshot commit succeeded, return directly
+ }
+ }
+ } catch (Exception zkException) {
+ LOG.warn(
+ "Failed to query ZK for snapshot {} of TableBucket {}. "
+ + "Assuming commit failed and proceeding with cleanup.",
Review Comment:
I tend to think that unless we are definitely sure the snapshot is successful, we should handle it as failed, as this will always ensure a correct result; otherwise, it may not.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "wuchong (via GitHub)" <gi...@apache.org>.
wuchong commented on code in PR #1738:
URL: https://github.com/apache/fluss/pull/1738#discussion_r2371538076
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -219,8 +227,56 @@ public void handleSnapshotResult(
updateMinRetainOffset.accept(snapshotResult.getLogOffset());
} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
- snapshotsCleaner.cleanSnapshot(completedSnapshot, () -> {}, ioExecutor);
- handleSnapshotFailure(snapshotId, snapshotLocation, t);
+
+ // Fix for issue: https://github.com/apache/fluss/issues/1304
+ // Tablet server try to commit kv snapshot to coordinator server,
+ // coordinator server commit the kv snapshot to zk, then failover.
+ // Tablet server will got exception from coordinator server, but mistake it as a fail
+ // commit although coordinator server has committed to zk, then discard the commited kv
+ // snapshot.
+ //
+ // Idempotent check: Double check ZK to verify if the snapshot actually exists before
+ // cleanup
+ boolean shouldCleanSnapshot = true;
+ try {
+ if (zooKeeperClient != null) {
Review Comment:
We don't need to check the nullability of `zooKeeperClient`, it's not-null, otherwise, it should be marked as `@Nullable`.
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -219,8 +227,56 @@ public void handleSnapshotResult(
updateMinRetainOffset.accept(snapshotResult.getLogOffset());
} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
- snapshotsCleaner.cleanSnapshot(completedSnapshot, () -> {}, ioExecutor);
- handleSnapshotFailure(snapshotId, snapshotLocation, t);
+
+ // Fix for issue: https://github.com/apache/fluss/issues/1304
Review Comment:
This is a very long method, we can extract the check&cleanup logic into a private method to improve code readability, e.g. `handleSnapshotCommitFailed()`,
##########
fluss-server/src/test/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTargetTest.java:
##########
@@ -297,6 +297,139 @@ void testAddToSnapshotToStoreFail(@TempDir Path kvTabletDir) throws Exception {
assertThat(updateMinRetainOffsetConsumer.get()).isEqualTo(1L);
}
+ @Test
+ void testIdempotentCheckWhenSnapshotExistsInZK(@TempDir Path kvTabletDir) throws Exception {
+ // Test case: coordinator commits to ZK successfully but response is lost due to failover
+ // The tablet server should detect the snapshot exists in ZK and skip cleanup
+ CompletedSnapshotHandleStore completedSnapshotHandleStore =
+ new ZooKeeperCompletedSnapshotHandleStore(zooKeeperClient);
+ FsPath remoteKvTabletDir = FsPath.fromLocalFile(kvTabletDir.toFile());
+
+ // Create a committer that commits to ZK first, then throws exception
+ // This simulates coordinator failover after ZK commit but before response
+ CompletedKvSnapshotCommitter failingAfterZkCommitCommitter =
+ (snapshot, coordinatorEpoch, bucketLeaderEpoch) -> {
+ // Always commit to ZK first
+ CompletedSnapshotHandle handle =
+ new CompletedSnapshotHandle(
+ snapshot.getSnapshotID(),
+ snapshot.getSnapshotLocation(),
+ snapshot.getLogOffset());
+ completedSnapshotHandleStore.add(
+ snapshot.getTableBucket(), snapshot.getSnapshotID(), handle);
+
+ // Then throw exception - simulating coordinator failover after ZK commit
+ throw new FlussException("Coordinator failover after ZK commit");
+ };
+
+ KvTabletSnapshotTarget kvTabletSnapshotTarget =
+ createSnapshotTargetWithCustomCommitter(
+ remoteKvTabletDir, failingAfterZkCommitCommitter);
+
+ periodicSnapshotManager = createSnapshotManager(kvTabletSnapshotTarget);
+ periodicSnapshotManager.start();
+
+ RocksDB rocksDB = rocksDBExtension.getRocksDb();
+ rocksDB.put("key1".getBytes(), "val1".getBytes());
+
+ // Trigger snapshot - will commit to ZK but throw exception
+ periodicSnapshotManager.triggerSnapshot();
+ long snapshotId1 = 1;
+
+ TestRocksIncrementalSnapshot rocksIncrementalSnapshot =
+ (TestRocksIncrementalSnapshot) kvTabletSnapshotTarget.getRocksIncrementalSnapshot();
+
+ // The snapshot should be treated as successful due to idempotent check
+ // Even though commit threw exception, idempotent check should find it in ZK
+ retry(
+ Duration.ofMinutes(1),
+ () ->
+ assertThat(rocksIncrementalSnapshot.completedSnapshots)
Review Comment:
`rocksIncrementalSnapshot.completedSnapshots` and `rocksIncrementalSnapshot.abortedSnapshots` is not thread-safe, would be better to use `ConcurrentHashMap.newKeySet()`.
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -219,8 +227,56 @@ public void handleSnapshotResult(
updateMinRetainOffset.accept(snapshotResult.getLogOffset());
} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
- snapshotsCleaner.cleanSnapshot(completedSnapshot, () -> {}, ioExecutor);
- handleSnapshotFailure(snapshotId, snapshotLocation, t);
+
+ // Fix for issue: https://github.com/apache/fluss/issues/1304
+ // Tablet server try to commit kv snapshot to coordinator server,
+ // coordinator server commit the kv snapshot to zk, then failover.
+ // Tablet server will got exception from coordinator server, but mistake it as a fail
+ // commit although coordinator server has committed to zk, then discard the commited kv
+ // snapshot.
+ //
+ // Idempotent check: Double check ZK to verify if the snapshot actually exists before
+ // cleanup
+ boolean shouldCleanSnapshot = true;
+ try {
+ if (zooKeeperClient != null) {
+ Optional<BucketSnapshot> zkSnapshot =
+ zooKeeperClient.getTableBucketSnapshot(tableBucket, snapshotId);
+ if (zkSnapshot.isPresent()) {
+ // Snapshot exists in ZK, indicating the commit was actually successful,
+ // just response was lost
+ LOG.warn(
+ "Snapshot {} for TableBucket {} already exists in ZK. "
+ + "The commit was successful but response was lost due to coordinator failover. "
+ + "Skipping cleanup and treating as successful.",
+ snapshotId,
+ tableBucket);
+
+ // Update local state as if the commit was successful
+ rocksIncrementalSnapshot.notifySnapshotComplete(snapshotId);
+ logOffsetOfLatestSnapshot = snapshotResult.getLogOffset();
+ snapshotSize = snapshotResult.getSnapshotSize();
+ updateMinRetainOffset.accept(snapshotResult.getLogOffset());
Review Comment:
extract this into a private method `handleSuccessfulSnapshot(SnapshotResult)`, and reuse with commit-kv successful code path.
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -219,8 +227,56 @@ public void handleSnapshotResult(
updateMinRetainOffset.accept(snapshotResult.getLogOffset());
} catch (Exception e) {
Throwable t = ExceptionUtils.stripExecutionException(e);
- snapshotsCleaner.cleanSnapshot(completedSnapshot, () -> {}, ioExecutor);
- handleSnapshotFailure(snapshotId, snapshotLocation, t);
+
+ // Fix for issue: https://github.com/apache/fluss/issues/1304
+ // Tablet server try to commit kv snapshot to coordinator server,
+ // coordinator server commit the kv snapshot to zk, then failover.
+ // Tablet server will got exception from coordinator server, but mistake it as a fail
+ // commit although coordinator server has committed to zk, then discard the commited kv
+ // snapshot.
+ //
+ // Idempotent check: Double check ZK to verify if the snapshot actually exists before
+ // cleanup
+ boolean shouldCleanSnapshot = true;
+ try {
+ if (zooKeeperClient != null) {
+ Optional<BucketSnapshot> zkSnapshot =
+ zooKeeperClient.getTableBucketSnapshot(tableBucket, snapshotId);
+ if (zkSnapshot.isPresent()) {
+ // Snapshot exists in ZK, indicating the commit was actually successful,
+ // just response was lost
+ LOG.warn(
+ "Snapshot {} for TableBucket {} already exists in ZK. "
+ + "The commit was successful but response was lost due to coordinator failover. "
+ + "Skipping cleanup and treating as successful.",
+ snapshotId,
+ tableBucket);
+
+ // Update local state as if the commit was successful
+ rocksIncrementalSnapshot.notifySnapshotComplete(snapshotId);
+ logOffsetOfLatestSnapshot = snapshotResult.getLogOffset();
+ snapshotSize = snapshotResult.getSnapshotSize();
+ updateMinRetainOffset.accept(snapshotResult.getLogOffset());
+
+ shouldCleanSnapshot = false;
+ return; // Snapshot commit succeeded, return directly
+ }
+ }
+ } catch (Exception zkException) {
+ LOG.warn(
+ "Failed to query ZK for snapshot {} of TableBucket {}. "
+ + "Assuming commit failed and proceeding with cleanup.",
Review Comment:
I still think we shouldn't cleanup the snapshot if zk request failed, because it may exist in zk. We should only cleanup the snapshot when zk truly doesn't have this snapshot id.
It's fine if we don't cleanup some unkown snapshots, the orphan files in remote storage should be cleanup by a dedicated service. It's also fine to not update local state for the snapshot, as it will eventually be updated by the next successful snapshot, and this doesn't affect data correctness.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "wuchong (via GitHub)" <gi...@apache.org>.
wuchong commented on code in PR #1738:
URL: https://github.com/apache/fluss/pull/1738#discussion_r2382985317
##########
fluss-server/src/main/java/org/apache/fluss/server/kv/snapshot/KvTabletSnapshotTarget.java:
##########
@@ -55,6 +58,8 @@ public class KvTabletSnapshotTarget implements PeriodicSnapshotManager.SnapshotT
private final CompletedKvSnapshotCommitter completedKvSnapshotCommitter;
+ @Nonnull private final ZooKeeperClient zooKeeperClient;
Review Comment:
minor: We don't need to add `@Nonnull` annotation for non-null fields, otherwise, we have so many fields need to add. We only need to and must to add `@Nullable` annotation for the nullable fields, so we know whether to check null when using it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [KV] Avoid TabletServer to discard already commited kv snapshot [fluss]
Posted by "wuchong (via GitHub)" <gi...@apache.org>.
wuchong commented on PR #1738:
URL: https://github.com/apache/fluss/pull/1738#issuecomment-3339696574
Hi @platinumhamburg , I left a comment about the snapshot cleanup, and a minor comment in the review. Please let me know your thoughts.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fluss.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org