Skip to content

MINOR: Refactor the MetadataPublisher interface#13337

Merged
cmccabe merged 5 commits intoapache:trunkfrom
cmccabe:cmccabe_2023-03-03_refactor_metadatapublisher
Mar 9, 2023
Merged

MINOR: Refactor the MetadataPublisher interface#13337
cmccabe merged 5 commits intoapache:trunkfrom
cmccabe:cmccabe_2023-03-03_refactor_metadatapublisher

Conversation

@cmccabe
Copy link
Copy Markdown
Contributor

@cmccabe cmccabe commented Mar 3, 2023

This PR refactors MetadataPublisher's interface a bit. There is now a handleControllerChange callback. This is something that some publishers might want. A good example is ZkMigrationClient.

There is now only a single publish() function rather than a separate function for publishing snapshots and log deltas. Most publishers didn't want to do anything different in those two cases. The ones that do want to do something different for snapshots can always check the manifest type.

The close function now has a default empty implementation, since most publishers didn't need to do anything there.

This PR refactors MetadataPublisher's interface a bit. There is now a handleControllerChange
callback. This is something that some publishers might want. A good example is ZkMigrationClient.

There is now only a single publish() function rather than a separate function for publishing
snapshots and log deltas. Most publishers didn't want to do anything different in those two cases.
The ones that do want to do something different for snapshots can always check the manifest type.

The close function now has a default empty implementation, since most publishers didn't need to do
anything there.
@cmccabe
Copy link
Copy Markdown
Contributor Author

cmccabe commented Mar 7, 2023

rebase on trunk

@cmccabe cmccabe force-pushed the cmccabe_2023-03-03_refactor_metadatapublisher branch from f563a51 to 3e96b22 Compare March 7, 2023 21:36
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any way to avoid this null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this have the override annotation?

MetadataImage newImage,
SnapshotManifest manifest
);
default void handleControllerChange(LeaderAndEpoch newLeaderAndEpoch) { }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: "publishControllerChange" to keep the naming consistent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How about
void onControllerChange(LeaderAndEpoch newLeaderAndEpoch)
and
void onMetadataUpdate(MetadataDelta delta, MetadataImage newImage, LoaderManifest manifest);?
Might be clearer.

/**
* Contains information about what was loaded.
*/
public interface LoaderManifest {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why can't we include the manifest type in the MetadataProvenance?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We need a type to represent the 3-tuple of (offset, epoch, timestamp) since that comes up in many places. I agree that conceptually whether it came from a snapshot or a log is part of the "provenance", but I think it would be ugly in code terms to start putting stuff from the manifest into MetadataProvenance.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, fair enough. Works for me 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Option[LoaderManifest] since it is optional?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@cmccabe cmccabe force-pushed the cmccabe_2023-03-03_refactor_metadatapublisher branch from da9a24d to cd5d2fd Compare March 9, 2023 17:58
@cmccabe
Copy link
Copy Markdown
Contributor Author

cmccabe commented Mar 9, 2023

I fixed the case where I was invoking DynamicConfigPublisher.publish with a null. This was a bit silly... I was just being lazy about adding an extra function.

I also fixed it so that BrokerMetadataPublisher is using DynamicClientQuotaPublisher and ScramPublisher. Ultimately this code should be the same on the broker and controller, just invoked slightly differently. (I have a follow-up change which will use Loader on the broker too, which will simplify this more.)

Copy link
Copy Markdown
Member

@mumrah mumrah left a comment

Choose a reason for hiding this comment

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

Thanks @cmccabe, the changes look good. I left a few nitpicks

/**
* Contains information about what was loaded.
*/
public interface LoaderManifest {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, fair enough. Works for me 👍

Comment on lines +458 to +459
"change to " + currentLeaderAndEpoch + " with publisher " +
publisher.name(), e);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit; tabs

LoaderManifest manifest
) {
enqueueMetadataChangeEvent(delta,
newImage,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: tabs

publishSnapshot(delta, newImage, (SnapshotManifest) manifest);
break;
default:
break;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

wdyt about throwing an IllegalStateException in the default. I do that sometimes to future-proof against unhandled enums down the road.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, let's just remove the default case. spotbugs will flag non-exhaustive switch statements on enums. And that's a hard build error for us.

Copy link
Copy Markdown
Contributor

@rondagostino rondagostino left a comment

Choose a reason for hiding this comment

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

LGTM

}
}
}
// APply SCRAM delta.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: s/AP/Ap/

@rondagostino
Copy link
Copy Markdown
Contributor

Looks like compile failures in BrokerMetadataPublisherTest.scala

@cmccabe cmccabe merged commit aaa976a into apache:trunk Mar 9, 2023
@cmccabe cmccabe deleted the cmccabe_2023-03-03_refactor_metadatapublisher branch March 9, 2023 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants