Skip to content
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

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

brandboat
Copy link
Member

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)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@github-actions github-actions bot added the tools label Jan 13, 2025
Copy link
Contributor

@m1a2st m1a2st left a 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";
Copy link
Contributor

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.

Copy link
Member Author

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);
Copy link
Contributor

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:

  1. Move keyVersion out of the abstract definition
  2. Provide a default implementation in the base class

WDYT?

Copy link
Member Author

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!

Copy link
Contributor

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)

Copy link
Member Author

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.

@dajac
Copy link
Member

dajac commented Jan 24, 2025

@brandboat What do you think about this one: #18695?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants