You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by GitBox <gi...@apache.org> on 2020/10/28 09:51:54 UTC

[GitHub] [cassandra-sidecar] Maxwell-Guo commented on a change in pull request #18: CDC reader in Apache Cassandra Sidecar - CASSANDRASC-27

Maxwell-Guo commented on a change in pull request #18:
URL: https://github.com/apache/cassandra-sidecar/pull/18#discussion_r512450830



##########
File path: src/main/java/org/apache/cassandra/sidecar/CQLSession.java
##########
@@ -0,0 +1,115 @@
+package org.apache.cassandra.sidecar;

Review comment:
       The file should got the header with "apache licence ?"
   /*
    * 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.
    */ 

##########
File path: src/main/java/org/apache/cassandra/sidecar/CQLSession.java
##########
@@ -0,0 +1,115 @@
+package org.apache.cassandra.sidecar;
+
+import java.net.InetSocketAddress;
+import java.util.Collections;
+
+import javax.annotation.Nullable;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.ConsistencyLevel;
+import com.datastax.driver.core.NettyOptions;
+import com.datastax.driver.core.QueryOptions;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.policies.ExponentialReconnectionPolicy;
+import com.datastax.driver.core.policies.ReconnectionPolicy;
+import com.datastax.driver.core.policies.RoundRobinPolicy;
+import com.datastax.driver.core.policies.WhiteListPolicy;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * Represents a connection to Cassandra cluster. Currently supports returning the local connection only as
+ * defined in the Configuration.
+ */
+@Singleton
+public class CQLSession
+{
+    private static final Logger logger = LoggerFactory.getLogger(CQLSession.class);
+    @Nullable
+    private Session localSession;
+    private final InetSocketAddress inet;
+    private final WhiteListPolicy wlp;
+    private NettyOptions nettyOptions;
+    private QueryOptions queryOptions;
+    private ReconnectionPolicy reconnectionPolicy;
+
+    @Inject
+    public CQLSession(Configuration configuration)
+    {
+        inet = InetSocketAddress.createUnresolved(configuration.getCassandraHost(), configuration.getCassandraPort());
+        wlp = new WhiteListPolicy(new RoundRobinPolicy(), Collections.singletonList(inet));
+        this.nettyOptions = new NettyOptions();
+        this.queryOptions = new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE);
+        this.reconnectionPolicy = new ExponentialReconnectionPolicy(1000,
+                configuration.getHealthCheckFrequencyMillis());
+    }
+
+    @VisibleForTesting
+    CQLSession(InetSocketAddress target, NettyOptions options)
+    {
+        inet = target;
+        wlp = new WhiteListPolicy(new RoundRobinPolicy(), Collections.singletonList(inet));
+        this.nettyOptions = options;
+        this.queryOptions = new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE);
+        reconnectionPolicy = new ExponentialReconnectionPolicy(100, 1000);
+    }
+
+    /**
+     * Provides a Session connected only to the local node from configuration. If null it means the the connection was
+     * not able to be established. The session still might throw a NoHostAvailableException if the local host goes
+     * offline or otherwise unavailable.
+     *
+     * @return Session
+     */
+    @Nullable
+    public synchronized Session getLocalCql()
+    {
+        Cluster cluster = null;
+        try
+        {
+            if (localSession == null)
+            {
+                cluster = Cluster.builder()
+                        .addContactPointsWithPorts(inet)
+                        .withLoadBalancingPolicy(wlp)
+                        .withQueryOptions(queryOptions)
+                        .withReconnectionPolicy(reconnectionPolicy)
+                        .withoutMetrics()
+                        // tests can create a lot of these Cluster objects, to avoid creating HWTs and
+                        // event thread pools for each we have the override
+                        .withNettyOptions(nettyOptions)
+                        .build();
+                localSession = cluster.connect();
+            }
+        }
+        catch (Exception e)
+        {
+            logger.debug("Failed to reach Cassandra", e);

Review comment:
       for me , I think the logging level for https://github.com/apache/cassandra-sidecar/blob/trunk/common/src/main/java/org/apache/cassandra/sidecar/common/CQLSession.java#L108 should also be error level , not debug level

##########
File path: src/main/java/org/apache/cassandra/sidecar/CQLSession.java
##########
@@ -0,0 +1,115 @@
+package org.apache.cassandra.sidecar;
+
+import java.net.InetSocketAddress;
+import java.util.Collections;
+
+import javax.annotation.Nullable;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.ConsistencyLevel;
+import com.datastax.driver.core.NettyOptions;
+import com.datastax.driver.core.QueryOptions;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.policies.ExponentialReconnectionPolicy;
+import com.datastax.driver.core.policies.ReconnectionPolicy;
+import com.datastax.driver.core.policies.RoundRobinPolicy;
+import com.datastax.driver.core.policies.WhiteListPolicy;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * Represents a connection to Cassandra cluster. Currently supports returning the local connection only as
+ * defined in the Configuration.
+ */
+@Singleton
+public class CQLSession

Review comment:
       we have got a CQLSession class In Common dir 

##########
File path: src/main/dist/conf/sidecar.yaml
##########
@@ -24,3 +24,6 @@ sidecar:
 
 healthcheck:
   - poll_freq_millis: 30000
+
+cdc:

Review comment:
       I think this can change from "cdc" to "cassandra config file" for we may got some other useage of cassandra yaml path not only cdc .

##########
File path: src/main/java/org/apache/cassandra/sidecar/MainModule.java
##########
@@ -151,6 +163,7 @@ public Configuration configuration() throws ConfigurationException, IOException
                     .setTrustStorePath(yamlConf.get(String.class, "sidecar.ssl.truststore.path", null))
                     .setTrustStorePassword(yamlConf.get(String.class, "sidecar.ssl.truststore.password", null))
                     .setSslEnabled(yamlConf.get(Boolean.class, "sidecar.ssl.enabled", false))
+                    .setCassandraConfigPath(yamlConf.get(String.class, "cdc.configPath"))

Review comment:
       as I said before, the cassandra configre path can also be for cassandra choice at the sidecar.yaml。

##########
File path: src/main/java/org/apache/cassandra/sidecar/Configuration.java
##########
@@ -55,12 +55,17 @@
 
     private final boolean isSslEnabled;
 
+    /* Cassandra server conf path */
+    @Nullable
+    private String cassandraConfigPath;

Review comment:
       why cassandraConfigPath can be null ?

##########
File path: src/main/java/org/apache/cassandra/sidecar/cdc/CassandraConfig.java
##########
@@ -0,0 +1,68 @@
+package org.apache.cassandra.sidecar.cdc;
+
+import java.io.File;
+import java.nio.file.Paths;
+import java.util.function.Supplier;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.cassandra.config.Config;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.config.YamlConfigurationLoader;
+import org.apache.cassandra.sidecar.Configuration;
+
+/**

Review comment:
       I think this file should be under sidecar dir with the configuration.java or to make it better if we can make the cassandraconfiguration with configuration.java

##########
File path: src/main/java/org/apache/cassandra/sidecar/CassandraSidecarDaemon.java
##########
@@ -38,19 +38,22 @@
     private static final Logger logger = LoggerFactory.getLogger(CassandraSidecarDaemon.class);
     private final HttpServer server;
     private final Configuration config;
+    private final CDCReaderService cdcReaderService;
 
     @Inject
-    public CassandraSidecarDaemon(HttpServer server, Configuration config)
+    public CassandraSidecarDaemon(HttpServer server, Configuration config, CDCReaderService cdcReaderService)
     {
         this.server = server;
         this.config = config;
+        this.cdcReaderService = cdcReaderService;
     }
 
     public void start()
     {
         banner(System.out);
         validate();
         logger.info("Starting Cassandra Sidecar on {}:{}", config.getHost(), config.getPort());
+        cdcReaderService.start();

Review comment:
       and I also think we can add a common method where all other service can be added inner the method . 
   such as startInitService() , for me ,I think cdcReaderService is a sidecar init start service and we can use a flag to 
   show the service's start or not . 

##########
File path: src/main/java/org/apache/cassandra/sidecar/cdc/CDCBookmark.java
##########
@@ -0,0 +1,213 @@
+package org.apache.cassandra.sidecar.cdc;
+

Review comment:
       shold add apache licenece header ?

##########
File path: src/main/java/org/apache/cassandra/sidecar/CassandraSidecarDaemon.java
##########
@@ -38,19 +38,22 @@
     private static final Logger logger = LoggerFactory.getLogger(CassandraSidecarDaemon.class);
     private final HttpServer server;
     private final Configuration config;
+    private final CDCReaderService cdcReaderService;
 
     @Inject
-    public CassandraSidecarDaemon(HttpServer server, Configuration config)
+    public CassandraSidecarDaemon(HttpServer server, Configuration config, CDCReaderService cdcReaderService)
     {
         this.server = server;
         this.config = config;
+        this.cdcReaderService = cdcReaderService;
     }
 
     public void start()
     {
         banner(System.out);
         validate();
         logger.info("Starting Cassandra Sidecar on {}:{}", config.getHost(), config.getPort());
+        cdcReaderService.start();

Review comment:
       Besides , do you think we should add a flag to enable or disable the cdc reader service?

##########
File path: src/main/dist/conf/sidecar.yaml
##########
@@ -24,3 +24,6 @@ sidecar:
 
 healthcheck:
   - poll_freq_millis: 30000
+
+cdc:

Review comment:
       and I think this config path should be put to "cassandra:"  which of the top choice of the sidecar.yaml

##########
File path: src/main/java/org/apache/cassandra/sidecar/CassandraSidecarDaemon.java
##########
@@ -38,19 +38,22 @@
     private static final Logger logger = LoggerFactory.getLogger(CassandraSidecarDaemon.class);
     private final HttpServer server;
     private final Configuration config;
+    private final CDCReaderService cdcReaderService;
 
     @Inject
-    public CassandraSidecarDaemon(HttpServer server, Configuration config)
+    public CassandraSidecarDaemon(HttpServer server, Configuration config, CDCReaderService cdcReaderService)
     {
         this.server = server;
         this.config = config;
+        this.cdcReaderService = cdcReaderService;
     }
 
     public void start()
     {
         banner(System.out);
         validate();
         logger.info("Starting Cassandra Sidecar on {}:{}", config.getHost(), config.getPort());
+        cdcReaderService.start();

Review comment:
       add a log for cdc reader service?

##########
File path: src/main/java/org/apache/cassandra/sidecar/CQLSession.java
##########
@@ -0,0 +1,115 @@
+package org.apache.cassandra.sidecar;
+
+import java.net.InetSocketAddress;
+import java.util.Collections;
+
+import javax.annotation.Nullable;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.ConsistencyLevel;
+import com.datastax.driver.core.NettyOptions;
+import com.datastax.driver.core.QueryOptions;
+import com.datastax.driver.core.Session;
+import com.datastax.driver.core.policies.ExponentialReconnectionPolicy;
+import com.datastax.driver.core.policies.ReconnectionPolicy;
+import com.datastax.driver.core.policies.RoundRobinPolicy;
+import com.datastax.driver.core.policies.WhiteListPolicy;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * Represents a connection to Cassandra cluster. Currently supports returning the local connection only as
+ * defined in the Configuration.
+ */
+@Singleton
+public class CQLSession

Review comment:
       I think we can use this class




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

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