You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "sklaha (via GitHub)" <gi...@apache.org> on 2025/09/30 07:11:39 UTC

[PR] CASSSIDECAR-344: Sidecar endpoint for moving a node to a new token [cassandra-sidecar]

sklaha opened a new pull request, #265:
URL: https://github.com/apache/cassandra-sidecar/pull/265

   ### Sidecar endpoint for moving a node to a new token
   These changes are part of the effort to introduce bespoke Sidecar APIs to support key operational functionality currently managed through nodetool commands. Changes in the commit:
   
   * API for moving a node to a new token
   * Unit tests
   * Integration tests


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-344: Sidecar endpoint for moving a node to a new token [cassandra-sidecar]

Posted by "sklaha (via GitHub)" <gi...@apache.org>.
sklaha closed pull request #265: CASSSIDECAR-344: Sidecar endpoint for moving a node to a new token
URL: https://github.com/apache/cassandra-sidecar/pull/265


-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-344: Sidecar endpoint for moving a node to a new token [cassandra-sidecar]

Posted by "sklaha (via GitHub)" <gi...@apache.org>.
sklaha commented on code in PR #265:
URL: https://github.com/apache/cassandra-sidecar/pull/265#discussion_r2493424151


##########
server-common/src/main/java/org/apache/cassandra/sidecar/common/server/StorageOperations.java:
##########
@@ -174,4 +174,11 @@ default void outOfRangeDataCleanup(@NotNull String keyspace, @NotNull String tab
      * @return the current compaction throughput in megabytes per second, or 0 if throughput cannot be determined
      */
     int getCompactionThroughputMbPerSec();
+
+    /**
+     * Triggers the node move operation to move the node to a new token.
+     *
+     * @param newToken the new token for the node to move to
+     */
+    void move(String newToken);

Review Comment:
   I accidentally deleted the commits in the PR from my fork, which automatically closed the PR. I’m unable to reopen it. I’ve created a new PR that addresses this comment: https://github.com/apache/cassandra-sidecar/pull/275



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-344: Sidecar endpoint for moving a node to a new token [cassandra-sidecar]

Posted by "sklaha (via GitHub)" <gi...@apache.org>.
sklaha commented on code in PR #265:
URL: https://github.com/apache/cassandra-sidecar/pull/265#discussion_r2493426038


##########
integration-tests/src/integrationTest/org/apache/cassandra/sidecar/routes/CassandraNodeOperationsIntegrationTest.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.routes;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.Test;
+
+import io.vertx.core.buffer.Buffer;
+import io.vertx.core.json.JsonObject;
+import io.vertx.ext.web.client.HttpResponse;
+import org.apache.cassandra.sidecar.common.ApiEndpointsV1;
+import org.apache.cassandra.sidecar.common.data.OperationalJobStatus;
+import org.apache.cassandra.sidecar.testing.SharedClusterSidecarIntegrationTestBase;
+
+import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;
+import static io.netty.handler.codec.http.HttpResponseStatus.OK;
+import static org.apache.cassandra.testing.utils.AssertionUtils.getBlocking;
+import static org.apache.cassandra.testing.utils.AssertionUtils.loopAssert;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration tests for Cassandra node operations
+ */
+public class CassandraNodeOperationsIntegrationTest extends SharedClusterSidecarIntegrationTestBase
+{
+    public static final String CASSANDRA_VERSION_4_0 = "4.0";
+
+    @Override
+    protected void initializeSchemaForTest()
+    {
+        // No schema init needed
+    }
+
+    @Override
+    protected void beforeTestStart()
+    {
+        // wait for the schema initialization
+        waitForSchemaReady(30, TimeUnit.SECONDS);
+    }
+
+    @Test
+    void testNodeMoveOperationSuccess()
+    {
+        // Use a test token - this is a valid token for Murmur3Partitioner 
+        String testToken = "123456789";
+
+        // Initiate move operation
+        HttpResponse<Buffer> moveResponse = getBlocking(
+        trustedClient().put(serverWrapper.serverPort, "localhost", ApiEndpointsV1.NODE_MOVE_ROUTE + "?newToken=" + testToken)
+                       .send());
+
+        assertThat(moveResponse.statusCode()).isIn(OK.code(), ACCEPTED.code());
+
+        JsonObject responseBody = moveResponse.bodyAsJsonObject();
+        assertThat(responseBody).isNotNull();
+        assertThat(responseBody.getString("jobId")).isNotNull();
+        assertThat(responseBody.getString("operation")).isEqualTo("move");
+        assertThat(responseBody.getString("jobStatus")).isIn(
+        OperationalJobStatus.CREATED.name(),
+        OperationalJobStatus.RUNNING.name(),
+        OperationalJobStatus.SUCCEEDED.name()
+        );
+
+        // Verify the job eventually completes (or at least gets processed)
+        loopAssert(30, 500, () -> {
+            HttpResponse<Buffer> streamStatsResponse = getBlocking(
+            trustedClient().get(serverWrapper.serverPort, "localhost", ApiEndpointsV1.STREAM_STATS_ROUTE)
+                           .send());
+
+            assertThat(streamStatsResponse.statusCode()).isEqualTo(OK.code());
+
+            JsonObject streamStats = streamStatsResponse.bodyAsJsonObject();
+            assertThat(streamStats).isNotNull();
+            // The operationMode should be either NORMAL (completed) or MOVING (in progress)
+            assertThat(streamStats.getString("operationMode")).isIn("NORMAL", "MOVING");

Review Comment:
   Done here: https://github.com/apache/cassandra-sidecar/pull/265



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-344: Sidecar endpoint for moving a node to a new token [cassandra-sidecar]

Posted by "frankgh (via GitHub)" <gi...@apache.org>.
frankgh commented on code in PR #265:
URL: https://github.com/apache/cassandra-sidecar/pull/265#discussion_r2392282273


##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/request/NodeMoveRequest.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import io.netty.handler.codec.http.HttpMethod;
+import org.apache.cassandra.sidecar.common.ApiEndpointsV1;
+import org.apache.cassandra.sidecar.common.response.OperationalJobResponse;
+
+/**
+ * Represents a request to execute node move operation
+ */
+public class NodeMoveRequest extends JsonRequest<OperationalJobResponse>
+{
+    /**
+     * Constructs a request to execute a node move operation
+     *
+     * @param newToken the new token for the node to move to
+     */
+    public NodeMoveRequest(String newToken)
+    {
+        super(ApiEndpointsV1.NODE_MOVE_ROUTE + "?newToken=" + newToken);

Review Comment:
   should we make the `newToken` be part of the body payload instead of having it as a query string? 



##########
server-common/src/main/java/org/apache/cassandra/sidecar/common/server/StorageOperations.java:
##########
@@ -174,4 +174,11 @@ default void outOfRangeDataCleanup(@NotNull String keyspace, @NotNull String tab
      * @return the current compaction throughput in megabytes per second, or 0 if throughput cannot be determined
      */
     int getCompactionThroughputMbPerSec();
+
+    /**
+     * Triggers the node move operation to move the node to a new token.
+     *
+     * @param newToken the new token for the node to move to
+     */
+    void move(String newToken);

Review Comment:
   I think we need to handle the case where the token does not belong to the node. In Cassandra, it looks like we throw an `IOException` when token is not valid. Also we should have a test around this.



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-344: Sidecar endpoint for moving a node to a new token [cassandra-sidecar]

Posted by "arjunashok (via GitHub)" <gi...@apache.org>.
arjunashok commented on code in PR #265:
URL: https://github.com/apache/cassandra-sidecar/pull/265#discussion_r2402863216


##########
integration-tests/src/integrationTest/org/apache/cassandra/sidecar/routes/CassandraNodeOperationsIntegrationTest.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.routes;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.jupiter.api.Test;
+
+import io.vertx.core.buffer.Buffer;
+import io.vertx.core.json.JsonObject;
+import io.vertx.ext.web.client.HttpResponse;
+import org.apache.cassandra.sidecar.common.ApiEndpointsV1;
+import org.apache.cassandra.sidecar.common.data.OperationalJobStatus;
+import org.apache.cassandra.sidecar.testing.SharedClusterSidecarIntegrationTestBase;
+
+import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED;
+import static io.netty.handler.codec.http.HttpResponseStatus.OK;
+import static org.apache.cassandra.testing.utils.AssertionUtils.getBlocking;
+import static org.apache.cassandra.testing.utils.AssertionUtils.loopAssert;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Integration tests for Cassandra node operations
+ */
+public class CassandraNodeOperationsIntegrationTest extends SharedClusterSidecarIntegrationTestBase
+{
+    public static final String CASSANDRA_VERSION_4_0 = "4.0";
+
+    @Override
+    protected void initializeSchemaForTest()
+    {
+        // No schema init needed
+    }
+
+    @Override
+    protected void beforeTestStart()
+    {
+        // wait for the schema initialization
+        waitForSchemaReady(30, TimeUnit.SECONDS);
+    }
+
+    @Test
+    void testNodeMoveOperationSuccess()
+    {
+        // Use a test token - this is a valid token for Murmur3Partitioner 
+        String testToken = "123456789";
+
+        // Initiate move operation
+        HttpResponse<Buffer> moveResponse = getBlocking(
+        trustedClient().put(serverWrapper.serverPort, "localhost", ApiEndpointsV1.NODE_MOVE_ROUTE + "?newToken=" + testToken)
+                       .send());
+
+        assertThat(moveResponse.statusCode()).isIn(OK.code(), ACCEPTED.code());
+
+        JsonObject responseBody = moveResponse.bodyAsJsonObject();
+        assertThat(responseBody).isNotNull();
+        assertThat(responseBody.getString("jobId")).isNotNull();
+        assertThat(responseBody.getString("operation")).isEqualTo("move");
+        assertThat(responseBody.getString("jobStatus")).isIn(
+        OperationalJobStatus.CREATED.name(),
+        OperationalJobStatus.RUNNING.name(),
+        OperationalJobStatus.SUCCEEDED.name()
+        );
+
+        // Verify the job eventually completes (or at least gets processed)
+        loopAssert(30, 500, () -> {
+            HttpResponse<Buffer> streamStatsResponse = getBlocking(
+            trustedClient().get(serverWrapper.serverPort, "localhost", ApiEndpointsV1.STREAM_STATS_ROUTE)
+                           .send());
+
+            assertThat(streamStatsResponse.statusCode()).isEqualTo(OK.code());
+
+            JsonObject streamStats = streamStatsResponse.bodyAsJsonObject();
+            assertThat(streamStats).isNotNull();
+            // The operationMode should be either NORMAL (completed) or MOVING (in progress)
+            assertThat(streamStats.getString("operationMode")).isIn("NORMAL", "MOVING");

Review Comment:
   The concern with this is that we get a false negative when no move happened i.e. node remains in `NORMAL` state. We would need a more concrete way to validate that a move happened - eg. add data to ensure the move takes longer and evaluate validating the end state via ring or token-ranges endpoint.



##########
server/src/main/java/org/apache/cassandra/sidecar/job/NodeMoveJob.java:
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.sidecar.common.server.StorageOperations;
+
+/**
+ * Implementation of {@link OperationalJob} to perform node move operation.
+ */
+public class NodeMoveJob extends OperationalJob
+{
+    private static final Logger LOGGER = LoggerFactory.getLogger(NodeMoveJob.class);
+    private static final String OPERATION = "move";
+    private static final String OPERATION_MODE_MOVING = "MOVING";
+    private final String newToken;
+    protected StorageOperations storageOperations;
+
+    public NodeMoveJob(UUID jobId, String newToken, StorageOperations storageOps)
+    {
+        super(jobId);
+        this.newToken = newToken;
+        this.storageOperations = storageOps;
+    }
+
+    @Override
+    public boolean isRunningOnCassandra()
+    {
+        String operationMode = storageOperations.operationMode();
+        return OPERATION_MODE_MOVING.equals(operationMode);

Review Comment:
   Question is, do we want to fail-fast when we discover the node is not in a `NORMAL` state here. It would seem reasonable to do so, but worth checking Cassandra's behavior across versions.



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/request/NodeMoveRequest.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import io.netty.handler.codec.http.HttpMethod;
+import org.apache.cassandra.sidecar.common.ApiEndpointsV1;
+import org.apache.cassandra.sidecar.common.response.OperationalJobResponse;
+
+/**
+ * Represents a request to execute node move operation
+ */
+public class NodeMoveRequest extends JsonRequest<OperationalJobResponse>
+{
+    /**
+     * Constructs a request to execute a node move operation
+     *
+     * @param newToken the new token for the node to move to
+     */
+    public NodeMoveRequest(String newToken)
+    {
+        super(ApiEndpointsV1.NODE_MOVE_ROUTE + "?newToken=" + newToken);

Review Comment:
   +1, should be in the body since it is part of the actual resource being updated rather than an optional parameter/filter.



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSSIDECAR-344: Sidecar endpoint for moving a node to a new token [cassandra-sidecar]

Posted by "sklaha (via GitHub)" <gi...@apache.org>.
sklaha commented on code in PR #265:
URL: https://github.com/apache/cassandra-sidecar/pull/265#discussion_r2493422989


##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/request/NodeMoveRequest.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import io.netty.handler.codec.http.HttpMethod;
+import org.apache.cassandra.sidecar.common.ApiEndpointsV1;
+import org.apache.cassandra.sidecar.common.response.OperationalJobResponse;
+
+/**
+ * Represents a request to execute node move operation
+ */
+public class NodeMoveRequest extends JsonRequest<OperationalJobResponse>
+{
+    /**
+     * Constructs a request to execute a node move operation
+     *
+     * @param newToken the new token for the node to move to
+     */
+    public NodeMoveRequest(String newToken)
+    {
+        super(ApiEndpointsV1.NODE_MOVE_ROUTE + "?newToken=" + newToken);

Review Comment:
   I accidentally deleted the commits in the PR from my fork, which automatically closed the PR. I’m unable to reopen it. I’ve created a new PR that addresses this comment: https://github.com/apache/cassandra-sidecar/pull/275



-- 
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-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org