-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-8286; Leader Election Admin RPC (KIP-460) #6686
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
35 commits
Select commit
Hold shift + click to select a range
1144c98
Change the elect leader RPC
jsancio d6728de
Election type support in the controller
jsancio 6a5a58b
Implement kafka-elect-leaders command
jsancio 3261276
Add PartitionLeaderNotAvailable exception
jsancio cf9e4c8
Add tests for partition state machine
jsancio 23f6eeb
Merge the preferred election command test suites
jsancio 33ec321
Add framework for testing LeaderElectionCommand
jsancio fcebc1e
Close AdminClient after elect leader command
jsancio 5bcf3cf
Propagate leader information during election
jsancio 35af0cc
Refactor controller to return leader election result
jsancio 0f945b3
Add a top level error to the leader election RPC
jsancio 144d8c2
Query all partitions after authorization
jsancio 41b16c9
Only fetch topic config if allowUnclean is not set
jsancio 9ddba69
Implement electPreferredLeaders using electLeaders
jsancio 8674e72
Do not assume cluster authorization error
jsancio 282d900
Change old command error semantic to mathc the new electLeaders RPC
jsancio e61f7ab
Merge remote-tracking branch 'upstream/trunk' into election-rpc
jsancio 524e8b9
Update documentation
jsancio a0b588c
Merge remote-tracking branch 'upstream/trunk' into election-rpc
jsancio bf0820e
Fix checkstyle
jsancio 4f60fa8
Either right bias is only supported in Scala 2.12
jsancio 7efac6a
Add deprecation notice to the upgrade document
jsancio 242b413
Change the admin test to now use deprecated APIs
jsancio 6ebb040
Don't return partitions that didn't need election
jsancio edbe381
Move the byte to ElectionType conversion function
jsancio 48cfdfa
Implement all() for ElectLeadersResult
jsancio 9f3466d
Avoid unnecessary copy when generating response
jsancio fdc5dfb
Merge remote-tracking branch 'upstream/trunk' into election-rpc
jsancio b806b26
For unclean filter partitions with a live leader
jsancio 4fd6420
Use Set for collection of topics
jsancio 092b3e4
Merge remote-tracking branch 'upstream/trunk' into election-rpc
jsancio 7dd3e01
It compiles in scala 2.11.x
jsancio 0709771
Merge remote-tracking branch 'upstream/trunk' into election-rpc
jsancio 95432ce
Remove extra match case introduced during merge
jsancio 6d53f26
Make a mutable copy of the topic Set
jsancio 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/bash | ||
| # 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. | ||
|
|
||
| exec $(dirname $0)/kafka-run-class.sh kafka.admin.LeaderElectionCommand "$@" |
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,17 @@ | ||
| @echo off | ||
| rem Licensed to the Apache Software Foundation (ASF) under one or more | ||
| rem contributor license agreements. See the NOTICE file distributed with | ||
| rem this work for additional information regarding copyright ownership. | ||
| rem The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| rem (the "License"); you may not use this file except in compliance with | ||
| rem the License. You may obtain a copy of the License at | ||
| rem | ||
| rem http://www.apache.org/licenses/LICENSE-2.0 | ||
| rem | ||
| rem Unless required by applicable law or agreed to in writing, software | ||
| rem distributed under the License is distributed on an "AS IS" BASIS, | ||
| rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| rem See the License for the specific language governing permissions and | ||
| rem limitations under the License. | ||
|
|
||
| "%~dp0kafka-run-class.bat" kafka.admin.LeaderElectionCommand %* |
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
29 changes: 29 additions & 0 deletions
29
clients/src/main/java/org/apache/kafka/clients/admin/ElectLeadersOptions.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,29 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * Options for {@link AdminClient#electLeaders(ElectionType, Set, ElectLeadersOptions)}. | ||
| * | ||
| * The API of this class is evolving, see {@link AdminClient} for details. | ||
| */ | ||
| @InterfaceStability.Evolving | ||
| final public class ElectLeadersOptions extends AbstractOptions<ElectLeadersOptions> { | ||
| } | ||
76 changes: 76 additions & 0 deletions
76
clients/src/main/java/org/apache/kafka/clients/admin/ElectLeadersResult.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,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.clients.admin; | ||
|
|
||
|
|
||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import org.apache.kafka.common.KafkaFuture; | ||
| import org.apache.kafka.common.TopicPartition; | ||
| import org.apache.kafka.common.annotation.InterfaceStability; | ||
| import org.apache.kafka.common.internals.KafkaFutureImpl; | ||
|
|
||
| /** | ||
| * The result of {@link AdminClient#electLeaders(ElectionType, Set, ElectLeadersOptions)} | ||
| * | ||
| * The API of this class is evolving, see {@link AdminClient} for details. | ||
| */ | ||
| @InterfaceStability.Evolving | ||
| final public class ElectLeadersResult { | ||
|
jsancio marked this conversation as resolved.
|
||
| private final KafkaFutureImpl<Map<TopicPartition, Optional<Throwable>>> electionFuture; | ||
|
|
||
| ElectLeadersResult(KafkaFutureImpl<Map<TopicPartition, Optional<Throwable>>> electionFuture) { | ||
| this.electionFuture = electionFuture; | ||
| } | ||
|
|
||
| /** | ||
| * <p>Get a future for the topic partitions for which a leader election was attempted. | ||
| * If the election succeeded then the value for a topic partition will be the empty Optional. | ||
| * Otherwise the election failed and the Optional will be set with the error.</p> | ||
| */ | ||
| public KafkaFuture<Map<TopicPartition, Optional<Throwable>>> partitions() { | ||
| return electionFuture; | ||
| } | ||
|
|
||
| /** | ||
| * Return a future which succeeds if all the topic elections succeed. | ||
| */ | ||
| public KafkaFuture<Void> all() { | ||
| final KafkaFutureImpl<Void> result = new KafkaFutureImpl<>(); | ||
|
|
||
| partitions().whenComplete( | ||
| new KafkaFuture.BiConsumer<Map<TopicPartition, Optional<Throwable>>, Throwable>() { | ||
| @Override | ||
| public void accept(Map<TopicPartition, Optional<Throwable>> topicPartitions, Throwable throwable) { | ||
| if (throwable != null) { | ||
| result.completeExceptionally(throwable); | ||
| } else { | ||
| for (Optional<Throwable> exception : topicPartitions.values()) { | ||
| if (exception.isPresent()) { | ||
| result.completeExceptionally(exception.get()); | ||
| return; | ||
| } | ||
| } | ||
| result.complete(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
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.