jyothsnakonisa commented on code in PR #347:
URL: https://github.com/apache/cassandra-sidecar/pull/347#discussion_r3237156017


##########
build.gradle:
##########
@@ -140,6 +140,10 @@ allprojects {
 
         // for dtest jar
         mavenLocal()
+
+        maven {
+            url 
"https://repository.apache.org/content/repositories/orgapachecassandra-1468/";

Review Comment:
   Yes!



##########
server/build.gradle:
##########
@@ -151,6 +151,7 @@ dependencies {
     implementation(group: "org.apache.cassandra", name: 
"cassandra-avro-converter_spark3_2.12", version: 
"${[project.analyticsVersion]}")
     implementation(group: "org.apache.cassandra", name: 
"cassandra-analytics-cdc_spark3_2.12", version: "${[project.analyticsVersion]}")
     implementation(group: "org.apache.cassandra", name: 
"cassandra-analytics-cdc-sidecar_spark3_2.12", version: 
"${[project.analyticsVersion]}")
+    compileOnly(group: "org.apache.cassandra", name: 
"cassandra-analytics-sidecar-client", version: "${[project.analyticsVersion]}")

Review Comment:
   Added a comment explaining the reason to add this



##########
server/src/test/java/org/apache/cassandra/sidecar/cdc/CdcPublisherTests.java:
##########
@@ -111,204 +112,22 @@ void setUp()
 
         cdcPublisher = new CdcPublisher(
             vertx,
-            sidecarConfiguration,
             executorPools,
             clusterConfigProvider,
             schemaSupplier,
-            sidecarInstancesProvider,
-            clientConfig,
             instanceMetadataFetcher,
             cdcConfig,
             databaseAccessor,
             cdcStats,
             virtualTables,
             sidecarCdcStats,
-            avroSerializer,
-            rangeManager
-        );
-    }
-
-
-    @Test
-    void testSecretsProviderReturnsNullWhenSslDisabled()

Review Comment:
   None of the tests were removed. They got moved to other files, this one got 
moved to `SidecarClientSecretsProviderTests`, during reorganization of commits, 
it got moved to another commit.



##########
server/src/main/java/org/apache/cassandra/sidecar/cdc/CachingSchemaStore.java:
##########
@@ -176,17 +209,26 @@ void onSchemaChanged()
                         
tableHistoryDatabaseAccessor.insertTableSchemaHistory(cqlTable.keyspace(), 
cqlTable.table(), cqlTable.createStatement());
                     }
                     LOGGER.info("Re-generating Avro Schema after schema change 
keyspace={} table={}", tableIdentifier.keyspace(), tableIdentifier.table());
-                    return new SchemaCacheEntry(cqlTable, 
cqlToAvroSchemaConverter);
+                    return new SchemaCacheEntry(cqlTable, 
cqlToAvroSchemaConverter.convert(cqlTable));
                 }
                 return v;
             });
         }
