Skip to content

Conversation

see-quick
Copy link
Contributor

@see-quick see-quick commented Sep 3, 2025

This PR moves the ScramPublisher class from the server metadata package
to the dedicated metadata module. During refactoring, I found out that I
also need to move the CredentialProvider interface to a more appropriate
location in the server common package because CredentialProvider is in
the server module, and I can't include that module in the metadata
because I would create a circular dependency, i.e.,

server module ←-------------┐ ↓ (depends on). │
(which would make it circular) metadata module------------┘

So I have moved CredentialProvider to server-common module, and
metadata module has already server-common and thus it's resolved.

Reviewers: Mickael Maison mickael.maison@gmail.com

Signed-off-by: see-quick <maros.orsak159@gmail.com>
Signed-off-by: see-quick <maros.orsak159@gmail.com>
Signed-off-by: see-quick <maros.orsak159@gmail.com>
@github-actions github-actions bot added triage PRs from the community core Kafka Broker kraft labels Sep 3, 2025
@showuon showuon self-assigned this Sep 4, 2025
@see-quick see-quick changed the title KAFKA-18704: Move ScramPublisher to metadata module KAFKA-18706: Move ScramPublisher to metadata module Sep 4, 2025
Copy link
Member

@mimaison mimaison 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. I left a few comments

@github-actions github-actions bot removed the triage PRs from the community label Sep 6, 2025
Signed-off-by: see-quick <maros.orsak159@gmail.com>
Signed-off-by: see-quick <maros.orsak159@gmail.com>
… admins scramMechanism)

Signed-off-by: see-quick <maros.orsak159@gmail.com>
if (scramDelta != null) {
scramDelta.changes().forEach((mechanism, userChanges) -> {
userChanges.forEach((userName, change) -> {
ScramMechanism internalMechanism = ScramMechanism.forMechanismName(mechanism.mechanismName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed?

Copy link
Contributor Author

@see-quick see-quick Sep 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ScramMechanism.forMechanismName returns org.apache.kafka.common.security.scram.internals.ScramMechanism and CredentialProvider methods, i.e., removeCredential and updateCredential need org.apache.kafka.common.security.scram.internals.ScramMechanism type instead of org.apache.kafka.clients.admin.ScramMechanism.

scramDelta.changes() using org.apache.kafka.clients.admin.ScramMechanism. That's why I have added that here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we keep the existing types. Let's focus this PR on the Scala to Java conversion.

If you think you can do further refactoring, we should do that in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we keep the existing types. Let's focus this PR on the Scala to Java conversion.

Updated.

Signed-off-by: see-quick <maros.orsak159@gmail.com>
@see-quick
Copy link
Contributor Author

FYI: Those failed tests are not related to PR.

Copy link
Member

@mimaison mimaison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mimaison mimaison changed the title KAFKA-18706: Move ScramPublisher to metadata module KAFKA-18708: Move ScramPublisher to metadata module Sep 10, 2025
@mimaison mimaison merged commit a244565 into apache:trunk Sep 10, 2025
33 of 37 checks passed
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@see-quick thanks for this patch. Sorry for leaving some comments on this merged PR

}

public void onMetadataUpdate(MetadataDelta delta, MetadataImage newImage) {
String deltaName = "MetadataDelta up to " + newImage.highestOffsetAndEpoch().offset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please create this variable in the catch block? It is only used by the error handler.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the PR comparing line by line with the Scala code which had that as well. Not a big deal but we can indeed move that into the catch block.

Looking at the catch block, I wonder if we should have one in FeaturesPublisher. At a glance, it seems metadataVersionOrThrow() could throw, or it's terribly named!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the catch block, I wonder if we should have one in FeaturesPublisher. At a glance, it seems metadataVersionOrThrow() could throw, or it's terribly named!

I prefer to let the caller handle the exception if all FeaturesPublisher does is call faultHandler.handleFault

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point was consistency. Maybe there's an explanation but looking at these classes they all catch Throwable and run faultHandler.handleFault() apart from FeaturesPublisher

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mimaison you are right. +1 to add catch to FeaturesPublisher

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onMetadataUpdate(delta, newImage);
}

public void onMetadataUpdate(MetadataDelta delta, MetadataImage newImage) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need the onMetadataUpdate(MetadataDelta, MetadataImage) method. It is only used by BrokerMetadataPublisher#onMetadataUpdate, but we could just call onMetadataUpdate(MetadataDelta, MetadataImage, LoaderManifest) instead

@see-quick @mimaison WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree I'm not sure why we have onMetadataUpdate(MetadataDelta, MetadataImage). It seems all the callers have a LoaderManifest instance so they could, and probably should, use onMetadataUpdate(MetadataDelta, MetadataImage, LoaderManifest).

I prefer keeping the code "as is" for the Java to Scala conversion. We can tackle this type of refactorings in follow up PRs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the case across most (all?) the *Publisher classes. So maybe a PR (or set of PRs) addressing them all together would make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe a PR (or set of PRs) addressing them all together would make sense.

+1 to "a PR"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will take a look at that and address those issues in the next PR :) Thanks @chia7712 @mimaison.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am considering updating this after all publisher classes have been converted to Java. Or?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could fix the ScramPublisher in PR#20522 and leave the other publishers for the migration :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could fix the ScramPublisher in PR#20522 and leave the other publishers for the migration :)

Yeah, that's a good idea. Will do.

chia7712 pushed a commit that referenced this pull request Sep 12, 2025
This PR is a follow-up from #20468.
Basically makes two things:
1. Moves the variable to the catch block as it is used only there.
2. Refactor FeaturesPublisher to handle exceptions the same as
ScramPublisher or other publishers :)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>

---------

Signed-off-by: see-quick <maros.orsak159@gmail.com>
jim0987795064 pushed a commit to jim0987795064/kafka that referenced this pull request Sep 25, 2025
This PR is a follow-up from apache#20468.
Basically makes two things:
1. Moves the variable to the catch block as it is used only there.
2. Refactor FeaturesPublisher to handle exceptions the same as
ScramPublisher or other publishers :)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>

---------

Signed-off-by: see-quick <maros.orsak159@gmail.com>
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.

4 participants