-
Notifications
You must be signed in to change notification settings - Fork 14.8k
KAFKA-19141; Persist topic id in OffsetCommit record #19683
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
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 |
|---|---|---|
|
|
@@ -517,7 +517,8 @@ public static CoordinatorRecord newOffsetCommitRecord( | |
| .setMetadata(offsetAndMetadata.metadata) | ||
| .setCommitTimestamp(offsetAndMetadata.commitTimestampMs) | ||
| // Version 1 has a non-empty expireTimestamp field | ||
| .setExpireTimestamp(offsetAndMetadata.expireTimestampMs.orElse(OffsetCommitRequest.DEFAULT_TIMESTAMP)), | ||
| .setExpireTimestamp(offsetAndMetadata.expireTimestampMs.orElse(OffsetCommitRequest.DEFAULT_TIMESTAMP)) | ||
| .setTopicId(offsetAndMetadata.topicId), | ||
| version | ||
| ) | ||
| ); | ||
|
|
@@ -527,9 +528,7 @@ static short offsetCommitValueVersion(boolean expireTimestampMs) { | |
| if (expireTimestampMs) { | ||
| return 1; | ||
| } else { | ||
| // Serialize with the highest supported non-flexible version | ||
| // until a tagged field is introduced or the version is bumped. | ||
| return 3; | ||
| return 4; | ||
|
Contributor
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. Wondering if we can use OffsetCommitValue.highestSupportedVersion here?
Member
Author
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. I prefer to use hard coded version here to ensure that they are not bumped unintentionally. This is what we have been doing for the other records too. |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,52 +16,69 @@ | |
| */ | ||
| package org.apache.kafka.coordinator.group; | ||
|
|
||
| import org.apache.kafka.common.Uuid; | ||
| import org.apache.kafka.common.message.OffsetCommitRequestData; | ||
| import org.apache.kafka.common.message.TxnOffsetCommitRequestData; | ||
| import org.apache.kafka.coordinator.group.generated.OffsetCommitValue; | ||
| import org.apache.kafka.server.util.MockTime; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| import java.util.OptionalInt; | ||
| import java.util.OptionalLong; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| public class OffsetAndMetadataTest { | ||
| @Test | ||
| public void testAttributes() { | ||
| Uuid topicId = Uuid.randomUuid(); | ||
| OffsetAndMetadata offsetAndMetadata = new OffsetAndMetadata( | ||
| 100L, | ||
| OptionalInt.of(10), | ||
| "metadata", | ||
| 1234L, | ||
| OptionalLong.of(5678L) | ||
| OptionalLong.of(5678L), | ||
| topicId | ||
| ); | ||
|
|
||
| assertEquals(100L, offsetAndMetadata.committedOffset); | ||
| assertEquals(OptionalInt.of(10), offsetAndMetadata.leaderEpoch); | ||
| assertEquals("metadata", offsetAndMetadata.metadata); | ||
| assertEquals(1234L, offsetAndMetadata.commitTimestampMs); | ||
| assertEquals(OptionalLong.of(5678L), offsetAndMetadata.expireTimestampMs); | ||
| assertEquals(topicId, offsetAndMetadata.topicId); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFromRecord() { | ||
| private static Stream<Uuid> uuids() { | ||
| return Stream.of( | ||
| Uuid.ZERO_UUID, | ||
| Uuid.randomUuid() | ||
| ); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("uuids") | ||
| public void testFromRecord(Uuid uuid) { | ||
| OffsetCommitValue record = new OffsetCommitValue() | ||
| .setOffset(100L) | ||
| .setLeaderEpoch(-1) | ||
| .setMetadata("metadata") | ||
| .setCommitTimestamp(1234L) | ||
| .setExpireTimestamp(-1L); | ||
| .setExpireTimestamp(-1L) | ||
| .setTopicId(uuid); | ||
|
Contributor
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. Just to confirm: when we read an older
Member
Author
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. Correct. It uses |
||
|
|
||
| assertEquals(new OffsetAndMetadata( | ||
| 10L, | ||
| 100L, | ||
| OptionalInt.empty(), | ||
| "metadata", | ||
| 1234L, | ||
| OptionalLong.empty() | ||
| OptionalLong.empty(), | ||
| uuid | ||
| ), OffsetAndMetadata.fromRecord(10L, record)); | ||
|
|
||
| record | ||
|
|
@@ -74,12 +91,14 @@ public void testFromRecord() { | |
| OptionalInt.of(12), | ||
| "metadata", | ||
| 1234L, | ||
| OptionalLong.of(5678L) | ||
| OptionalLong.of(5678L), | ||
| uuid | ||
| ), OffsetAndMetadata.fromRecord(11L, record)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFromRequest() { | ||
| @ParameterizedTest | ||
| @MethodSource("uuids") | ||
| public void testFromRequest(Uuid uuid) { | ||
| MockTime time = new MockTime(); | ||
|
|
||
| OffsetCommitRequestData.OffsetCommitRequestPartition partition = | ||
|
|
@@ -95,8 +114,10 @@ public void testFromRequest() { | |
| OptionalInt.empty(), | ||
| "", | ||
| time.milliseconds(), | ||
| OptionalLong.empty() | ||
| OptionalLong.empty(), | ||
| uuid | ||
| ), OffsetAndMetadata.fromRequest( | ||
| uuid, | ||
| partition, | ||
| time.milliseconds(), | ||
| OptionalLong.empty() | ||
|
|
@@ -113,8 +134,10 @@ public void testFromRequest() { | |
| OptionalInt.of(10), | ||
| "hello", | ||
| time.milliseconds(), | ||
| OptionalLong.empty() | ||
| OptionalLong.empty(), | ||
| uuid | ||
| ), OffsetAndMetadata.fromRequest( | ||
| uuid, | ||
| partition, | ||
| time.milliseconds(), | ||
| OptionalLong.empty() | ||
|
|
@@ -127,8 +150,10 @@ public void testFromRequest() { | |
| OptionalInt.of(10), | ||
| "hello", | ||
| time.milliseconds(), | ||
| OptionalLong.of(5678L) | ||
| OptionalLong.of(5678L), | ||
| uuid | ||
| ), OffsetAndMetadata.fromRequest( | ||
| uuid, | ||
| partition, | ||
| time.milliseconds(), | ||
| OptionalLong.of(5678L) | ||
|
|
@@ -153,7 +178,8 @@ public void testFromTransactionalRequest() { | |
| OptionalInt.empty(), | ||
| "", | ||
| time.milliseconds(), | ||
| OptionalLong.empty() | ||
| OptionalLong.empty(), | ||
| Uuid.ZERO_UUID | ||
| ), OffsetAndMetadata.fromRequest( | ||
| partition, | ||
| time.milliseconds() | ||
|
|
@@ -170,7 +196,8 @@ public void testFromTransactionalRequest() { | |
| OptionalInt.of(10), | ||
| "hello", | ||
| time.milliseconds(), | ||
| OptionalLong.empty() | ||
| OptionalLong.empty(), | ||
| Uuid.ZERO_UUID | ||
| ), OffsetAndMetadata.fromRequest( | ||
| partition, | ||
| time.milliseconds() | ||
|
|
||
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.
Should we update
offsetCommitValueVersionto return version 4 if topic id is present?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.
Good catch! I missed this.