forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-16535: Implement AddVoter, RemoveVoter, UpdateVoter RPCs
Implement the add voter, remove voter, and update voter RPCs for KIP-853. This is just adding the RPC handling; the current implementation in RaftManager just throws UnsupportedVersionException. Reviewers: Andrew Schofield <[email protected]>, José Armando García Sancio <[email protected]>
- Loading branch information
Showing
31 changed files
with
1,161 additions
and
4 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
clients/src/main/java/org/apache/kafka/clients/admin/AddRaftVoterOptions.java
This file contains 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,26 @@ | ||
/* | ||
* 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 Admin#addRaftVoter}. | ||
*/ | ||
@InterfaceStability.Stable | ||
public class AddRaftVoterOptions extends AbstractOptions<AddRaftVoterOptions> { | ||
} |
42 changes: 42 additions & 0 deletions
42
clients/src/main/java/org/apache/kafka/clients/admin/AddRaftVoterResult.java
This file contains 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,42 @@ | ||
/* | ||
* 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.annotation.InterfaceStability; | ||
|
||
/** | ||
* The result of {@link org.apache.kafka.clients.admin.Admin#addRaftVoter(int, org.apache.kafka.common.Uuid, java.util.Set, org.apache.kafka.clients.admin.AddRaftVoterOptions)}. | ||
* | ||
* The API of this class is evolving, see {@link Admin} for details. | ||
*/ | ||
@InterfaceStability.Stable | ||
public class AddRaftVoterResult { | ||
private final KafkaFuture<Void> result; | ||
|
||
AddRaftVoterResult(KafkaFuture<Void> result) { | ||
this.result = result; | ||
} | ||
|
||
/** | ||
* Returns a future that completes when the voter has been added. | ||
*/ | ||
public KafkaFuture<Void> all() { | ||
return result; | ||
} | ||
|
||
} |
This file contains 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 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 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
100 changes: 100 additions & 0 deletions
100
clients/src/main/java/org/apache/kafka/clients/admin/RaftVoterEndpoint.java
This file contains 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,100 @@ | ||
/* | ||
* 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.Locale; | ||
import java.util.Objects; | ||
|
||
/** | ||
* An endpoint for a raft quorum voter. | ||
*/ | ||
@InterfaceStability.Stable | ||
public class RaftVoterEndpoint { | ||
private final String name; | ||
private final String host; | ||
private final int port; | ||
|
||
static String requireNonNullAllCapsNonEmpty(String input) { | ||
if (input == null) { | ||
throw new IllegalArgumentException("Null argument not allowed."); | ||
} | ||
if (!input.trim().equals(input)) { | ||
throw new IllegalArgumentException("Leading or trailing whitespace is not allowed."); | ||
} | ||
if (input.isEmpty()) { | ||
throw new IllegalArgumentException("Empty string is not allowed."); | ||
} | ||
if (!input.toUpperCase(Locale.ROOT).equals(input)) { | ||
throw new IllegalArgumentException("String must be UPPERCASE."); | ||
} | ||
return input; | ||
} | ||
|
||
/** | ||
* Create an endpoint for a metadata quorum voter. | ||
* | ||
* @param name The human-readable name for this endpoint. For example, CONTROLLER. | ||
* @param host The DNS hostname for this endpoint. | ||
* @param port The network port for this endpoint. | ||
*/ | ||
public RaftVoterEndpoint( | ||
String name, | ||
String host, | ||
int port | ||
) { | ||
this.name = requireNonNullAllCapsNonEmpty(name); | ||
this.host = Objects.requireNonNull(host); | ||
this.port = port; | ||
} | ||
|
||
public String name() { | ||
return name; | ||
} | ||
|
||
public String host() { | ||
return host; | ||
} | ||
|
||
public int port() { | ||
return port; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || (!o.getClass().equals(getClass()))) return false; | ||
RaftVoterEndpoint other = (RaftVoterEndpoint) o; | ||
return name.equals(other.name) && | ||
host.equals(other.host) && | ||
port == other.port; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, host, port); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RaftVoterEndpoint" + | ||
"(name=" + name + | ||
", host=" + host + | ||
", port=" + port + | ||
")"; | ||
} | ||
} |
Oops, something went wrong.