You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "frankgh (via GitHub)" <gi...@apache.org> on 2024/07/15 20:47:44 UTC

Re: [PR] CASSANDRASC-132: Add restore job progress endpoint and consistency check on restore ranges [cassandra-sidecar]

frankgh commented on code in PR #123:
URL: https://github.com/apache/cassandra-sidecar/pull/123#discussion_r1664132974


##########
src/main/java/org/apache/cassandra/sidecar/restore/RestoreJobManagerGroup.java:
##########
@@ -54,39 +52,32 @@ public RestoreJobManagerGroup(SidecarConfiguration configuration,
                                   ExecutorPools executorPools,
                                   PeriodicTaskExecutor periodicTaskExecutor,
                                   RestoreProcessor restoreProcessor,
-                                  RestoreJobDiscoverer jobDiscoverer)
+                                  RestoreJobDiscoverer jobDiscoverer,
+                                  RingTopologyRefresher ringTopologyRefresher)
     {
         this.restoreJobConfig = configuration.restoreJobConfiguration();
         this.restoreProcessor = restoreProcessor;
-        this.jobDiscoverer = jobDiscoverer;
         this.executorPools = executorPools;
         initializeManagers(instancesConfig);
-        jobDiscoverer.signalRefresh();
         periodicTaskExecutor.schedule(jobDiscoverer);
         periodicTaskExecutor.schedule(restoreProcessor);
+        periodicTaskExecutor.schedule(ringTopologyRefresher);

Review Comment:
   It feels like the ring topology refresher is not necessarily tied to the restore feature. I'd preferably schedule it somewhere else where we don't couple it with this feature.



##########
src/main/java/org/apache/cassandra/sidecar/db/schema/RestoreRangesSchema.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.db.schema;
+
+import com.datastax.driver.core.Metadata;
+import com.datastax.driver.core.PreparedStatement;
+import com.datastax.driver.core.Session;
+import org.apache.cassandra.sidecar.config.SchemaKeyspaceConfiguration;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * {@link RestoreRangesSchema} holds all prepared statements needed for talking to Cassandra for various actions
+ * related to restore progress tracking in terms of each token range
+ */
+public class RestoreRangesSchema extends TableSchema
+{
+    private static final String TABLE_NAME = "restore_range_v1";
+
+    private final SchemaKeyspaceConfiguration keyspaceConfig;
+    private final long tableTtlSeconds;
+
+    private PreparedStatement insert;
+    private PreparedStatement findAll;
+    private PreparedStatement update;
+
+    public RestoreRangesSchema(SchemaKeyspaceConfiguration keyspaceConfig, long tableTtlSeconds)
+    {
+        this.keyspaceConfig = keyspaceConfig;
+        this.tableTtlSeconds = tableTtlSeconds;
+    }
+
+    @Override
+    protected String keyspaceName()
+    {
+        return keyspaceConfig.keyspace();
+    }
+
+    @Override
+    protected void prepareStatements(@NotNull Session session)
+    {
+        insert = prepare(insert, session, CqlLiterals.insert(keyspaceConfig));
+        findAll = prepare(findAll, session, CqlLiterals.findAll(keyspaceConfig));
+        update = prepare(update, session, CqlLiterals.update(keyspaceConfig));
+    }
+
+    @Override
+    protected boolean exists(@NotNull Metadata metadata)
+    {
+        return false;

Review Comment:
   is it okay to return false here?



##########
src/main/java/org/apache/cassandra/sidecar/utils/InstanceMetadataFetcher.java:
##########
@@ -99,11 +103,32 @@ public CassandraAdapterDelegate delegate(int instanceId)
      * @throws IllegalStateException when there are no configured instances
      */
     public InstanceMetadata firstInstance()
+    {
+        ensureInstancesConfigured();
+        return instancesConfig.instances().get(0);
+    }
+
+    /**
+     * @return any instance from the list of configured instances
+     * @throws IllegalStateException when there are no configured instances
+     */
+    public InstanceMetadata anyInstance()

Review Comment:
   looking at the caller of this method , it seems what we really need is the "first available instance". Having a random instance being returned here could prevent the topology refresher to make any progress for a prolonged period of time, if say all instances except one are available and you keep getting an unavailable instance on each iteration. Can we instead have a new API method that returns the firstAvailableInstance instead? 



##########
src/main/java/org/apache/cassandra/sidecar/restore/RestoreJobManager.java:
##########
@@ -240,4 +245,10 @@ boolean isObsoleteRestoreJobDir(Path path)
         long gapInMillis = TimeUnit.DAYS.toMillis(restoreJobConfig.jobDiscoveryRecencyDays());
         return delta > gapInMillis;
     }
+
+    @VisibleForTesting
+    RestoreJobProgressTracker progressTrackerUnsafe(RestoreJob restoreJob)

Review Comment:
   why unsafe here?



##########
server-common/src/main/java/org/apache/cassandra/sidecar/common/server/utils/StringUtils.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.server.utils;
+
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Collection of utility methods for String
+ */
+public class StringUtils
+{
+    /**
+     * @param string string value to test
+     * @return true when the string is null or its length is 0; false otherwise
+     */
+    public static boolean isNullOrEmpty(@Nullable String string)
+    {
+        return string == null || string.isEmpty();
+    }
+
+    /**
+     * @param string string value to test
+     * @return true only when the string is not null and its length is not 0; false otherwise
+     */
+    public static boolean notEmpty(@Nullable String string)

Review Comment:
   why not use commons lang3 StringUtils ? This method is only used from the server which has a dependency to lang3



##########
src/main/java/org/apache/cassandra/sidecar/utils/InstanceMetadataFetcher.java:
##########
@@ -99,11 +103,32 @@ public CassandraAdapterDelegate delegate(int instanceId)
      * @throws IllegalStateException when there are no configured instances
      */
     public InstanceMetadata firstInstance()
+    {
+        ensureInstancesConfigured();
+        return instancesConfig.instances().get(0);
+    }
+
+    /**
+     * @return any instance from the list of configured instances
+     * @throws IllegalStateException when there are no configured instances
+     */
+    public InstanceMetadata anyInstance()
+    {
+        ensureInstancesConfigured();
+        List<InstanceMetadata> instances = instancesConfig.instances();
+        if (instances.size() == 1)
+        {
+            return instances.get(0);
+        }
+        int randomPick = RANDOM.nextInt(instances.size());

Review Comment:
   can we use `ThreadLocalRandom.current().nextInt()` here instead? 



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/ApiEndpointsV1.java:
##########
@@ -96,17 +97,17 @@ public final class ApiEndpointsV1
     public static final String KEYSPACE_TOKEN_MAPPING_ROUTE = API_V1 + PER_KEYSPACE + "/token-range-replicas";
 
     // Blob Transport Extension
-    public static final String JOB_ID_PATH_PARAM = ":jobId";
     public static final String RESTORE_JOBS = "/restore-jobs";
     public static final String SLICES = "/slices";
     public static final String ABORT = "/abort";
+    public static final String PROGRESS = "/progress";
+    public static final String FETCH_POLICY = "fetch-policy";

Review Comment:
   should we name this `FETCH_POLICY_QUERY_PARAM` ?



##########
client-common/src/main/java/org/apache/cassandra/sidecar/common/request/data/CreateRestoreJobRequestPayload.java:
##########
@@ -94,17 +102,19 @@ public CreateRestoreJobRequestPayload(@JsonProperty(JOB_ID) UUID jobId,
                              ? SSTableImportOptions.defaults()
                              : importOptions;
         this.expireAtInMillis = expireAtInMillis;
-        this.consistencyLevel = consistencyLevel;
+        this.consistencyLevel = ConsistencyLevel.fromString(consistencyLevel);
+        this.localDatacenter = localDatacenter;

Review Comment:
   should we validate here that if (consistencyLevel.isLocal) then localDC cannot be null?



##########
client-common/src/test/java/org/apache/cassandra/sidecar/common/request/CreateRestoreJobRequestPayloadTest.java:
##########
@@ -49,10 +56,14 @@ void testSerDeser() throws JsonProcessingException
         Date date = Date.from(Instant.ofEpochMilli(time));
         CreateRestoreJobRequestPayload req = CreateRestoreJobRequestPayload.builder(secrets, time)
                                                                            .jobId(UUID.fromString(id))
-                                                                           .consistencyLevel("QUORUM")
+                                                                           .consistencyLevel(ConsistencyLevel.QUORUM)
                                                                            .jobAgent("agent")
                                                                            .build();
         String json = MAPPER.writeValueAsString(req);
+        assertThat(json).describedAs("Null value fields should be excluded").doesNotContain(JOB_LOCAL_DATA_CENTER)

Review Comment:
   so here we just assert that the string is contained in the serialized payload? is that desired?



-- 
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