-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-5692: Change PreferredReplicaLeaderElectionCommand to use Admin… #3848
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 19 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
707d664
KAFKA-5692: Change PreferredReplicaLeaderElectionCommand to use Admin…
tombentley 1e01e86
wip
tombentley 3620a0a
Easy review comments
tombentley b20c3a2
Don't leak partitions to unauthz clients
tombentley 5b38fc1
Tidy up PSM
tombentley bf1226d
Use empty errors map to indicate cluster auth failure
tombentley 81670d0
Support loading admin client config from file, or options
tombentley f5973ba
wip
tombentley dd0e146
Use case classes
tombentley 77d043e
Fix compiler error?
tombentley d8bf6a9
Avoid https://github.com/scala/bug/issues/10418 using a loop
tombentley 96f682b
Use implicit instead
tombentley 0d5aa7b
Review comments 2
tombentley 1fb6c05
Use JSON request/response definitions
tombentley a181a9a
Review comments
tombentley 560591c
Actually use generated proto messages
tombentley cfb6bb9
Fix test
tombentley b2d4eb1
Jun comments
tombentley 2cd37d5
Invoke callbacks when clearing queue
tombentley fce97ef
Review comments
tombentley 1257d8f
Fix test by make sure the bootstrap server is the controller
tombentley 9df18c6
Review comments
tombentley 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
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
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
31 changes: 31 additions & 0 deletions
31
clients/src/main/java/org/apache/kafka/clients/admin/ElectPreferredLeadersOptions.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,31 @@ | ||
| /* | ||
| * 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.clients.admin; | ||
|
|
||
| import org.apache.kafka.common.annotation.InterfaceStability; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| /** | ||
| * Options for {@link AdminClient#electPreferredLeaders(Collection, ElectPreferredLeadersOptions)}. | ||
| * | ||
| * The API of this class is evolving, see {@link AdminClient} for details. | ||
| */ | ||
| @InterfaceStability.Evolving | ||
| public class ElectPreferredLeadersOptions extends AbstractOptions<ElectPreferredLeadersOptions> { | ||
| } |
136 changes: 136 additions & 0 deletions
136
clients/src/main/java/org/apache/kafka/clients/admin/ElectPreferredLeadersResult.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,136 @@ | ||
| /* | ||
| * 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.clients.admin; | ||
|
|
||
| import org.apache.kafka.common.KafkaFuture; | ||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.annotation.InterfaceStability; | ||
| import org.apache.kafka.common.errors.ApiException; | ||
| import org.apache.kafka.common.errors.UnknownTopicOrPartitionException; | ||
| import org.apache.kafka.common.internals.KafkaFutureImpl; | ||
| import org.apache.kafka.common.protocol.Errors; | ||
| import org.apache.kafka.common.requests.ApiError; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * The result of {@link AdminClient#electPreferredLeaders(Collection, ElectPreferredLeadersOptions)} | ||
| * | ||
| * The API of this class is evolving, see {@link AdminClient} for details. | ||
| */ | ||
| @InterfaceStability.Evolving | ||
| public class ElectPreferredLeadersResult { | ||
|
|
||
| private final KafkaFutureImpl<Map<TopicPartition, ApiError>> electionFuture; | ||
| private final Set<TopicPartition> partitions; | ||
|
|
||
| ElectPreferredLeadersResult(KafkaFutureImpl<Map<TopicPartition, ApiError>> electionFuture, Set<TopicPartition> partitions) { | ||
| this.electionFuture = electionFuture; | ||
| this.partitions = partitions; | ||
| } | ||
|
|
||
| /** | ||
| * Get the result of the election for the given {@code partition}. | ||
| * If there was not an election triggered for the given {@code partition}, the | ||
| * returned future will complete with an error. | ||
| */ | ||
| public KafkaFuture<Void> partitionResult(final TopicPartition partition) { | ||
| final KafkaFutureImpl<Void> result = new KafkaFutureImpl<>(); | ||
| electionFuture.whenComplete(new KafkaFuture.BiConsumer<Map<TopicPartition, ApiError>, Throwable>() { | ||
| @Override | ||
| public void accept(Map<TopicPartition, ApiError> topicPartitions, Throwable throwable) { | ||
| if (throwable != null) { | ||
| result.completeExceptionally(throwable); | ||
| } else if (!topicPartitions.containsKey(partition)) { | ||
| result.completeExceptionally(new UnknownTopicOrPartitionException( | ||
| "Preferred leader election for partition \"" + partition + | ||
| "\" was not attempted")); | ||
| } else { | ||
| if (partitions == null && topicPartitions.isEmpty()) { | ||
| result.completeExceptionally(Errors.CLUSTER_AUTHORIZATION_FAILED.exception()); | ||
| } | ||
| ApiException exception = topicPartitions.get(partition).exception(); | ||
| if (exception == null) { | ||
| result.complete(null); | ||
| } else { | ||
| result.completeExceptionally(exception); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * <p>Get a future for the topic partitions for which a leader election | ||
| * was attempted. A partition will be present in this result if | ||
| * an election was attempted even if the election was not successful.</p> | ||
| * | ||
| * <p>This method is provided to discover the partitions attempted when | ||
| * {@link AdminClient#electPreferredLeaders(Collection)} is called | ||
| * with a null {@code partitions} argument.</p> | ||
| */ | ||
| public KafkaFuture<Set<TopicPartition>> partitions() { | ||
| if (partitions != null) { | ||
| return KafkaFutureImpl.completedFuture(this.partitions); | ||
| } else { | ||
| final KafkaFutureImpl<Set<TopicPartition>> result = new KafkaFutureImpl<>(); | ||
| electionFuture.whenComplete(new KafkaFuture.BiConsumer<Map<TopicPartition, ApiError>, Throwable>() { | ||
| @Override | ||
| public void accept(Map<TopicPartition, ApiError> topicPartitions, Throwable throwable) { | ||
| if (throwable != null) { | ||
| result.completeExceptionally(throwable); | ||
| } else if (topicPartitions.isEmpty()) { | ||
| result.completeExceptionally(Errors.CLUSTER_AUTHORIZATION_FAILED.exception()); | ||
| } else { | ||
| for (ApiError apiError : topicPartitions.values()) { | ||
| if (apiError.isFailure()) { | ||
| result.completeExceptionally(apiError.exception()); | ||
| } | ||
| } | ||
| result.complete(topicPartitions.keySet()); | ||
| } | ||
| } | ||
| }); | ||
| return result; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Return a future which succeeds if all the topic elections succeed. | ||
| */ | ||
| public KafkaFuture<Void> all() { | ||
| final KafkaFutureImpl<Void> result = new KafkaFutureImpl<>(); | ||
| electionFuture.thenApply(new KafkaFuture.Function<Map<TopicPartition, ApiError>, Void>() { | ||
| @Override | ||
| public Void apply(Map<TopicPartition, ApiError> topicPartitions) { | ||
| for (ApiError apiError : topicPartitions.values()) { | ||
| if (apiError.isFailure()) { | ||
| result.completeExceptionally(apiError.exception()); | ||
| return null; | ||
| } | ||
| } | ||
| result.complete(null); | ||
| return null; | ||
| } | ||
| }); | ||
| return result; | ||
| } | ||
| } |
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
28 changes: 28 additions & 0 deletions
28
...ts/src/main/java/org/apache/kafka/common/errors/PreferredLeaderNotAvailableException.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,28 @@ | ||
| /* | ||
| * 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.common.errors; | ||
|
|
||
| public class PreferredLeaderNotAvailableException extends InvalidMetadataException { | ||
|
|
||
| public PreferredLeaderNotAvailableException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public PreferredLeaderNotAvailableException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
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
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.