-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
KAFKA-18409: ShareGroupStateMessageFormatter should use ApiMessageFormatter #18510
base: trunk
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.
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? |
related to https://issues.apache.org/jira/browse/KAFKA-18409
ShareGroupStateMessageFormatter should extend ApiMessageFormatter in order to have a consistent handling of records of coordinators.
Committer Checklist (excluded from commit message)