Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions clients/src/main/java/org/apache/kafka/clients/admin/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,36 @@ default AlterDisklessSwitchResult alterDisklessSwitch(String topic, int partitio
*/
AlterDisklessSwitchResult alterDisklessSwitch(String topic, int partition, long sealOffset, AlterDisklessSwitchOptions options);

/**
* Reconcile the control-plane diskless log entry of a single partition with the seal committed in
* KRaft. This is an operator tool; the request must be sent to the partition leader, which owns the
* control-plane connection, so the caller supplies its broker id.
*
* This is a convenience method for {@link #repairDisklessLog(String, int, int, RepairDisklessLogOptions)}
* with default options.
*
* @param topic The topic name.
* @param partition The partition index.
* @param brokerId The id of the partition leader broker to send the request to.
* @return The RepairDisklessLogResult.
*/
default RepairDisklessLogResult repairDisklessLog(String topic, int partition, int brokerId) {
return repairDisklessLog(topic, partition, brokerId, new RepairDisklessLogOptions());
}

/**
* Reconcile the control-plane diskless log entry of a single partition with the seal committed in
* KRaft. This is an operator tool; the request must be sent to the partition leader, which owns the
* control-plane connection, so the caller supplies its broker id.
*
* @param topic The topic name.
* @param partition The partition index.
* @param brokerId The id of the partition leader broker to send the request to.
* @param options The options to use.
* @return The RepairDisklessLogResult.
*/
RepairDisklessLogResult repairDisklessLog(String topic, int partition, int brokerId, RepairDisklessLogOptions options);

/**
* Get information about the nodes in the cluster, using the default options.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public AlterDisklessSwitchResult alterDisklessSwitch(String topic, int partition
return delegate.alterDisklessSwitch(topic, partition, sealOffset, options);
}

@Override
public RepairDisklessLogResult repairDisklessLog(String topic, int partition, int brokerId, RepairDisklessLogOptions options) {
return delegate.repairDisklessLog(topic, partition, brokerId, options);
}

@Override
public DescribeClusterResult describeCluster(DescribeClusterOptions options) {
return delegate.describeCluster(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
import org.apache.kafka.common.message.MetadataRequestData;
import org.apache.kafka.common.message.RemoveRaftVoterRequestData;
import org.apache.kafka.common.message.RenewDelegationTokenRequestData;
import org.apache.kafka.common.message.RepairDisklessLogRequestData;
import org.apache.kafka.common.message.UnregisterBrokerRequestData;
import org.apache.kafka.common.message.UpdateFeaturesRequestData;
import org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult;
Expand Down Expand Up @@ -249,6 +250,8 @@
import org.apache.kafka.common.requests.RemoveRaftVoterResponse;
import org.apache.kafka.common.requests.RenewDelegationTokenRequest;
import org.apache.kafka.common.requests.RenewDelegationTokenResponse;
import org.apache.kafka.common.requests.RepairDisklessLogRequest;
import org.apache.kafka.common.requests.RepairDisklessLogResponse;
import org.apache.kafka.common.requests.UnregisterBrokerRequest;
import org.apache.kafka.common.requests.UnregisterBrokerResponse;
import org.apache.kafka.common.requests.UpdateFeaturesRequest;
Expand Down Expand Up @@ -4937,6 +4940,43 @@ void handleFailure(Throwable throwable) {
return new AlterDisklessSwitchResult(future);
}

@Override
public RepairDisklessLogResult repairDisklessLog(String topic, int partition, int brokerId,
RepairDisklessLogOptions options) {
final KafkaFutureImpl<Void> future = new KafkaFutureImpl<>();
final long now = time.milliseconds();
// The control-plane write happens on the partition leader, so send directly to that broker.
final Call call = new Call("repairDisklessLog", calcDeadlineMs(now, options.timeoutMs()),
new ConstantNodeIdProvider(brokerId)) {

@Override
RepairDisklessLogRequest.Builder createRequest(int timeoutMs) {
RepairDisklessLogRequestData data = new RepairDisklessLogRequestData()
.setTopicName(topic)
.setPartitionIndex(partition);
return new RepairDisklessLogRequest.Builder(data);
}

@Override
void handleResponse(AbstractResponse abstractResponse) {
final RepairDisklessLogResponse response = (RepairDisklessLogResponse) abstractResponse;
Errors error = Errors.forCode(response.data().errorCode());
if (error == Errors.NONE) {
future.complete(null);
} else {
future.completeExceptionally(error.exception(response.data().errorMessage()));
}
}

@Override
void handleFailure(Throwable throwable) {
future.completeExceptionally(throwable);
}
};
runnable.call(call, now);
return new RepairDisklessLogResult(future);
}

@Override
public DescribeProducersResult describeProducers(Collection<TopicPartition> topicPartitions, DescribeProducersOptions options) {
PartitionLeaderStrategy.PartitionLeaderFuture<DescribeProducersResult.PartitionProducerState> future =
Expand Down
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 Admin#repairDisklessLog(String, int, int, RepairDisklessLogOptions)}.
*
* The API of this class is evolving, see {@link Admin} for details.
*/
@InterfaceStability.Unstable
public class RepairDisklessLogOptions extends AbstractOptions<RepairDisklessLogOptions> {
Comment thread
giuseppelillo marked this conversation as resolved.
Resolved
}
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 the {@link Admin#repairDisklessLog(String, int, int, RepairDisklessLogOptions)} call.
*
* The API of this class is evolving, see {@link Admin} for details.
*/
@InterfaceStability.Unstable
public class RepairDisklessLogResult {
private final KafkaFuture<Void> future;

RepairDisklessLogResult(final KafkaFuture<Void> future) {
this.future = future;
}

/**
* Return a future which succeeds if the repair is successful.
*/
public KafkaFuture<Void> all() {
return future;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ public enum ApiKeys {
ALTER_SHARE_GROUP_OFFSETS(ApiMessageType.ALTER_SHARE_GROUP_OFFSETS),
DELETE_SHARE_GROUP_OFFSETS(ApiMessageType.DELETE_SHARE_GROUP_OFFSETS),
INIT_DISKLESS_LOG(ApiMessageType.INIT_DISKLESS_LOG, true),
ALTER_DISKLESS_SWITCH(ApiMessageType.ALTER_DISKLESS_SWITCH, false, true);
ALTER_DISKLESS_SWITCH(ApiMessageType.ALTER_DISKLESS_SWITCH, false, true),
REPAIR_DISKLESS_LOG(ApiMessageType.REPAIR_DISKLESS_LOG, false, false);


private static final Map<ApiMessageType.ListenerType, EnumSet<ApiKeys>> APIS_BY_LISTENER =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ private static AbstractRequest doParseRequest(ApiKeys apiKey, short apiVersion,
return InitDisklessLogRequest.parse(readable, apiVersion);
case ALTER_DISKLESS_SWITCH:
return AlterDisklessSwitchRequest.parse(readable, apiVersion);
case REPAIR_DISKLESS_LOG:
return RepairDisklessLogRequest.parse(readable, apiVersion);
default:
throw new AssertionError(String.format("ApiKey %s is not currently handled in `parseRequest`, the " +
"code should be updated to do so.", apiKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ public static AbstractResponse parseResponse(ApiKeys apiKey, Readable readable,
return InitDisklessLogResponse.parse(readable, version);
case ALTER_DISKLESS_SWITCH:
return AlterDisklessSwitchResponse.parse(readable, version);
case REPAIR_DISKLESS_LOG:
return RepairDisklessLogResponse.parse(readable, version);
default:
throw new AssertionError(String.format("ApiKey %s is not currently handled in `parseResponse`, the " +
"code should be updated to do so.", apiKey));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.requests;

import org.apache.kafka.common.message.RepairDisklessLogRequestData;
import org.apache.kafka.common.message.RepairDisklessLogResponseData;
import org.apache.kafka.common.protocol.ApiKeys;
import org.apache.kafka.common.protocol.Readable;

public class RepairDisklessLogRequest extends AbstractRequest {

public static class Builder extends AbstractRequest.Builder<RepairDisklessLogRequest> {
private final RepairDisklessLogRequestData data;

public Builder(RepairDisklessLogRequestData data) {
super(ApiKeys.REPAIR_DISKLESS_LOG);
this.data = data;
}

@Override
public RepairDisklessLogRequest build(short version) {
return new RepairDisklessLogRequest(data, version);
}

@Override
public String toString() {
return data.toString();
}
}

private final RepairDisklessLogRequestData data;

public RepairDisklessLogRequest(RepairDisklessLogRequestData data, short version) {
super(ApiKeys.REPAIR_DISKLESS_LOG, version);
this.data = data;
}

@Override
public RepairDisklessLogRequestData data() {
return data;
}

@Override
public RepairDisklessLogResponse getErrorResponse(int throttleTimeMs, Throwable e) {
ApiError apiError = ApiError.fromThrowable(e);
return new RepairDisklessLogResponse(new RepairDisklessLogResponseData()
.setThrottleTimeMs(throttleTimeMs)
.setErrorCode(apiError.error().code())
.setErrorMessage(apiError.message()));
}

public static RepairDisklessLogRequest parse(Readable readable, short version) {
return new RepairDisklessLogRequest(new RepairDisklessLogRequestData(readable, version), version);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.requests;

import org.apache.kafka.common.message.RepairDisklessLogResponseData;
import org.apache.kafka.common.protocol.ApiKeys;
import org.apache.kafka.common.protocol.Errors;
import org.apache.kafka.common.protocol.Readable;

import java.util.EnumMap;
import java.util.Map;

public class RepairDisklessLogResponse extends AbstractResponse {
private final RepairDisklessLogResponseData data;

public RepairDisklessLogResponse(RepairDisklessLogResponseData data) {
super(ApiKeys.REPAIR_DISKLESS_LOG);
this.data = data;
}

@Override
public RepairDisklessLogResponseData data() {
return data;
}

@Override
public int throttleTimeMs() {
return data.throttleTimeMs();
}

@Override
public void maybeSetThrottleTimeMs(int throttleTimeMs) {
data.setThrottleTimeMs(throttleTimeMs);
}

@Override
public Map<Errors, Integer> errorCounts() {
Map<Errors, Integer> errorCounts = new EnumMap<>(Errors.class);
if (data.errorCode() != 0) {
errorCounts.put(Errors.forCode(data.errorCode()), 1);
}
return errorCounts;
}

public static RepairDisklessLogResponse parse(Readable readable, short version) {
return new RepairDisklessLogResponse(new RepairDisklessLogResponseData(readable, version));
}

@Override
public boolean shouldClientThrottle(short version) {
return true;
}
}
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.

{
"apiKey": 502,
"type": "request",
"listeners": ["broker"],
"name": "RepairDisklessLogRequest",
"validVersions": "0",
"flexibleVersions": "0+",
"fields": [
{ "name": "TopicName", "type": "string", "versions": "0+", "entityType": "topicName",
"about": "The name of the topic whose control-plane diskless log entry is being repaired." },
{ "name": "PartitionIndex", "type": "int32", "versions": "0+",
"about": "The partition index." }
]
}
Loading
Loading