You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by st...@apache.org on 2020/05/17 14:24:43 UTC

[phoenix-queryserver] branch master updated: PHOENIX-5852 The zkConnectionString in LoadBalance is incorrect

This is an automated email from the ASF dual-hosted git repository.

stoty pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix-queryserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 5182951  PHOENIX-5852 The zkConnectionString in LoadBalance is incorrect
5182951 is described below

commit 518295158b16d1e57ff7dc7ccec124ec0761de8c
Author: Baiqiang Zhao <zb...@gmail.com>
AuthorDate: Thu Apr 16 19:36:42 2020 +0800

    PHOENIX-5852 The zkConnectionString in LoadBalance is incorrect
---
 .../service/LoadBalanceZookeeperConfImpl.java      |  5 +-
 .../service/LoadBalanceZookeeperConfImplTest.java  | 60 ++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/load-balancer/src/main/java/org/apache/phoenix/loadbalancer/service/LoadBalanceZookeeperConfImpl.java b/load-balancer/src/main/java/org/apache/phoenix/loadbalancer/service/LoadBalanceZookeeperConfImpl.java
index 807295b..17294cb 100644
--- a/load-balancer/src/main/java/org/apache/phoenix/loadbalancer/service/LoadBalanceZookeeperConfImpl.java
+++ b/load-balancer/src/main/java/org/apache/phoenix/loadbalancer/service/LoadBalanceZookeeperConfImpl.java
@@ -23,6 +23,7 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.net.HostAndPort;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.zookeeper.ZKConfig;
 import org.apache.phoenix.queryserver.QueryServerOptions;
 import org.apache.phoenix.queryserver.QueryServerProperties;
 import org.apache.zookeeper.ZooDefs;
@@ -65,8 +66,8 @@ public class LoadBalanceZookeeperConfImpl implements LoadBalanceZookeeperConf {
 
         @Override
         public String getZkConnectString(){
-            return String.format("%s:%s",configuration.get(QueryServerProperties.ZOOKEEPER_QUORUM_ATTRIB,
-                    "localhost"),configuration.get(QueryServerProperties.ZOOKEEPER_PORT_ATTRIB,"2181"));
+            return ZKConfig.standardizeZKQuorumServerString(configuration.get(QueryServerProperties.ZOOKEEPER_QUORUM_ATTRIB,
+                    "localhost"), configuration.get(QueryServerProperties.ZOOKEEPER_PORT_ATTRIB, "2181"));
         }
 
         private String getZkLbUserName(){
diff --git a/load-balancer/src/test/java/org/apache/phoenix/loadbalancer/service/LoadBalanceZookeeperConfImplTest.java b/load-balancer/src/test/java/org/apache/phoenix/loadbalancer/service/LoadBalanceZookeeperConfImplTest.java
new file mode 100644
index 0000000..b88b67e
--- /dev/null
+++ b/load-balancer/src/test/java/org/apache/phoenix/loadbalancer/service/LoadBalanceZookeeperConfImplTest.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.phoenix.loadbalancer.service;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.phoenix.queryserver.QueryServerProperties;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class LoadBalanceZookeeperConfImplTest {
+    @Test
+    public void testZkConnectString() {
+        // server port is different from the port which is set by user
+        testZKClusterKey("server:2183", "2182");
+        // multiple servers have their own port
+        testZKClusterKey("server1:2182,server2:2183,server3:2184", "2181");
+        // some servers no specified port
+        testZKClusterKey("server1,server2:2181,server3:2182", "2181");
+        testZKClusterKey("server1:2182,server2,server3:2183", "2181");
+        testZKClusterKey("server1:2182,server2:2183,server3", "2181");
+        testZKClusterKey("server1:2182,server2,server3:2183", "2184");
+        // no port set
+        testZKClusterKey("server1,server2,server3", "");
+        testZKClusterKey("server1:2182,server2,server3:2183", "");
+    }
+
+    private void testZKClusterKey(String quorum, String port) {
+        final Configuration conf = HBaseConfiguration.create();
+        conf.set(QueryServerProperties.ZOOKEEPER_QUORUM_ATTRIB, quorum);
+        conf.set(QueryServerProperties.ZOOKEEPER_PORT_ATTRIB, port);
+        final LoadBalanceZookeeperConfImpl loadBalanceZookeeperConf = new LoadBalanceZookeeperConfImpl(conf);
+        String[] connectStrings = loadBalanceZookeeperConf.getZkConnectString().split(",");
+        String[] quorums = quorum.split(",");
+        Assert.assertTrue( connectStrings.length == quorums.length);
+        for (int i = 0; i< connectStrings.length; ++i) {
+            if (quorums[i].contains(":")) {
+                Assert.assertEquals(quorums[i], connectStrings[i]);
+            } else {
+                Assert.assertEquals(quorums[i] + ":" + port, connectStrings[i]);
+            }
+        }
+    }
+}