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

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

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


##########
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:
   Config was natural choice. But from callers we don't always get same object (see AvaticaConnection.config). So this was not feasible. toString() method was another option I had considered, but it was a superset of config.getLbURLs().
   So config.getLbURLs() was a better option here.



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