You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "stoty (via GitHub)" <gi...@apache.org> on 2023/03/22 08:40:43 UTC

[GitHub] [calcite-avatica] stoty commented on a diff in pull request #217: CALCITE-5581: Client side LB implementation

stoty commented on code in PR #217:
URL: https://github.com/apache/calcite-avatica/pull/217#discussion_r1144363321


##########
core/src/main/java/org/apache/calcite/avatica/remote/Driver.java:
##########
@@ -119,23 +119,25 @@ Service createService(AvaticaConnection connection, ConnectionConfig config) {
     final Service service;
     if (metaFactory != null) {
       service = metaFactory.create(connection);
-    } else if (config.url() != null) {
-      final AvaticaHttpClient httpClient = getHttpClient(connection, config);
-      final Serialization serializationType = getSerialization(config);
-
-      LOG.debug("Instantiating {} service", serializationType);
-      switch (serializationType) {
-      case JSON:
-        service = new RemoteService(httpClient);
-        break;
-      case PROTOBUF:
-        service = new RemoteProtobufService(httpClient, new ProtobufTranslationImpl());
-        break;
-      default:
-        throw new IllegalArgumentException("Unhandled serialization type: " + serializationType);
-      }
     } else {
-      service = new MockJsonService(Collections.<String, String>emptyMap());
+      if (config.url() != null) {

Review Comment:
   This change seems to be eqivalent to the existing code but nests one more if.
   While we want to make sure that we always use curly braces in control statements, else if a special case, which actually improves readability.



##########
core/src/main/java/org/apache/calcite/avatica/ha/RoundRobinLBStrategy.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.calcite.avatica.ha;
+
+import org.apache.calcite.avatica.ConnectionConfig;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Round Robin strategy for client side load balancing.
+ * Its implemented it as a singleton so that we can maintain state
+ * i.e. which URL was last used from the list of URLs specified.
+ */
+public class RoundRobinLBStrategy implements LBStrategy {
+
+  public static final RoundRobinLBStrategy INSTANCE = new RoundRobinLBStrategy();
+  private RoundRobinLBStrategy() { }
+  public static final String URL_SEPERATOR_CHAR = ",";
+
+  Map<String, Integer>  configToIndexServedMap = new HashMap<>();

Review Comment:
   We may consider using the config object itself, instead of just the server list.
   Both have pros and cons.



##########
core/src/main/java/org/apache/calcite/avatica/ha/RoundRobinLBStrategy.java:
##########
@@ -0,0 +1,60 @@
+/*
+ * 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.calcite.avatica.ha;
+
+import org.apache.calcite.avatica.ConnectionConfig;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Round Robin strategy for client side load balancing.
+ * Its implemented it as a singleton so that we can maintain state
+ * i.e. which URL was last used from the list of URLs specified.
+ */
+public class RoundRobinLBStrategy implements LBStrategy {
+
+  public static final RoundRobinLBStrategy INSTANCE = new RoundRobinLBStrategy();
+  private RoundRobinLBStrategy() { }
+  public static final String URL_SEPERATOR_CHAR = ",";
+
+  Map<String, Integer>  configToIndexServedMap = new HashMap<>();
+  @Override
+  public String getLbURL(ConnectionConfig config) {
+    try {
+      String key = getKey(config);
+      String[] urls = config.getLbURLs().split(URL_SEPERATOR_CHAR);

Review Comment:
   We should store the split list, and not re-process on each connection attempt.



-- 
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: commits-unsubscribe@calcite.apache.org

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