-
Notifications
You must be signed in to change notification settings - Fork 14.8k
KAFKA-19817 Move DynamicTopicClusterQuotaPublisher to metadata module #20783
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
base: trunk
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.metadata.publisher; | ||
|
|
||
| import org.apache.kafka.common.Cluster; | ||
| import org.apache.kafka.image.MetadataDelta; | ||
| import org.apache.kafka.image.MetadataImage; | ||
| import org.apache.kafka.image.loader.LoaderManifest; | ||
| import org.apache.kafka.image.publisher.MetadataPublisher; | ||
| import org.apache.kafka.metadata.MetadataCache; | ||
| import org.apache.kafka.server.fault.FaultHandler; | ||
|
|
||
| public class DynamicTopicClusterQuotaPublisher implements MetadataPublisher { | ||
| private final String clusterId; | ||
| private final Integer nodeId; | ||
| private final FaultHandler faultHandler; | ||
| private final String nodeType; | ||
| private final QuotaManagersProvider quotaManagersProvider; | ||
|
|
||
| public DynamicTopicClusterQuotaPublisher( | ||
| String clusterId, | ||
| Integer nodeId, | ||
| FaultHandler faultHandler, | ||
| String nodeType, | ||
| QuotaManagersProvider quotaManagers | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you consider de-coupling those components by using lambda function? for example: public DynamicTopicClusterQuotaPublisher(
String clusterId,
int nodeId,
FaultHandler faultHandler,
String nodeType,
Plugin<ClientQuotaCallback> clientQuotaCallbackPlugin,
Runnable updateQuotaMetricConfigs
) {
this.clusterId = clusterId;
this.nodeId = nodeId;
this.faultHandler = faultHandler;
this.nodeType = nodeType;
this.clientQuotaCallbackPlugin = clientQuotaCallbackPlugin;
this.updateQuotaMetricConfigs = updateQuotaMetricConfigs;
}
@Override
public String name() {
return "DynamicTopicClusterQuotaPublisher " + nodeType + " id=" + nodeId;
}
@Override
public void onMetadataUpdate(MetadataDelta delta, MetadataImage newImage, LoaderManifest manifest) {
try {
if (delta.topicsDelta() != null || delta.clusterDelta() != null) {
Cluster cluster = MetadataCache.toCluster(clusterId, newImage);
if (clientQuotaCallbackPlugin.get().updateClusterMetadata(cluster)) {
updateQuotaMetricConfigs.run();
}
}
} catch (Exception e) {
String deltaName = "MetadataDelta up to " + newImage.highestOffsetAndEpoch().offset();
faultHandler.handleFault("Uncaught exception while publishing dynamic topic or cluster changes from " + deltaName, e);
}
}
@JimmyWang6 WDYT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @chia7712 , public class DynamicTopicClusterQuotaPublisher implements MetadataPublisher {
private final FaultHandler faultHandler;
private final String nodeType;
private final Runnable updateQuotaMetricConfigs;
public DynamicTopicClusterQuotaPublisher(
FaultHandler faultHandler,
String nodeType,
Runnable updateQuotaMetricConfigs
) {
this.faultHandler = faultHandler;
this.nodeType = nodeType;
this.updateQuotaMetricConfigs = updateQuotaMetricConfigs;
}
@Override
public String name() {
return "DynamicTopicClusterQuotaPublisher " + nodeType;
}
@Override
public void onMetadataUpdate(MetadataDelta delta, MetadataImage newImage, LoaderManifest manifest) {
try {
if (delta.topicsDelta() != null || delta.clusterDelta() != null) {
updateQuotaMetricConfigs.run();
}
} catch (Exception e) {
String deltaName = "MetadataDelta up to " + newImage.highestOffsetAndEpoch().offset();
faultHandler.handleFault("Uncaught exception while publishing dynamic topic or cluster changes from " + deltaName, e);
}
}
}And the logic of the original
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes but |
||
| ) { | ||
| this.clusterId = clusterId; | ||
| this.nodeId = nodeId; | ||
| this.faultHandler = faultHandler; | ||
| this.nodeType = nodeType; | ||
| this.quotaManagersProvider = quotaManagers; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "DynamicTopicClusterQuotaPublisher " + nodeType + " id=" + nodeId; | ||
| } | ||
|
|
||
| @Override | ||
| public void onMetadataUpdate(MetadataDelta delta, MetadataImage newImage, LoaderManifest manifest) { | ||
| onMetadataUpdate(delta, newImage); | ||
| } | ||
|
|
||
| public void onMetadataUpdate(MetadataDelta delta, MetadataImage newImage) { | ||
JimmyWang6 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| quotaManagersProvider.clientQuotaCallbackPlugin().ifPresent(plugin -> { | ||
| if (delta.topicsDelta() != null || delta.clusterDelta() != null) { | ||
| Cluster cluster = MetadataCache.toCluster(clusterId, newImage); | ||
| if (plugin.get().updateClusterMetadata(cluster)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The necessity of this method is being discussed in KIP-1200. While I hope the vote succeeds, there is no harm in migrating the code though |
||
| quotaManagersProvider.fetch().updateQuotaMetricConfigs(); | ||
| quotaManagersProvider.produce().updateQuotaMetricConfigs(); | ||
| quotaManagersProvider.request().updateQuotaMetricConfigs(); | ||
| quotaManagersProvider.controllerMutation().updateQuotaMetricConfigs(); | ||
| } | ||
| } | ||
| }); | ||
| } catch (Exception e) { | ||
| String deltaName = "MetadataDelta up to " + newImage.highestOffsetAndEpoch().offset(); | ||
| faultHandler.handleFault("Uncaught exception while publishing dynamic topic or cluster changes from " + deltaName, e); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.metadata.publisher; | ||
|
|
||
| import org.apache.kafka.common.internals.Plugin; | ||
| import org.apache.kafka.server.quota.ClientQuotaCallback; | ||
| import org.apache.kafka.server.quota.ClientQuotaManager; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| /** | ||
| * Interface to provide access to quota managers for metadata publishers. | ||
| * This abstraction allows the metadata module to access quota managers without | ||
| * directly depending on the core module. | ||
| */ | ||
| public interface QuotaManagersProvider { | ||
| ClientQuotaManager fetch(); | ||
|
|
||
| ClientQuotaManager produce(); | ||
|
|
||
| ClientQuotaManager request(); | ||
|
|
||
| ClientQuotaManager controllerMutation(); | ||
|
|
||
| Optional<Plugin<ClientQuotaCallback>> clientQuotaCallbackPlugin(); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.