arjunashok commented on code in PR #231: URL: https://github.com/apache/cassandra-sidecar/pull/231#discussion_r2244312733
########## server/src/main/java/org/apache/cassandra/sidecar/job/RepairJob.java: ########## @@ -0,0 +1,249 @@ +/* + * 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.cassandra.sidecar.job; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.vertx.core.Future; +import io.vertx.core.Promise; +import io.vertx.core.Vertx; +import org.apache.cassandra.sidecar.adapters.base.RepairOptions; +import org.apache.cassandra.sidecar.common.request.data.RepairPayload; +import org.apache.cassandra.sidecar.common.server.StorageOperations; +import org.apache.cassandra.sidecar.config.RepairConfiguration; +import org.apache.cassandra.sidecar.handlers.data.RepairRequestParam; + +import static java.util.Objects.requireNonNull; + +/** + * Implementation of {@link OperationalJob} to perform repair operation. + */ +public class RepairJob extends OperationalJob +{ + private static final Logger LOGGER = LoggerFactory.getLogger(RepairJob.class); + private static final String OPERATION = "repair"; + private static final String PREVIEW_KIND_REPAIRED = "REPAIRED"; + + private final RepairRequestParam repairParams; + private final Vertx vertx; + private final RepairConfiguration repairConfiguration; + protected StorageOperations storageOperations; + + /** + * Enum representing the status of a parent repair session + */ + public enum ParentRepairStatus + { + IN_PROGRESS, COMPLETED, FAILED + } + + /** + * Constructs a job with a unique UUID, in Pending state + * + * @param vertx + * @param repairConfiguration + * @param jobId UUID representing the Job to be created + * @param storageOps + * @param repairParams + */ + public RepairJob(Vertx vertx, RepairConfiguration repairConfiguration, UUID jobId, StorageOperations storageOps, RepairRequestParam repairParams) + { + super(jobId); + this.vertx = vertx; + this.repairConfiguration = repairConfiguration; + this.storageOperations = storageOps; + this.repairParams = repairParams; + } + + @Override + public boolean isRunningOnCassandra() + { + // TODO: Leverage repair vtables to fail-fast on conflicting repairs (overlapping token-ranges or replica-sets) + // Currently does not check for concurrent repairs + return false; + } + + @Override + protected void executeInternal() + { + Map<String, String> options = generateRepairOptions(repairParams.requestpayload()); + String keyspace = repairParams.keyspace().name(); + + LOGGER.info("Executing repair operation for keyspace {} jobId={} maxRuntime={}", + keyspace, this.jobId(), repairConfiguration.maxRepairJobRuntimeMillis()); + + int cmd = storageOperations.repair(keyspace, options); + if (cmd <= 0) + { + // repairAsync can only return 0 for replication factor 1. + LOGGER.info("Replication factor is 1. No repair is needed for keyspace '{}'", keyspace); Review Comment: How about a more generic comment/log line? ``` // When there are no relevant token ranges for the keyspace or RF is 1, the repair is inapplicable LOGGER.info("Repair is not applicable for the provided options and keyspace '{}' jobId '{}'", keyspace, this.jobId()); ``` -- 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: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org