-        loadPublisher();
-        publishSchemas();
+        try
+        {
+            loadPublisher();
+            publishSchemas();
+        }
+        catch (Exception e)
+        {
+            LOGGER.error("Failed to publish schemas to Kafka, CDC will still 
start", e);
+        }
         // Remove any old schema entries for deleted tables, this operation 
can be done in the end as this is
         // only for removing stale entries and no one is going to use these 
entries once the table is removed.
         // This doesn't have to be an atomic operation.
-        
avroSchemasCache.keySet().retainAll(refreshedCdcTables.stream().map(cqlTable -> 
TableIdentifier.of(cqlTable.keyspace(), 
cqlTable.table())).collect(Collectors.toList()));
+        avroSchemasCache.keySet().retainAll(refreshedCdcTables.stream()
+                                                               .map(cqlTable 
-> TableIdentifier.of(cqlTable.keyspace(), cqlTable.table()))
+                                                               
.collect(Collectors.toList()));
         vertx.eventBus().publish(ON_CDC_CACHE_WARMED_UP.address(), "Cdc cache 
warmed up");

Review Comment:
   This change is not part of this PR. This is my guess, CdcPublisher should 
only start if the CachingSchemaStore Is initialized to avoid reading commit 
logs before schema is available in-memory, otherwise we will run into errors. 
`ON_CDC_CACHE_WARMED_UP ` event is published when initialization of in -memory 
cache is complete to indicate that schemas are ready In memory and we can start 
processing commit logs for producing mutations.



##########
server/src/main/java/org/apache/cassandra/sidecar/cdc/CachingSchemaStore.java:
##########
@@ -91,13 +105,13 @@ public class CachingSchemaStore implements SchemaStore
         this.tableHistoryDatabaseAccessor = tableHistoryDatabaseAccessor;
         this.sidecarSchema = sidecarSchema;
         this.cqlToAvroSchemaConverter = cqlToAvroSchemaConverter;
-        
this.avroSchemasCache.putAll(createSchemaCache(cassandraClusterSchemaMonitor.getCdcTables()));
-        AvroSchemas.registerLogicalTypes();
-        
cassandraClusterSchemaMonitor.addSchemaChangeListener(this::onSchemaChanged);
         this.vertx = vertx;
         this.cdcConfig = cdcConfig;
         this.sidecarCdcStats = sidecarCdcStats;
         this.schemaStorePublisherFactory = schemaStorePublisherFactory;
+        
this.avroSchemasCache.putAll(createSchemaCache(cassandraClusterSchemaMonitor.getCdcTables()));

Review Comment:
   Added a comment explaining the reason



##########
server/src/main/java/org/apache/cassandra/sidecar/cdc/SidecarReplicationFactorSupplier.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.cdc;
+
+import java.util.Comparator;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.cdc.api.CdcOptions;
+import org.apache.cassandra.cdc.api.SchemaSupplier;
+import org.apache.cassandra.cdc.sidecar.ReplicationFactorSupplier;
+import org.apache.cassandra.cdc.sidecar.SidecarCommitLogProvider;
+import org.apache.cassandra.spark.data.CqlTable;
+import org.apache.cassandra.spark.data.ReplicationFactor;
+import org.apache.cassandra.spark.utils.FutureUtils;
+
+/**
+ * {@link ReplicationFactorSupplier} implementation that reads the actual 
replication factor
+ * from Cassandra cluster metadata via {@link CdcOptions}, rather than using 
the default RF=1
+ * SimpleStrategy fallback. Used by {@link SidecarCommitLogProvider} to build 
a correctly
+ * replicated {@link 
org.apache.cassandra.spark.data.partitioner.CassandraRing}.
+ */
+public class SidecarReplicationFactorSupplier implements 
ReplicationFactorSupplier
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(SidecarReplicationFactorSupplier.class);
+    private final CdcOptions cdcOptions;
+    private final SchemaSupplier schemaSupplier;
+
+    public SidecarReplicationFactorSupplier(CdcOptions cdcOptions, 
SchemaSupplier schemaSupplier)
+    {
+        this.cdcOptions = cdcOptions;
+        this.schemaSupplier = schemaSupplier;
+    }
+
+    @Override
+    public ReplicationFactor getReplicationFactor(String keyspace)
+    {
+        return cdcOptions.replicationFactor(keyspace);
+    }
+
+    @Override
+    public ReplicationFactor getMaximalReplicationFactor()
+    {
+        String dc = cdcOptions.dc();
+        Set<CqlTable> tables = 
FutureUtils.get(schemaSupplier.getCdcEnabledTables());
+        return tables.stream()
+                     .map(CqlTable::replicationFactor)
+                     .filter(rf -> rf.getOptions().containsKey(dc))
+                     .max(Comparator.comparingInt(rf -> 
rf.getOptions().get(dc)))
+                     .orElseGet(() -> {
+                         LOGGER.warn("No CDC-enabled tables found for DC '{}'; 
falling back to RF=1 SimpleStrategy", dc);

Review Comment:
   Default implementation for this method in the base class fallbacks to RF1 
and hence I am using that here, If you think we should fail in this scenario, I 
am open to that suggestion.



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

Reply via email to