-
Notifications
You must be signed in to change notification settings - Fork 611
[server] Support primary-key writes to historical partitions #4001
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
Open
luoyuxia
wants to merge
1
commit into
apache:main
Choose a base branch
from
luoyuxia:fip28-historical-partition-write-foundations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
fluss-server/src/main/java/org/apache/fluss/server/entity/PutKvDataForBucket.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.fluss.server.entity; | ||
|
|
||
| import org.apache.fluss.metadata.TableBucket; | ||
| import org.apache.fluss.record.KvRecordBatch; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import static org.apache.fluss.utils.Preconditions.checkNotNull; | ||
|
|
||
| /** Put KV request data and historical partition context for one table bucket. */ | ||
| public final class PutKvDataForBucket { | ||
|
|
||
| private final TableBucket tableBucket; | ||
| private final KvRecordBatch records; | ||
| private final @Nullable String originalPartitionName; | ||
|
|
||
| /** Creates decoded put-KV data for one table bucket. */ | ||
| public PutKvDataForBucket( | ||
| TableBucket tableBucket, | ||
| KvRecordBatch records, | ||
| @Nullable String originalPartitionName) { | ||
| this.tableBucket = checkNotNull(tableBucket, "tableBucket must not be null."); | ||
| this.records = checkNotNull(records, "records must not be null."); | ||
| this.originalPartitionName = originalPartitionName; | ||
| } | ||
|
|
||
| /** Returns the physical table bucket targeted by this request data. */ | ||
| public TableBucket tableBucket() { | ||
| return tableBucket; | ||
| } | ||
|
|
||
| /** Returns the encoded KV records for this table bucket. */ | ||
| public KvRecordBatch records() { | ||
| return records; | ||
| } | ||
|
|
||
| /** Returns the original partition name for a historical write, or null. */ | ||
| public @Nullable String originalPartitionName() { | ||
| return originalPartitionName; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
fluss-server/src/main/java/org/apache/fluss/server/kv/KvStateAccessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.fluss.server.kv; | ||
|
|
||
| import org.apache.fluss.annotation.Internal; | ||
| import org.apache.fluss.server.kv.prewrite.KvPreWriteBuffer.Key; | ||
| import org.apache.fluss.server.kv.prewrite.KvPreWriteBuffer.TruncateReason; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| /** Accessor for the local state used while processing KV records. */ | ||
| @Internal | ||
| public interface KvStateAccessor { | ||
|
|
||
| /** | ||
| * Encodes the logical primary key into the physical key used by this state. | ||
| * | ||
| * <p>Normal KV state keeps the primary key unchanged. Historical KV state also encodes the | ||
| * original partition context because multiple original partitions share one historical KV | ||
| * tablet. | ||
| */ | ||
| Key encodeKey(byte[] primaryKey); | ||
|
|
||
| /** Looks up an encoded key from local state and an optional external fallback. */ | ||
| KvStateLookupResult lookup(Key key) throws Exception; | ||
|
|
||
| /** Adds an insert mutation to the prewrite buffer. */ | ||
| void insert(Key key, byte[] value, long logOffset); | ||
|
|
||
| /** Adds an update mutation to the prewrite buffer. */ | ||
| void update(Key key, @Nullable byte[] value, long logOffset); | ||
|
|
||
| /** Adds a delete mutation to the prewrite buffer. */ | ||
| void delete(Key key, long logOffset); | ||
|
|
||
| /** Truncates pending mutations to the given log offset. */ | ||
| void truncateTo(long logOffset, TruncateReason reason); | ||
| } |
131 changes: 131 additions & 0 deletions
131
fluss-server/src/main/java/org/apache/fluss/server/kv/KvStateLookupResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to you under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.fluss.server.kv; | ||
|
|
||
| import org.apache.fluss.annotation.Internal; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import static org.apache.fluss.utils.Preconditions.checkArgument; | ||
| import static org.apache.fluss.utils.Preconditions.checkNotNull; | ||
|
|
||
| /** | ||
| * Result of looking up a key from local KV state. | ||
| * | ||
| * <p>{@link Status#NOT_FOUND} only means that the key was not found in local KV state, so a | ||
| * historical lookup may still query lake storage. {@link Status#DELETED} confirms that the key has | ||
| * been deleted and must stop the fallback from exposing an older value in lake storage. | ||
| */ | ||
| @Internal | ||
| public final class KvStateLookupResult { | ||
|
|
||
| /** Status of a local KV state lookup. */ | ||
| public enum Status { | ||
| /** The key was not found in local KV state. */ | ||
| NOT_FOUND, | ||
|
|
||
| /** Local state contains a non-empty encoded value. */ | ||
| PRESENT, | ||
|
|
||
| /** The key is known to have been deleted. */ | ||
| DELETED | ||
| } | ||
|
|
||
| private static final KvStateLookupResult NOT_FOUND = | ||
| new KvStateLookupResult(Status.NOT_FOUND, null); | ||
| private static final KvStateLookupResult DELETED = | ||
| new KvStateLookupResult(Status.DELETED, null); | ||
|
|
||
| private final Status status; | ||
| private final @Nullable byte[] value; | ||
|
|
||
| private KvStateLookupResult(Status status, @Nullable byte[] value) { | ||
| this.status = status; | ||
| this.value = value; | ||
| } | ||
|
|
||
| /** Returns a result indicating that the key was not found in local KV state. */ | ||
| public static KvStateLookupResult notFound() { | ||
| return NOT_FOUND; | ||
| } | ||
|
|
||
| /** Returns a result containing a non-empty encoded value. */ | ||
| public static KvStateLookupResult present(byte[] value) { | ||
| checkNotNull(value, "value must not be null"); | ||
| checkArgument(value.length > 0, "value must not be empty"); | ||
| return new KvStateLookupResult(Status.PRESENT, value); | ||
| } | ||
|
|
||
| /** Returns a result indicating that the key is known to have been deleted. */ | ||
| public static KvStateLookupResult deleted() { | ||
| return DELETED; | ||
| } | ||
|
|
||
| /** Returns the lookup status. */ | ||
| public Status status() { | ||
| return status; | ||
| } | ||
|
|
||
| /** Returns whether this result contains an encoded value. */ | ||
| public boolean isPresent() { | ||
| return status == Status.PRESENT; | ||
| } | ||
|
|
||
| /** Returns whether the key is known to have been deleted. */ | ||
| public boolean isDeleted() { | ||
| return status == Status.DELETED; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the encoded value, or null when the key is absent or deleted. | ||
| * | ||
| * <p>The returned byte array is owned by the underlying state and must not be modified. | ||
| */ | ||
| public @Nullable byte[] value() { | ||
| return value; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| KvStateLookupResult that = (KvStateLookupResult) o; | ||
| return status == that.status && Arrays.equals(value, that.value); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return 31 * status.hashCode() + Arrays.hashCode(value); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "KvStateLookupResult{" | ||
| + "status=" | ||
| + status | ||
| + ", value=" | ||
| + Arrays.toString(value) | ||
| + '}'; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.