-
Notifications
You must be signed in to change notification settings - Fork 462
[kv] Add an implementation of AutoIncIDBuffer #2161
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
45dc38a to
4d674d7
Compare
fluss-common/src/main/java/org/apache/fluss/metadata/Schema.java
Outdated
Show resolved
Hide resolved
fluss-common/src/test/java/org/apache/fluss/metadata/TableDescriptorTest.java
Outdated
Show resolved
Hide resolved
fluss-server/src/main/java/org/apache/fluss/server/kv/autoinc/SegmentIDGenerator.java
Outdated
Show resolved
Hide resolved
|
hi, I had created this Pr: #2119 for this issue. Do we want to prefer this one over that? |
|
Hi @vamossagar12 , we prefer this one to work on since it is more comprehensive. |
4d674d7 to
19d0475
Compare
19d0475 to
697dbcf
Compare
fluss-server/src/main/java/org/apache/fluss/server/utils/TableDescriptorValidation.java
Outdated
Show resolved
Hide resolved
fluss-common/src/main/java/org/apache/fluss/utils/json/ColumnJsonSerde.java
Outdated
Show resolved
Hide resolved
fluss-common/src/main/java/org/apache/fluss/config/ConfigOptions.java
Outdated
Show resolved
Hide resolved
| new Column( | ||
| column.getName(), | ||
| column.getDataType().copy(false), | ||
| column.getDataType().copy(true), |
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.
Partial update is required, so the data type here needs to be temporarily set to nullable.
fluss-server/src/main/java/org/apache/fluss/server/kv/autoinc/AutoIncProcessor.java
Outdated
Show resolved
Hide resolved
fluss-server/src/main/java/org/apache/fluss/server/zk/data/ZkData.java
Outdated
Show resolved
Hide resolved
platinumhamburg
left a comment
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.
@beryllw Thanks for contribution, I left some comments.
| * | ||
| * <p>/metadata/databases/[databaseName]/tables/[tableName]/auto_inc/col_[columnIdx] | ||
| */ | ||
| public static final class AutoIncrementColumnZNode { |
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.
Schema evolution (adding a column) is already supported; It would be better to use column IDs instead of column indices here.
| if (incrementValue.succeeded()) { | ||
| return incrementValue.preValue(); | ||
| } else { | ||
| throw new Exception("Failed to add sequence id counter."); |
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.
Perhaps we could make the exception information clearer—for example, by including the sequenceIDPath.
| int schemaId, | ||
| Configuration properties, | ||
| TableConfig tableConf, | ||
| Schema schema, |
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.
Use SchemaGetter instead of Schema.
| TableConfig tableConf, | ||
| Schema schema, | ||
| ZooKeeperClient zkClient) { | ||
| int[] autoIncColumnIndexes = schema.getAutoIncColumnIndexes(); |
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.
Use column IDs instead of column indices.
|
|
||
| /** | ||
| * Return row value. | ||
| * Returns the next auto increment column ID. |
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.
Consider renaming this method, as "column ID" is misleading and conflicts with the actual ID of a Column object, which can cause confusion. Moreover, while UID is one use case for auto-increment columns, it does not encompass all possible scenarios, so naming it with "ID" is not advisable.
| this.current = start; | ||
| } | ||
|
|
||
| public long remaining() { |
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 part is a bit confusing to me—the outer check already handles negative values, so the Math.max here seems like an unnecessary overhead.
| } | ||
|
|
||
| @Test | ||
| void testPutAutoIncColumnAndLookup() throws Exception { |
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.
To achieve more precise test assertions, I recommend explicitly creating a single-bucket table, writing multiple batches of data—some with duplicate primary keys and others with distinct primary keys—and then verifying that the auto-increment column behaves correctly.
| .longType() | ||
| .defaultValue(100000L) | ||
| .withDescription( | ||
| "The batch size of auto-increment IDs fetched from the distributed counter each time. This value determines the length of the ID segment cached locally. Default: 100000."); |
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.
New configuration options should be documented, including recommended values and a description of the behavioral impact associated with different settings.
| throws Exception { | ||
| walBuilder.append(ChangeType.INSERT, latestSchemaRow.replaceRow(currentValue.row)); | ||
| kvPreWriteBuffer.put(key, currentValue.encodeValue(), logOffset); | ||
| BinaryValue newValue = autoIncProcessor.processAutoInc(currentValue); |
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.
I've been wondering about the relationship between auto-increment column handling and the Merge Engine. I think they should probably be integrated in the design to avoid redundant encoding of row data, which would otherwise lead to significant performance overhead.
|
In addition to integration tests, I think we should also add several unit tests in KvTabletTest to cover behavior assertions after a TabletServer restart and after a single segment overflows. |
Purpose
Linked issue: close #2111
Brief change log
Tests
API and Format
Documentation