fvaleri commented on code in PR #22531:
URL: https://github.com/apache/kafka/pull/22531#discussion_r4667588017
##########
clients/src/main/java/org/apache/kafka/clients/admin/Admin.java:
##########
@@ -1908,65 +1908,178 @@ default ListClientMetricsResourcesResult
listClientMetricsResources() {
*/
Uuid clientInstanceId(Duration timeout);
+ /**
+ * Add a new voter node to the KRaft metadata quorum.
+ *
+ * <p>
+ * This is a convenience method which allows the active controller to
derive the
+ * voter's directory ID and endpoints from its in-memory state. It is not
idempotent:
+ * if multiple observers have the same node ID, the request may fail
because the
+ * target voter cannot be identified unambiguously.
+ *
+ * <p>
+ * To validate the target voter or override the derived values, use
+ * {@link #addRaftVoter(int, AddRaftVoterOptions)} with
+ * {@link AddRaftVoterOptions#setVoterDirectoryId(Optional)} or
+ * {@link AddRaftVoterOptions#setEndpoints(Set)}.
+ *
+ * @param voterId The node ID of the voter to add.
+ */
+ default AddRaftVoterResult addRaftVoter(int voterId) {
+ return addRaftVoter(voterId, new AddRaftVoterOptions());
+ }
+
+ /**
+ * Add a new voter node to the KRaft metadata quorum.
+ *
+ * <p>
+ * The clusterId in {@link AddRaftVoterOptions} is optional.
+ * If provided, the operation will only succeed if the cluster id matches
the id
+ * of the current cluster. If the cluster id does not match, the operation
+ * will fail with {@link InconsistentClusterIdException}.
+ * If not provided, the cluster id check is skipped.
+ *
+ * <p>
+ * If {@link AddRaftVoterOptions#voterDirectoryId()} is empty, the active
controller
+ * derives the voter's directory ID from its in-memory observer state. If
+ * {@link AddRaftVoterOptions#endpoints()} is empty, the active controller
derives
+ * the voter's endpoints from its in-memory state.
+ *
+ * <p>
+ * This operation is not idempotent when the directory ID is omitted: if
multiple
+ * observers have the same node ID, the target voter cannot be identified
+ * unambiguously and the request will fail.
+ *
+ * <p>
+ * To validate the target voter or override the derived values, use
+ * {@link AddRaftVoterOptions#setVoterDirectoryId(Optional)} and
+ * {@link AddRaftVoterOptions#setEndpoints(Set)}.
+ *
+ * @param voterId The node ID of the voter to add.
+ * @param options Additional options for the operation.
+ */
+ AddRaftVoterResult addRaftVoter(int voterId, AddRaftVoterOptions options);
Review Comment:
This and removeRaftVoter break the compatibility strategy explicitly
described in the KIP: an existing third-party implementation of Admin has
implementations of the old abstract methods, but does not implement the new
ones. Calling an inherited convenience method such as addRaftVoter(int) or
removeRaftVoter(int) can therefore end in an AbstractMethodError.
The options-based methods should be default methods that bridge to the
previous abstract signatures, as the KIP specifies. KafkaAdminClient can
override the new methods to implement the new request semantics.
##########
clients/src/main/java/org/apache/kafka/clients/admin/AddRaftVoterOptions.java:
##########
@@ -46,4 +51,48 @@ public AddRaftVoterOptions setClusterId(Optional<String>
clusterId) {
public Optional<String> clusterId() {
return clusterId;
}
+
+ public AddRaftVoterOptions setVoterDirectoryId(Optional<Uuid>
voterDirectoryId) {
+ this.voterDirectoryId = voterDirectoryId;
Review Comment:
Should we reject null Optional here?
##########
clients/src/main/java/org/apache/kafka/clients/admin/AddRaftVoterOptions.java:
##########
@@ -46,4 +51,48 @@ public AddRaftVoterOptions setClusterId(Optional<String>
clusterId) {
public Optional<String> clusterId() {
return clusterId;
}
+
+ public AddRaftVoterOptions setVoterDirectoryId(Optional<Uuid>
voterDirectoryId) {
+ this.voterDirectoryId = voterDirectoryId;
+ return this;
+ }
+
+ public Optional<Uuid> voterDirectoryId() {
+ return voterDirectoryId;
+ }
+
+ public AddRaftVoterOptions setEndpoints(Set<RaftVoterEndpoint> endpoints) {
+ this.endpoints = endpoints;
Review Comment:
Should we take a defensive copy of endpoints here? Since the operation is
asynchronous, a caller modifying the original set after invoking the API can
change which endpoints are sent. Concurrent modification could also cause
request construction to fail.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]