This is an automated email from the ASF dual-hosted git repository.
dope pushed a commit to branch cluster
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git
The following commit(s) were added to refs/heads/cluster by this push:
new 65f88ac support new port
65f88ac is described below
commit 65f88aca8d8a3f6bc45447b97f99bdb9db852b3a
Author: XuYi <[email protected]>
AuthorDate: Wed Mar 27 10:35:54 2019 +0800
support new port
---
.../apache/iotdb/cluster/utils/hash/Router.java | 30 ++------
.../iotdb/cluster/utils/hash/RouterTest.java | 84 ++++++++--------------
2 files changed, 35 insertions(+), 79 deletions(-)
diff --git
a/cluster/src/main/java/org/apache/iotdb/cluster/utils/hash/Router.java
b/cluster/src/main/java/org/apache/iotdb/cluster/utils/hash/Router.java
index 728d1e1..e47d3a5 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/utils/hash/Router.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/utils/hash/Router.java
@@ -1,21 +1,3 @@
-/**
- * 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.iotdb.cluster.utils.hash;
import java.util.Arrays;
@@ -60,13 +42,13 @@ public class Router {
public void init() {
reset();
ClusterConfig config = ClusterDescriptor.getInstance().getConfig();
- String[] ipList = config.getNodes();
+ String[] hosts = config.getNodes();
this.replicator = config.getReplication();
- int port = config.getPort();
- int numOfVirtulaNodes = config.getNumOfVirtulaNodes();
- for (String ip : ipList) {
- PhysicalNode node = new PhysicalNode(ip, port);
- addNode(node, numOfVirtulaNodes);
+ int numOfVirtualNodes = config.getNumOfVirtulaNodes();
+ for (String host : hosts) {
+ String[] values = host.split(":");
+ PhysicalNode node = new PhysicalNode(values[0],
Integer.parseInt(values[1]));
+ addNode(node, numOfVirtualNodes);
}
PhysicalNode[] nodes = physicalRing.values().toArray(new
PhysicalNode[physicalRing.size()]);
int len = nodes.length;
diff --git
a/cluster/src/test/java/org/apache/iotdb/cluster/utils/hash/RouterTest.java
b/cluster/src/test/java/org/apache/iotdb/cluster/utils/hash/RouterTest.java
index cb9d3ed..697a534 100644
--- a/cluster/src/test/java/org/apache/iotdb/cluster/utils/hash/RouterTest.java
+++ b/cluster/src/test/java/org/apache/iotdb/cluster/utils/hash/RouterTest.java
@@ -1,21 +1,3 @@
-/**
- * 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.iotdb.cluster.utils.hash;
import static org.junit.Assert.*;
@@ -34,15 +16,14 @@ public class RouterTest {
ClusterConfig config = ClusterDescriptor.getInstance().getConfig();
String[] ipListOld;
- int portOld;
int replicatorOld;
int numOfVirtulaNodesOld;
HashFunction function = new MD5Hash();
+ final int PORT = 7777;
@Before
public void setUp() throws Exception {
ipListOld = config.getNodes();
- portOld = config.getPort();
replicatorOld = config.getReplication();
numOfVirtulaNodesOld = config.getNumOfVirtulaNodes();
}
@@ -50,20 +31,18 @@ public class RouterTest {
@After
public void tearDown() throws Exception {
config.setNodes(ipListOld);
- config.setPort(portOld);
config.setReplication(replicatorOld);
config.setNumOfVirtulaNodes(numOfVirtulaNodesOld);
}
@Test
public void testRouteNodeAndGroup1() {
- String[] ipList = {"192.168.130.1", "192.168.130.2", "192.168.130.3",
"192.168.130.4",
- "192.168.130.5",};
- int port = 7777;
+ String[] ipList = {"192.168.130.1:" + PORT, "192.168.130.2:" + PORT,
"192.168.130.3:" + PORT,
+ "192.168.130.4:" + PORT,
+ "192.168.130.5:" + PORT};
int replicator = 3;
int numOfVirtulaNodes = 2;
config.setNodes(ipList);
- config.setPort(port);
config.setReplication(replicator);
config.setNumOfVirtulaNodes(numOfVirtulaNodes);
Router router = Router.getInstance();
@@ -72,11 +51,11 @@ public class RouterTest {
// router.showVirtualRing();
String sg1 = "root.device.sensor";
// System.out.println(function.hash(sg1));
- assertTrue(router.routeNode(sg1).equals(new PhysicalNode("192.168.130.4",
port)));
+ assertTrue(router.routeNode(sg1).equals(new PhysicalNode("192.168.130.4",
PORT)));
PhysicalNode[] expected1 = {
- new PhysicalNode("192.168.130.4", port),
- new PhysicalNode("192.168.130.5", port),
- new PhysicalNode("192.168.130.2", port)
+ new PhysicalNode("192.168.130.4", PORT),
+ new PhysicalNode("192.168.130.5", PORT),
+ new PhysicalNode("192.168.130.2", PORT)
};
assertPhysicalNodeEquals(expected1, router.routeGroup(sg1));
// test cache
@@ -85,11 +64,11 @@ public class RouterTest {
String sg2 = "root.device.sensor2";
// System.out.println(function.hash(sg2));
- assertTrue(router.routeNode(sg2).equals(new PhysicalNode("192.168.130.3",
port)));
+ assertTrue(router.routeNode(sg2).equals(new PhysicalNode("192.168.130.3",
PORT)));
PhysicalNode[] expected2 = {
- new PhysicalNode("192.168.130.3", port),
- new PhysicalNode("192.168.130.4", port),
- new PhysicalNode("192.168.130.5", port)
+ new PhysicalNode("192.168.130.3", PORT),
+ new PhysicalNode("192.168.130.4", PORT),
+ new PhysicalNode("192.168.130.5", PORT)
};
assertPhysicalNodeEquals(expected2, router.routeGroup(sg2));
// test cache
@@ -99,13 +78,11 @@ public class RouterTest {
@Test
public void testRouteNodeAndGroup2() {
- String[] ipList = {"192.168.130.1", "192.168.130.2", "192.168.130.3"};
- int port = 7777;
+ String[] ipList = {"192.168.130.1:" + PORT, "192.168.130.2:" + PORT,
"192.168.130.3:" + PORT};
int replicator = 3;
int numOfVirtulaNodes = 2;
config.setNodes(ipList);
- config.setPort(port);
config.setReplication(replicator);
config.setNumOfVirtulaNodes(numOfVirtulaNodes);
@@ -115,11 +92,11 @@ public class RouterTest {
// router.showVirtualRing();
String sg1 = "root.device.sensor";
// System.out.println(function.hash(sg1));
- assertTrue(router.routeNode(sg1).equals(new PhysicalNode("192.168.130.3",
port)));
+ assertTrue(router.routeNode(sg1).equals(new PhysicalNode("192.168.130.3",
PORT)));
PhysicalNode[] expected1 = {
- new PhysicalNode("192.168.130.3", port),
- new PhysicalNode("192.168.130.2", port),
- new PhysicalNode("192.168.130.1", port)
+ new PhysicalNode("192.168.130.3", PORT),
+ new PhysicalNode("192.168.130.2", PORT),
+ new PhysicalNode("192.168.130.1", PORT)
};
assertPhysicalNodeEquals(expected1, router.routeGroup(sg1));
// test cache
@@ -128,11 +105,11 @@ public class RouterTest {
String sg2 = "root.vehicle.d1";
// System.out.println(function.hash(sg2));
- assertTrue(router.routeNode(sg2).equals(new PhysicalNode("192.168.130.2",
port)));
+ assertTrue(router.routeNode(sg2).equals(new PhysicalNode("192.168.130.2",
PORT)));
PhysicalNode[] expected2 = {
- new PhysicalNode("192.168.130.2", port),
- new PhysicalNode("192.168.130.1", port),
- new PhysicalNode("192.168.130.3", port)
+ new PhysicalNode("192.168.130.2", PORT),
+ new PhysicalNode("192.168.130.1", PORT),
+ new PhysicalNode("192.168.130.3", PORT)
};
assertPhysicalNodeEquals(expected2, router.routeGroup(sg2));
// test cache
@@ -143,14 +120,13 @@ public class RouterTest {
@Test
public void testGenerateGroups1() {
- String[] ipList = {"192.168.130.1", "192.168.130.2", "192.168.130.3",
"192.168.130.4",
- "192.168.130.5",};
- int port = 7777;
+ String[] ipList = {"192.168.130.1:" + PORT, "192.168.130.2:" + PORT,
"192.168.130.3:" + PORT,
+ "192.168.130.4:" + PORT,
+ "192.168.130.5:" + PORT,};
int replicator = 3;
int numOfVirtulaNodes = 2;
config.setNodes(ipList);
- config.setPort(port);
config.setReplication(replicator);
config.setNumOfVirtulaNodes(numOfVirtulaNodes);
@@ -185,20 +161,18 @@ public class RouterTest {
},
};
for (int i = 1; i < 5; i++) {
- PhysicalNode[][] expected = generateNodesArray(ipIndex[i - 1], 3, 3,
port);
- assertPhysicalNodeEquals(expected, router.generateGroups("192.168.130."
+ i, port));
+ PhysicalNode[][] expected = generateNodesArray(ipIndex[i - 1], 3, 3,
PORT);
+ assertPhysicalNodeEquals(expected, router.generateGroups("192.168.130."
+ i, PORT));
}
}
@Test
public void testGenerateGroups2() {
- String[] ipList = {"192.168.130.1", "192.168.130.2", "192.168.130.3"};
- int port = 7777;
+ String[] ipList = {"192.168.130.1:" + PORT, "192.168.130.2:" + PORT,
"192.168.130.3:" + PORT};
int replicator = 3;
int numOfVirtulaNodes = 2;
config.setNodes(ipList);
- config.setPort(port);
config.setReplication(replicator);
config.setNumOfVirtulaNodes(numOfVirtulaNodes);
@@ -217,8 +191,8 @@ public class RouterTest {
},
};
for (int i = 1; i < 4; i++) {
- PhysicalNode[][] expected = generateNodesArray(ipIndex[i - 1], 1, 3,
port);
- assertPhysicalNodeEquals(expected, router.generateGroups("192.168.130."
+ i, port));
+ PhysicalNode[][] expected = generateNodesArray(ipIndex[i - 1], 1, 3,
PORT);
+ assertPhysicalNodeEquals(expected, router.generateGroups("192.168.130."
+ i, PORT));
}
}