sarankk commented on code in PR #272:
URL: https://github.com/apache/cassandra-sidecar/pull/272#discussion_r2635912817
##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/ApiEndpointsV1.java:
##########
@@ -18,6 +18,8 @@
package org.apache.cassandra.sidecar.common;
+import java.lang.ref.PhantomReference;
Review Comment:
Nit: Remove unused import
##########
server/src/main/java/org/apache/cassandra/sidecar/modules/CassandraOperationsModule.java:
##########
@@ -112,6 +115,28 @@ VertxRoute
cassandraCompactionStatsRoute(RouteBuilder.Factory factory,
return factory.buildRouteWithHandler(compactionStatsHandler);
}
+ @POST // Note: POST, not PUT, since we're sending data in the body
Review Comment:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Methods/PUT Http
docs say we can send request content with `PUT` requests too. Difference
between them is, `PUT` requests are idempotent. Gossip update route is an
example
https://github.com/apache/cassandra-sidecar/blob/6cf4b4c9c818efac825af999fb47ac545f75d430/server/src/main/java/org/apache/cassandra/sidecar/modules/CassandraOperationsModule.java#L395.
Lets update this to `PUT` and remove note?
##########
adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/CassandraCompactionManagerOperations.java:
##########
@@ -20,10 +20,12 @@
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import
org.apache.cassandra.sidecar.adapters.base.jmx.CompactionManagerJmxOperations;
import org.apache.cassandra.sidecar.common.server.CompactionManagerOperations;
import org.apache.cassandra.sidecar.common.server.JmxClient;
+import org.jetbrains.annotations.NotNull;
Review Comment:
Nit: Remove unused import
##########
client/src/testFixtures/java/org/apache/cassandra/sidecar/client/SidecarClientTest.java:
##########
@@ -2003,7 +2068,7 @@ void testNodeLifecycleInfo() throws Exception
assertThat(result).isNotNull();
assertThat(result.currentState()).isEqualTo(CassandraState.RUNNING);
assertThat(result.desiredState()).isEqualTo(CassandraState.RUNNING);
- assertThat(result.status()).isEqualTo(OperationStatus.CONVERGED);
+
assertThat(result.status()).isEqualTo(Lifecycle.OperationStatus.CONVERGED);
Review Comment:
Nit: These changes seem unrelated to PR.
##########
adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/CassandraCompactionManagerOperations.java:
##########
@@ -53,4 +55,37 @@ public List<Map<String, String>> getCompactions()
return jmxClient.proxy(CompactionManagerJmxOperations.class,
COMPACTION_MANAGER_OBJ_NAME)
.getCompactions();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void stopCompactionById(String compactionId)
+ {
+ // compactionId takes precedence over type if both are provided
+ if (compactionId != null && !compactionId.trim().isEmpty()) {
+ CompactionManagerJmxOperations proxy = jmxClient.proxy(
+ CompactionManagerJmxOperations.class,
+ COMPACTION_MANAGER_OBJ_NAME
+ );
+ proxy.stopCompactionById(compactionId);
+ } else {
+ throw new IllegalArgumentException("compaction id is null or
empty");
+ }
+ }
+
+ @Override
+ public void stopCompaction(String compactionType) {
+ if (compactionType != null && !compactionType.trim().isEmpty()) {
+ CompactionManagerJmxOperations proxy = jmxClient.proxy(
+ CompactionManagerJmxOperations.class,
+ COMPACTION_MANAGER_OBJ_NAME
+ );
+
+ proxy.stopCompaction(Objects.requireNonNull(compactionType,
+ "compactionType must not be null when compactionId is not
provided"));
+ } else {
+ throw new IllegalArgumentException("compaction type is null or
empty");
Review Comment:
Nit: can you also add the compaction type in error message. Easy to debug
with that.
##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/CompactionStopResponse.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.common.response;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.cassandra.sidecar.common.DataObjectBuilder;
+import org.apache.cassandra.sidecar.common.data.CompactionStopStatus;
+import org.apache.cassandra.sidecar.common.data.CompactionType;
+
+/**
+ * Response class for the Compaction Stop API
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class CompactionStopResponse
+{
+ public static final String COMPACTION_TYPE_KEY = "compaction_type";
Review Comment:
Nit: here too shall we use camel case for parameter names for consistency?
##########
adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/jmx/CompactionManagerJmxOperations.java:
##########
@@ -34,4 +34,14 @@ public interface CompactionManagerJmxOperations
* @return list of compaction info maps
*/
List<Map<String, String>> getCompactions();
+
+ /**
+ * Stop compaction by type
Review Comment:
Can you also that in Javadoc, that it throws exception for invalid
compaction type, similarly javadoc for compaction by Id.
##########
client-common/src/test/java/org/apache/cassandra/sidecar/common/request/data/CompactionStopRequestPayloadTest.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.common.request.data;
+
+import org.junit.jupiter.api.Test;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.cassandra.sidecar.common.data.CompactionType;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
Review Comment:
Nit: Unused import.
##########
server-common/src/main/java/org/apache/cassandra/sidecar/common/server/CompactionManagerOperations.java:
##########
@@ -32,4 +32,22 @@ public interface CompactionManagerOperations
* @return list of compaction info maps
*/
List<Map<String, String>> getCompactions();
+
+ /**
+ * Stops compaction based on compaction ID or type.
+ * If compactionId is provided, it takes precedence over compactionType.
+ *
+ * @param compactionId the compaction ID to stop (nullable)
+ * @throws IllegalArgumentException if both parameters are null or empty
+ */
+ void stopCompactionById(String compactionId);
+
+ /**
+ * Stops compaction based on compaction ID or type.
Review Comment:
This comment is confusing. This method is only for stopping with compaction
type right? similarly comment for `stopCompactionById` method.
##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/data/CompactionType.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.common.data;
+
+import java.util.Locale;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+
+/**
+ * Supported compaction types based on Cassandra's OperationType enum
+ */
+public enum CompactionType
Review Comment:
I do not see `MAJOR_COMPACTION` type here from `OperationType` class, is
that intentional?
##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/request/data/CompactionStopRequestPayload.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.common.request.data;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.cassandra.sidecar.common.data.CompactionType;
+
+/**
+ * Request payload for stopping compaction operations.
+ *
+ * <p>Valid JSON:</p>
+ * <pre>
+ * { "compaction_type": "COMPACTION", "compaction_id": "abc-123" }
+ * { "compaction_type": "VALIDATION" }
+ * </pre>
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class CompactionStopRequestPayload
+{
+ private final CompactionType compactionType;
+ private final String compactionId;
+
+ /**
+ * Creates a new CompactionStopRequestPayload
+ *
+ * @param compactionType the type of compaction to stop (e.g., COMPACTION,
VALIDATION, etc.)
+ * @param compactionId optional ID of a specific compaction to stop
+ */
+ @JsonCreator
+ public CompactionStopRequestPayload(
+ @JsonProperty(value = "compaction_type") CompactionType compactionType,
Review Comment:
Nit: for parameter names shall we use camel case, just for consistency?.
Other request payloads use camel case
##########
server/src/main/java/org/apache/cassandra/sidecar/modules/CassandraOperationsModule.java:
##########
@@ -112,6 +115,28 @@ VertxRoute
cassandraCompactionStatsRoute(RouteBuilder.Factory factory,
return factory.buildRouteWithHandler(compactionStatsHandler);
}
+ @POST // Note: POST, not PUT, since we're sending data in the body
+ @Path(ApiEndpointsV1.COMPACTION_STOP_ROUTE)
+ @Operation(summary = "Stop compaction operation",
+ description = "Stops a compaction operation on the Cassandra node")
+ @APIResponse(description = "Compaction stop operation completed",
+ responseCode = "200",
+ content = @Content(mediaType = "application/json",
+ schema = @Schema(implementation =
CompactionStopResponse.class)))
+ @APIResponse(responseCode = "500", description = "Internal server error")
Review Comment:
Ideally we should not see `500` response from handler. 500 means we did not
foresee some error and handle it properly. I would suggest removing it from
list of expected responses.
##########
adapters/adapters-base/src/main/java/org/apache/cassandra/sidecar/adapters/base/CassandraCompactionManagerOperations.java:
##########
@@ -53,4 +55,37 @@ public List<Map<String, String>> getCompactions()
return jmxClient.proxy(CompactionManagerJmxOperations.class,
COMPACTION_MANAGER_OBJ_NAME)
.getCompactions();
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void stopCompactionById(String compactionId)
+ {
+ // compactionId takes precedence over type if both are provided
+ if (compactionId != null && !compactionId.trim().isEmpty()) {
+ CompactionManagerJmxOperations proxy = jmxClient.proxy(
+ CompactionManagerJmxOperations.class,
+ COMPACTION_MANAGER_OBJ_NAME
+ );
+ proxy.stopCompactionById(compactionId);
+ } else {
+ throw new IllegalArgumentException("compaction id is null or
empty");
Review Comment:
Nit: can you also add the compaction id in error message. Easy to debug with
that.
##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/data/CompactionType.java:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.common.data;
+
+import java.util.Locale;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+
+/**
+ * Supported compaction types based on Cassandra's OperationType enum
+ */
+public enum CompactionType
+{
+ COMPACTION,
+ VALIDATION,
+ KEY_CACHE_SAVE,
+ ROW_CACHE_SAVE,
+ COUNTER_CACHE_SAVE,
+ CLEANUP,
+ SCRUB,
+ UPGRADE_SSTABLES,
+ INDEX_BUILD,
+ TOMBSTONE_COMPACTION,
+ ANTICOMPACTION,
+ VERIFY,
+ WRITE,
Review Comment:
`WRITE` operation seems to be not a compaction type, can you double check?
##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/response/CompactionStopResponse.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.common.response;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.cassandra.sidecar.common.DataObjectBuilder;
+import org.apache.cassandra.sidecar.common.data.CompactionStopStatus;
+import org.apache.cassandra.sidecar.common.data.CompactionType;
+
+/**
+ * Response class for the Compaction Stop API
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class CompactionStopResponse
+{
+ public static final String COMPACTION_TYPE_KEY = "compaction_type";
+ public static final String COMPACTION_ID_KEY = "compaction_id";
+ public static final String STATUS_KEY = "status";
+ private final CompactionType compactionType;
+ private final String compactionId;
+ private final CompactionStopStatus status;
+
+ private CompactionStopResponse(Builder builder)
+ {
+ this.compactionType = builder.compactionType;
+ this.compactionId = builder.compactionId;
+ this.status = builder.status;
+ }
+
+ /**
+ * Constructs a new {@link CompactionStopResponse}.
+ *
+ * @param compactionType the type of compaction that was requested to stop
+ * @param compactionId the ID of the compaction that was requested to
stop
+ * @param status the status of the stop operation (e.g.,
"PENDING", "FAILED")
+ */
+ @JsonCreator
+ public CompactionStopResponse(@JsonProperty(COMPACTION_TYPE_KEY)
CompactionType compactionType,
Review Comment:
Nit: can you reuse these in request payload too. Feel free to ignore this
comment.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]