-
Notifications
You must be signed in to change notification settings - Fork 15.4k
MINOR: add the MetaLogListener, LocalLogManager, and Controller interface. #10106
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180 changes: 180 additions & 0 deletions
180
metadata/src/main/java/org/apache/kafka/controller/Controller.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| /* | ||
| * 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.controller; | ||
|
|
||
| import org.apache.kafka.clients.admin.AlterConfigOp; | ||
| import org.apache.kafka.common.config.ConfigResource; | ||
| import org.apache.kafka.common.message.AlterIsrRequestData; | ||
| import org.apache.kafka.common.message.AlterIsrResponseData; | ||
| import org.apache.kafka.common.message.BrokerHeartbeatRequestData; | ||
| import org.apache.kafka.common.message.BrokerRegistrationRequestData; | ||
| import org.apache.kafka.common.message.CreateTopicsRequestData; | ||
| import org.apache.kafka.common.message.CreateTopicsResponseData; | ||
| import org.apache.kafka.common.message.ElectLeadersRequestData; | ||
| import org.apache.kafka.common.message.ElectLeadersResponseData; | ||
| import org.apache.kafka.common.quota.ClientQuotaAlteration; | ||
| import org.apache.kafka.common.quota.ClientQuotaEntity; | ||
| import org.apache.kafka.common.requests.ApiError; | ||
| import org.apache.kafka.metadata.BrokerHeartbeatReply; | ||
| import org.apache.kafka.metadata.BrokerRegistrationReply; | ||
| import org.apache.kafka.metadata.FeatureMapAndEpoch; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Map; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
|
|
||
| public interface Controller extends AutoCloseable { | ||
| /** | ||
| * Change the in-sync replica sets for some partitions. | ||
| * | ||
| * @param request The AlterIsrRequest data. | ||
| * | ||
| * @return A future yielding the response. | ||
| */ | ||
| CompletableFuture<AlterIsrResponseData> alterIsr(AlterIsrRequestData request); | ||
|
|
||
| /** | ||
| * Create a batch of topics. | ||
| * | ||
| * @param request The CreateTopicsRequest data. | ||
| * | ||
| * @return A future yielding the response. | ||
| */ | ||
| CompletableFuture<CreateTopicsResponseData> | ||
| createTopics(CreateTopicsRequestData request); | ||
|
|
||
| /** | ||
| * Unregister a broker. | ||
| * | ||
| * @param brokerId The broker id to unregister. | ||
| * | ||
| * @return A future that is completed successfully when the broker is | ||
| * unregistered. | ||
| */ | ||
| CompletableFuture<Void> unregisterBroker(int brokerId); | ||
|
|
||
| /** | ||
| * Describe the current configuration of various resources. | ||
| * | ||
| * @param resources A map from resources to the collection of config keys that we | ||
| * want to describe for each. If the collection is empty, then | ||
| * all configuration keys will be described. | ||
| * | ||
| * @return | ||
| */ | ||
| CompletableFuture<Map<ConfigResource, ResultOrError<Map<String, String>>>> | ||
| describeConfigs(Map<ConfigResource, Collection<String>> resources); | ||
|
|
||
| /** | ||
| * Elect new partition leaders. | ||
| * | ||
| * @param request The request. | ||
| * | ||
| * @return A future yielding the elect leaders response. | ||
| */ | ||
| CompletableFuture<ElectLeadersResponseData> electLeaders(ElectLeadersRequestData request); | ||
|
|
||
| /** | ||
| * Get the current finalized feature ranges for each feature. | ||
| * | ||
| * @return A future yielding the feature ranges. | ||
| */ | ||
| CompletableFuture<FeatureMapAndEpoch> finalizedFeatures(); | ||
|
|
||
| /** | ||
| * Perform some incremental configuration changes. | ||
| * | ||
| * @param configChanges The changes. | ||
| * @param validateOnly True if we should validate the changes but not apply them. | ||
| * | ||
| * @return A future yielding a map from partitions to error results. | ||
| */ | ||
| CompletableFuture<Map<ConfigResource, ApiError>> incrementalAlterConfigs( | ||
| Map<ConfigResource, Map<String, Map.Entry<AlterConfigOp.OpType, String>>> configChanges, | ||
| boolean validateOnly); | ||
|
|
||
| /** | ||
| * Perform some configuration changes using the legacy API. | ||
| * | ||
| * @param newConfigs The new configuration maps to apply. | ||
| * @param validateOnly True if we should validate the changes but not apply them. | ||
| * | ||
| * @return A future yielding a map from partitions to error results. | ||
| */ | ||
| CompletableFuture<Map<ConfigResource, ApiError>> legacyAlterConfigs( | ||
| Map<ConfigResource, Map<String, String>> newConfigs, boolean validateOnly); | ||
|
|
||
| /** | ||
| * Process a heartbeat from a broker. | ||
| * | ||
| * @param request The broker heartbeat request. | ||
| * | ||
| * @return A future yielding a heartbeat reply. | ||
| */ | ||
| CompletableFuture<BrokerHeartbeatReply> processBrokerHeartbeat( | ||
| BrokerHeartbeatRequestData request); | ||
|
|
||
| /** | ||
| * Attempt to register the given broker. | ||
| * | ||
| * @param request The registration request. | ||
| * | ||
| * @return A future yielding a registration reply. | ||
| */ | ||
| CompletableFuture<BrokerRegistrationReply> registerBroker( | ||
| BrokerRegistrationRequestData request); | ||
|
|
||
| /** | ||
| * Wait for the given number of brokers to be registered and unfenced. | ||
| * This is for testing. | ||
| * | ||
| * @param minBrokers The minimum number of brokers to wait for. | ||
| * @return A future which is completed when the given number of brokers | ||
| * is reached. | ||
| */ | ||
| CompletableFuture<Void> waitForReadyBrokers(int minBrokers); | ||
|
|
||
| /** | ||
| * Perform some client quota changes | ||
| * | ||
| * @param quotaAlterations The list of quotas to alter | ||
| * @param validateOnly True if we should validate the changes but not apply them. | ||
| * @return A future yielding a map of quota entities to error results. | ||
| */ | ||
| CompletableFuture<Map<ClientQuotaEntity, ApiError>> alterClientQuotas( | ||
| Collection<ClientQuotaAlteration> quotaAlterations, boolean validateOnly | ||
| ); | ||
|
|
||
| /** | ||
| * Begin shutting down, but don't block. You must still call close to clean up all | ||
| * resources. | ||
| */ | ||
| void beginShutdown(); | ||
|
|
||
| /** | ||
| * If this controller is active, this is the non-negative controller epoch. | ||
| * Otherwise, this is -1. | ||
| */ | ||
| long curClaimEpoch(); | ||
|
|
||
| /** | ||
| * Blocks until we have shut down and freed all resources. | ||
| */ | ||
| void close() throws InterruptedException; | ||
| } |
84 changes: 84 additions & 0 deletions
84
metadata/src/main/java/org/apache/kafka/controller/ResultOrError.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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.controller; | ||
|
|
||
| import org.apache.kafka.common.protocol.Errors; | ||
| import org.apache.kafka.common.requests.ApiError; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
|
|
||
| class ResultOrError<T> { | ||
| private final ApiError error; | ||
| private final T result; | ||
|
|
||
| public ResultOrError(Errors error, String message) { | ||
| this(new ApiError(error, message)); | ||
| } | ||
|
|
||
| public ResultOrError(ApiError error) { | ||
| Objects.requireNonNull(error); | ||
| this.error = error; | ||
| this.result = null; | ||
| } | ||
|
|
||
| public ResultOrError(T result) { | ||
| this.error = null; | ||
| this.result = result; | ||
| } | ||
|
|
||
| public boolean isError() { | ||
| return error != null; | ||
| } | ||
|
|
||
| public boolean isResult() { | ||
| return error == null; | ||
| } | ||
|
|
||
| public ApiError error() { | ||
| return error; | ||
| } | ||
|
|
||
| public T result() { | ||
| return result; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (o == null || (!o.getClass().equals(getClass()))) { | ||
| return false; | ||
| } | ||
| ResultOrError other = (ResultOrError) o; | ||
| return error.equals(other.error) && | ||
| Objects.equals(result, other.result); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(error, result); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| if (error.isSuccess()) { | ||
| return "ResultOrError(" + result + ")"; | ||
| } else { | ||
| return "ResultOrError(" + error + ")"; | ||
| } | ||
| } | ||
| } | ||
80 changes: 80 additions & 0 deletions
80
metadata/src/main/java/org/apache/kafka/metadata/BrokerHeartbeatReply.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
|
|
||
| public class BrokerHeartbeatReply { | ||
| /** | ||
| * True if the heartbeat reply should tell the broker that it has caught up. | ||
| */ | ||
| private final boolean isCaughtUp; | ||
|
|
||
| /** | ||
| * True if the heartbeat reply should tell the broker that it is fenced. | ||
| */ | ||
| private final boolean isFenced; | ||
|
|
||
| /** | ||
| * True if the heartbeat reply should tell the broker that it should shut down. | ||
| */ | ||
| private final boolean shouldShutDown; | ||
|
|
||
| public BrokerHeartbeatReply(boolean isCaughtUp, | ||
| boolean isFenced, | ||
| boolean shouldShutDown) { | ||
| this.isCaughtUp = isCaughtUp; | ||
| this.isFenced = isFenced; | ||
| this.shouldShutDown = shouldShutDown; | ||
| } | ||
|
|
||
| public boolean isCaughtUp() { | ||
| return isCaughtUp; | ||
| } | ||
|
|
||
| public boolean isFenced() { | ||
| return isFenced; | ||
| } | ||
|
|
||
| public boolean shouldShutDown() { | ||
| return shouldShutDown; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(isCaughtUp, isFenced, shouldShutDown); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (!(o instanceof BrokerHeartbeatReply)) return false; | ||
| BrokerHeartbeatReply other = (BrokerHeartbeatReply) o; | ||
| return other.isCaughtUp == isCaughtUp && | ||
| other.isFenced == isFenced && | ||
| other.shouldShutDown == shouldShutDown; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "BrokerHeartbeatReply(isCaughtUp=" + isCaughtUp + | ||
| ", isFenced=" + isFenced + | ||
| ", shouldShutDown = " + shouldShutDown + | ||
| ")"; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.