-
Notifications
You must be signed in to change notification settings - Fork 586
[server] fix KV snapshot restoring fallback #3790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,6 @@ | |
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.apache.fluss.utils.Preconditions.checkNotNull; | ||
| import static org.apache.fluss.utils.Preconditions.checkState; | ||
|
|
||
| /** | ||
| * A handle to the snapshot of a kv tablet. It contains the share file handles and the private file | ||
|
|
@@ -46,22 +45,36 @@ public class KvSnapshotHandle { | |
| private final long incrementalSize; | ||
|
|
||
| /** | ||
| * Once the shared states are registered, it is the {@link SharedKvFileRegistry}'s | ||
| * responsibility to cleanup those shared states. But in the cases where the state handle is | ||
| * discarded before performing the registration, the handle should delete all the shared states | ||
| * created by it. | ||
| * | ||
| * <p>This variable is not null iff the handles was registered. | ||
| * Whether {@link #discard()} should directly delete the shared files. This is true for newly | ||
| * created handles until registration and false for restored handles. | ||
| */ | ||
| private transient SharedKvFileRegistry sharedKvFileRegistry; | ||
| private boolean ownsSharedFiles; | ||
|
|
||
| public KvSnapshotHandle( | ||
| KvSnapshotHandle( | ||
| List<KvFileHandleAndLocalPath> sharedFileHandles, | ||
| List<KvFileHandleAndLocalPath> privateFileHandles, | ||
| long incrementalSize) { | ||
| long incrementalSize, | ||
| boolean ownsSharedFiles) { | ||
| this.sharedFileHandles = sharedFileHandles; | ||
| this.privateFileHandles = privateFileHandles; | ||
| this.incrementalSize = incrementalSize; | ||
| this.ownsSharedFiles = ownsSharedFiles; | ||
| } | ||
|
|
||
| /** Creates a handle that directly discards its shared files until they are registered. */ | ||
| public static KvSnapshotHandle create( | ||
| List<KvFileHandleAndLocalPath> sharedFileHandles, | ||
| List<KvFileHandleAndLocalPath> privateFileHandles, | ||
| long incrementalSize) { | ||
| return new KvSnapshotHandle(sharedFileHandles, privateFileHandles, incrementalSize, true); | ||
| } | ||
|
|
||
| /** Restores a handle that only references already-persisted shared files. */ | ||
| static KvSnapshotHandle restore( | ||
| List<KvFileHandleAndLocalPath> sharedFileHandles, | ||
| List<KvFileHandleAndLocalPath> privateFileHandles, | ||
| long incrementalSize) { | ||
| return new KvSnapshotHandle(sharedFileHandles, privateFileHandles, incrementalSize, false); | ||
| } | ||
|
|
||
| public List<KvFileHandleAndLocalPath> getSharedKvFileHandles() { | ||
|
|
@@ -98,9 +111,6 @@ public long getSnapshotSize() { | |
| } | ||
|
|
||
| public void discard() { | ||
| SharedKvFileRegistry registry = this.sharedKvFileRegistry; | ||
| final boolean isRegistered = (registry != null); | ||
|
|
||
| try { | ||
| SnapshotUtil.bestEffortDiscardAllKvFiles( | ||
| privateFileHandles.stream() | ||
|
|
@@ -110,7 +120,7 @@ public void discard() { | |
| LOG.warn("Could not properly discard misc file states.", e); | ||
| } | ||
|
|
||
| if (!isRegistered) { | ||
| if (ownsSharedFiles) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. discard() no longer touches the shared files, which is right, but it's not obvious from here who does. |
||
| try { | ||
| SnapshotUtil.bestEffortDiscardAllKvFiles( | ||
| sharedFileHandles.stream() | ||
|
|
@@ -123,11 +133,8 @@ public void discard() { | |
| } | ||
|
|
||
| public void registerKvFileHandles(SharedKvFileRegistry registry, long snapshotID) { | ||
| checkState( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to drop the checkState completely? A double registration goes silent now. |
||
| sharedKvFileRegistry != registry, | ||
| "The kv file handle has already registered its shared kv files to the given registry."); | ||
|
|
||
| sharedKvFileRegistry = checkNotNull(registry); | ||
| checkNotNull(registry); | ||
| ownsSharedFiles = false; | ||
|
|
||
| for (KvFileHandleAndLocalPath handleAndLocalPath : sharedFileHandles) { | ||
| registry.registerReference( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deletes the znode and the files, so a wrong true here is unrecoverable. A standby during failover also says File does not exist while the file is fine, should we confirm with fileSystem.exists() before treating the snapshot as broken?
And should we match on FileNotFoundException / NoSuchFileException too? Otherwise S3, OSS and GCS each need another string added here later.