-
Notifications
You must be signed in to change notification settings - Fork 14.8k
MINOR: Update GroupCoordinator interface to received MetadataImage/Delta directly
#21008
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
| * This is initialised when the {@link GroupCoordinator#onMetadataUpdate(MetadataDelta, MetadataImage)} is called | ||
| */ | ||
| private CoordinatorMetadataImage metadataImage = null; | ||
| private volatile CoordinatorMetadataImage metadataImage = 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.
This is a bug. The attribute must be volatile because it is accessed from multiple threads.
| var wrappedImage = newImage == null ? null : new KRaftCoordinatorMetadataImage(newImage); | ||
| var wrappedDelta = delta == null ? null : new KRaftCoordinatorMetadataDelta(delta); |
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.
This is pretty ugly and it should not be here because the image and the delta can never be null. Unfortunately, we have a couple of tests passing nulls here. I will fix those separately and remove this code in a follow-up. I want the core change to be well scoped.
| metadataImage = new MetadataImageBuilder() | ||
| .addTopic(TOPIC_ID, TOPIC_NAME, 1) | ||
| .build(); |
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.
This change is semi-related. It is just easier to build the image rather than mocking it.
GroupCoordinator interface to received MetadataImage/Delta directly
squah-confluent
left a comment
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.
Refactor looks good to me
lianetm
left a comment
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.
Nice refactoring, makes sense to me. Just a nit.
| var wrappedImage = newImage == null ? null : new KRaftCoordinatorMetadataImage(newImage); | ||
| var wrappedDelta = delta == null ? null : new KRaftCoordinatorMetadataDelta(delta); | ||
| metadataImage = wrappedImage; | ||
| runtime.onNewMetadataImage(wrappedImage, wrappedDelta); |
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.
do we want to rename this on the CoordinatorRuntime to onNewMetadataUpdate for consistency?
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.
done.
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.
Our parameter order isn't consistent. We have one onNewMetadataUpdate definition take (delta, image) and the other take (image, delta).
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.
addressed it.
lianetm
left a comment
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! LGTM.
chia7712
left a comment
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.
@dajac thanks for this refacor. I have just posted some review comments. Sorry for the delay
| throwIfNotActive(); | ||
| metadataImage = newImage; | ||
| runtime.onNewMetadataImage(newImage, delta); | ||
| var wrappedImage = newImage == null ? null : new KRaftCoordinatorMetadataImage(newImage); |
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.
Can the image be null? Since a null wrappedImage causes an NPE in CoordinatorRuntime#onMetadataUpdate, if null input is allowed, we should implement a fast-fail
Line 2546 in ed3af72
| log.debug("Scheduling applying of a new metadata image with version {}.", newImage.version()); |
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.
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.
Sorry for neglecting the previous comment. Sounds good
| CoordinatorMetadataImage newImage, | ||
| CoordinatorMetadataDelta delta | ||
| public void onMetadataUpdate( | ||
| CoordinatorMetadataDelta delta, |
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 the ShareCoordinator also be updated with this change?
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.
From the description:
It does not change the
ShareCoordinator yet. I will do this as a follow-up if people agree
with the general approach
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.
if people agree with the general approach
If the interfaces CoordinatorMetadataImage and CoordinatorMetadataDelta are not referenced by ShareCoordinator or GroupCoordinator, can we remove them by using record class to rewrite them
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.
They are still used by other interfaces so I prefer to keep them as interfaces.
…/Delta` directly (apache#21008) In apache#20061, we introduced the `CoordinatorMetadataImage` and `CoordinatorMetadataDelta` interfaces to basically contain/control how metadata is used within the `GroupCoordinatorService`, more precisely within the `GroupCoordinatorShard`. When we did the change, we directly changed the `GroupCoordinator` interface to take implementation of those interfaces, requiring to wrap the `MetadataImage` and the `MetadataDelta` in the `BrokerMetadataPublisher`. While looking at it now, I find this not idea for a couple a reasons: 1) From a `BrokerMetadataPublisher` perspective, propagating metadata should be standardized. Basically, all the internal components should work the same from his point of view. If a component wants to be more restrictive within his scope, it is fine but the publisher should not be aware of this. 2) From a `GroupCoordinator` perspective, requiring `CoordinatorMetadataImage` and `CoordinatorMetadataDelta` limits what we can do. For instance, we could move more functionality such as electing shards from the `BrokerMetadataPublisher` to the `GroupCoordinatorService` to further simplify the metadata publishing and improving the encapsulation of the components. 3) From a `ShareCoordinator` perspective, the abstraction failed short as we require `CoordinatorMetadataImage` and `CoordinatorMetadataDelta` in the interface but we still require `FeaturesImage` as well. The abstraction fails short here. This patch is an attempt to change this by moving back to requiring `MetadataImage` and `MetadataDelta` in the `GroupCoordinator` interface and to wrap them within the service itself. It does not change the `ShareCoordinator` yet. I will do this as a follow-up if people agree with the general approach. Reviewers: Sean Quah <squah@confluent.io>, Lianet Magrans <lmagrans@confluent.io>
In #20061, we introduced the
CoordinatorMetadataImageandCoordinatorMetadataDeltainterfaces tobasically contain/control how metadata is used within the
GroupCoordinatorService, more precisely within theGroupCoordinatorShard. When we did the change, we directly changed theGroupCoordinatorinterface to take implementation of those interfaces,requiring to wrap the
MetadataImageand theMetadataDeltain theBrokerMetadataPublisher. While looking at it now, I find this not ideafor a couple a reasons:
BrokerMetadataPublisherperspective, propagating metadatashould be standardized. Basically, all the internal components should
work the same from his point of view. If a component wants to be more
restrictive within his scope, it is fine but the publisher should not be
aware of this.
GroupCoordinatorperspective, requiringCoordinatorMetadataImageandCoordinatorMetadataDeltalimits what wecan do. For instance, we could move more functionality such as electing
shards from the
BrokerMetadataPublisherto theGroupCoordinatorServiceto further simplify the metadata publishingand improving the encapsulation of the components.
ShareCoordinatorperspective, the abstraction failed shortas we require
CoordinatorMetadataImageandCoordinatorMetadataDeltain the interface but we still require
FeaturesImageas well. Theabstraction fails short here.
This patch is an attempt to change this by moving back to requiring
MetadataImageandMetadataDeltain theGroupCoordinatorinterfaceand to wrap them within the service itself. It does not change the
ShareCoordinatoryet. I will do this as a follow-up if people agreewith the general approach.
Reviewers: Sean Quah squah@confluent.io, Lianet Magrans
lmagrans@confluent.io