-
Notifications
You must be signed in to change notification settings - Fork 14.3k
KAFKA-18409: ShareGroupStateMessageFormatter should use CoordinatorRecordMessageFormatter #18510
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
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.
Thanks for the PR, left few comments. PTAL
@@ -38,7 +38,7 @@ public abstract class ApiMessageFormatter implements MessageFormatter { | |||
private static final String DATA = "data"; | |||
private static final String KEY = "key"; | |||
private static final String VALUE = "value"; | |||
static final String UNKNOWN = "unknown"; | |||
public static final String UNKNOWN = "unknown"; |
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 think we should use the modifier protected
.
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.
Sure, thanks.
@@ -79,5 +79,5 @@ public void writeTo(ConsumerRecord<byte[], byte[]> consumerRecord, PrintStream o | |||
} | |||
|
|||
protected abstract JsonNode readToKeyJson(ByteBuffer byteBuffer); | |||
protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer); | |||
} | |||
protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer, short keyVersion); |
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.
Since the keyVersion
parameter is only used by the ShareGroupStateMessageFormatter
class, we should refactor this to make the method less abstract. Instead of requiring all subclasses to implement the keyVersion parameter, we could:
- Move keyVersion out of the abstract definition
- Provide a default implementation in the base class
WDYT?
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.
Yes, I've thought about that before, but that means we need to add below methods to ApiMessageFormatter.java
.
protected abstract JsonNode readToValueJson(ByteBuffer byteBuffer);
protected JsonNode readToValueJson(ByteBuffer byteBuffer, short keyVersion) {
return readToValueJson(byteBuffer);
}
But doing that means I need to override two methods in ShareGroupStateMessageFormatter.java, particularly readToValueJson(ByteBuffer byteBuffer). This method will essentially be a dummy method, which feels somewhat awkward to implement, so I decided to add an extra parameter to it instead.
@Override
protected JsonNode readToValueJson(ByteBuffer byteBuffer, short keyVersion) {
short valueVersion = byteBuffer.getShort();
return readToSnapshotMessageValue(byteBuffer, keyVersion, valueVersion)
.map(logValue -> transferValueMessageToJsonNode(logValue, valueVersion))
.orElseGet(() -> new TextNode(UNKNOWN));
}
@Override
protected JsonNode readToValueJson(ByteBuffer byteBuffer) {
return null;
}
Or you have other ideas? Let me know if you'd like any further adjustments!
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 propose changing the JsonNode readToValueJson
signature to accept a ConsumerRecord<byte[], byte[]>
parameter. This would standardize the method signature across all subclasses. WDYT?
protected JsonNode readToValueJson(ConsumerRecord<byte[], byte[]> consumerRecord)
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.
Not sure if this is a good idea, perhaps we can wait for others opinion.
key should not be converted to unknow json node
@brandboat What do you think about this one: #18695? |
I think this is a better approach. The entire refactor looks great to me. I'll hold off on this PR until #18695 is merged. Thank you for letting me know! |
@brandboat We have merged #18695. We can proceed with your PR. Please ping me when the PR is ready for review. |
Thanks for the heads-up, I'll handle this ASAP! |
Gentle ping @dajac, CI passed, could you take a look when you are available? Thank you! |
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.
@brandboat Thanks for the update. I left a few initial comments.
@@ -137,23 +137,23 @@ private static Stream<Arguments> parameters() { | |||
Arguments.of( | |||
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_SNAPSHOT_KEY).array(), | |||
MessageUtil.toVersionPrefixedByteBuffer((short) 0, SHARE_SNAPSHOT_VALUE).array(), | |||
"{\"key\":{\"version\":0,\"data\":{\"groupId\":\"gs1\",\"topicId\":\"gtb2stGYRk-vWZ2zAozmoA\",\"partition\":0}},\"value\":{\"version\":0,\"data\":{\"snapshotEpoch\":0,\"stateEpoch\":1,\"leaderEpoch\":20,\"startOffset\":50,\"stateBatches\":[{\"firstOffset\":100,\"lastOffset\":200,\"deliveryState\":1,\"deliveryCount\":10},{\"firstOffset\":201,\"lastOffset\":210,\"deliveryState\":2,\"deliveryCount\":10}]}}}" | |||
"{\"key\":{\"type\":0,\"data\":{\"groupId\":\"gs1\",\"topicId\":\"gtb2stGYRk-vWZ2zAozmoA\",\"partition\":0}},\"value\":{\"version\":0,\"data\":{\"snapshotEpoch\":0,\"stateEpoch\":1,\"leaderEpoch\":20,\"startOffset\":50,\"stateBatches\":[{\"firstOffset\":100,\"lastOffset\":200,\"deliveryState\":1,\"deliveryCount\":10},{\"firstOffset\":201,\"lastOffset\":210,\"deliveryState\":2,\"deliveryCount\":10}]}}}" |
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.
nit: Would it be possible to use the new test blocks like we did for the other formatters?
new RuntimeException("non-nullable field stateBatches was serialized as null") | ||
new RuntimeException("Could not read record at offset 0 due to: " + | ||
"Could not read record with version 0 from value's buffer due to: " + | ||
"non-nullable field stateBatches was serialized as null.") | ||
) | ||
); | ||
} |
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.
Could we remove testShareGroupStateMessageFormatter
? We have it in the parent class now.
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.
Thank you! I've addressed all the comments!
@brandboat It looks like https://github.com/apache/kafka/pull/18510/files#r2019007145 has not been addressed yet. Could you please address it? |
My apologies, I've replaced all long string in the test with text blocks. |
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.
lgtm, thanks
…cordMessageFormatter (apache#18510) ShareGroupStateMessageFormatter should extend CoordinatorRecordMessageFormatter in order to have a consistent handling of records of coordinators. Reviewers: Ken Huang <[email protected]>, David Jacot <[email protected]>
ShareGroupStateMessageFormatter should extend CoordinatorRecordMessageFormatter in order to have a consistent handling of records of coordinators.
Reviewers: Ken Huang [email protected], David Jacot [email protected]