yifan-c commented on code in PR #294:
URL: https://github.com/apache/cassandra-sidecar/pull/294#discussion_r2676835635


##########
server/src/main/java/org/apache/cassandra/sidecar/cdc/CachingSchemaStore.java:
##########
@@ -0,0 +1,263 @@
+/*
+ * 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.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import io.vertx.core.Vertx;
+import io.vertx.core.eventbus.EventBus;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericDatumReader;
+import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.avro.generic.GenericRecord;
+
+import org.apache.cassandra.cdc.avro.AvroSchemas;
+import org.apache.cassandra.cdc.avro.CqlToAvroSchemaConverter;
+import org.apache.cassandra.cdc.kafka.KafkaOptions;
+import org.apache.cassandra.cdc.schemastore.SchemaStore;
+import org.apache.cassandra.cdc.schemastore.SchemaStorePublisherFactory;
+import org.apache.cassandra.cdc.schemastore.TableSchemaPublisher;
+import org.apache.cassandra.sidecar.db.TableHistoryDatabaseAccessor;
+import org.apache.cassandra.sidecar.db.schema.SidecarSchema;
+import org.apache.cassandra.sidecar.tasks.CassandraClusterSchemaMonitor;
+import org.apache.cassandra.spark.data.CqlTable;
+import org.apache.cassandra.spark.utils.TableIdentifier;
+
+import static 
org.apache.cassandra.sidecar.server.SidecarServerEvents.ON_CDC_CACHE_WARMED_UP;
+import static 
org.apache.cassandra.sidecar.server.SidecarServerEvents.ON_SERVER_START;
+import static 
org.apache.cassandra.sidecar.server.SidecarServerEvents.ON_SIDECAR_SCHEMA_INITIALIZED;
+
+/**
+ * Schemas cache to be used by CDC event serialization. It contains a map of 
table schemas
+ * using TableIdentifier as key.
+ */
+@Singleton
+public class CachingSchemaStore implements SchemaStore
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(CachingSchemaStore.class);
+    private final Map<TableIdentifier, SchemaCacheEntry> avroSchemasCache = 
new ConcurrentHashMap<>();
+    private final CassandraClusterSchemaMonitor cassandraClusterSchemaMonitor;
+    private final SidecarSchema sidecarSchema;
+    private final TableHistoryDatabaseAccessor tableHistoryDatabaseAccessor;
+    private final Vertx vertx;
+    private final CdcConfigImpl cdcConfig;
+    @Nullable private volatile TableSchemaPublisher publisher;
+    private final CqlToAvroSchemaConverter cqlToAvroSchemaConverter;
+    private final SidecarCdcStats sidecarCdcStats;
+
+    private static final String METADATA_NAME_KEY = "name";
+    private static final String METADATA_NAMESPACE_KEY = "namespace";
+
+    @Inject
+    CachingSchemaStore(Vertx vertx,
+                       CassandraClusterSchemaMonitor 
cassandraClusterSchemaMonitor,
+                       TableHistoryDatabaseAccessor 
tableHistoryDatabaseAccessor,
+                       CdcConfigImpl cdcConfig,
+                       SidecarCdcStats sidecarCdcStats,
+                       SidecarSchema sidecarSchema,
+                       CqlToAvroSchemaConverter cqlToAvroSchemaConverter)
+    {
+        super();
+        this.cassandraClusterSchemaMonitor = cassandraClusterSchemaMonitor;
+        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;
+
+        configureSidecarServerEventListeners();

Review Comment:
   Thanks. Just to clarify that conditionally register the listeners are still 
wanted in this patch. 



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