-
Notifications
You must be signed in to change notification settings - Fork 490
[lake] Fix lake encoder causing prefix lookup to miss data when bucket key is a subset of primary key #2464
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?
Conversation
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.
Pull request overview
This PR implements backward compatibility support for key encoding in data lake tables, preventing old clients from accessing new tables that use incompatible encoding strategies.
Changes:
- Introduces API version validation for KV operations (PUT_KV, LOOKUP, PREFIX_LOOKUP) to reject old clients (version 0) when accessing new format tables
- Refactors KeyEncoder with separate factory methods for primary key encoding and bucket key encoding to support different encoding strategies
- Adds kv format version 2 configuration that automatically applies to new primary key tables
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| fluss-rpc/src/main/java/org/apache/fluss/rpc/protocol/ApiKeys.java | Bumps API versions for PUT_KV, LOOKUP, and PREFIX_LOOKUP from 0 to 1 |
| fluss-server/src/main/java/org/apache/fluss/server/replica/ReplicaManager.java | Adds client version validation for KV operations and updates method signatures |
| fluss-server/src/main/java/org/apache/fluss/server/tablet/TabletService.java | Passes API version from session to ReplicaManager operations |
| fluss-server/src/main/java/org/apache/fluss/server/replica/Replica.java | Adds tableInfo field to enable version validation |
| fluss-common/src/main/java/org/apache/fluss/row/encode/KeyEncoder.java | Splits key encoding into primary key and bucket key factory methods |
| fluss-common/src/main/java/org/apache/fluss/config/ConfigOptions.java | Adds TABLE_KV_FORMAT_VERSION configuration option |
| fluss-common/src/main/java/org/apache/fluss/config/TableConfig.java | Adds getKvFormatVersion() method |
| fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorService.java | Automatically sets kv format version 2 for new primary key tables |
| fluss-server/src/main/java/org/apache/fluss/server/kv/KvRecoverHelper.java | Updates to use new primary key encoder factory method |
| fluss-client/src/main/java/org/apache/fluss/client/table/writer/* | Updates UpsertWriter and AppendWriter to use new encoder factory methods |
| fluss-client/src/main/java/org/apache/fluss/client/lookup/* | Updates PrimaryKeyLookuper and PrefixKeyLookuper to use new encoder factory methods |
| fluss-server/src/test/java/.../ReplicaManagerTest.java | Adds test for old client version rejection and updates existing tests |
| fluss-client/src/test/java/.../FlussLakeTableITCase.java | Adds backward compatibility test for legacy tables |
| fluss-lake/.../FlinkUnionReadPrimaryKeyTableITCase.java | Adds test for non-default bucket key table union read |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fluss-client/src/test/java/org/apache/fluss/client/table/FlussLakeTableITCase.java
Outdated
Show resolved
Hide resolved
fluss-server/src/main/java/org/apache/fluss/server/replica/ReplicaManager.java
Outdated
Show resolved
Hide resolved
fluss-server/src/test/java/org/apache/fluss/server/replica/ReplicaManagerTest.java
Outdated
Show resolved
Hide resolved
fluss-server/src/main/java/org/apache/fluss/server/coordinator/CoordinatorService.java
Outdated
Show resolved
Hide resolved
fluss-common/src/main/java/org/apache/fluss/config/ConfigOptions.java
Outdated
Show resolved
Hide resolved
fluss-client/src/test/java/org/apache/fluss/client/table/FlussTableITCase.java
Show resolved
Hide resolved
a83dbe7 to
0bd719e
Compare
0bd719e to
297764b
Compare
|
@wuchong Could you please help review when you got some time? |
Purpose
Linked issue: close #1412
Fix lake encoder causing prefix lookup to miss data when bucket key is a subset of primary key.
When a primary key table has a non-default bucket key (bucket key is a subset of primary key), the previous implementation used lake's encoder (e.g., Paimon) to encode the primary key. However, lake encoders like Paimon store strings longer than 7 characters in a variable-length area, which breaks prefix lookup because the encoded bucket key bytes are no longer a prefix of the encoded primary key bytes.
Brief change log
This PR:
Tests
Also verify the back compatibility:
UnsupportedVersionExceptionis thrownAPI and Format
Added new config option TABLE_KV_FORMAT_VERSION to track table's kv encoding format version.
Documentation