helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [1/3] helix git commit: Copy 101tec ZkConnection into Helix code base for customization.
Date Mon, 28 Jan 2019 19:54:02 GMT
Repository: helix
Updated Branches:
  refs/heads/master e8125e8b9 -> 8c8f79c5e


Copy 101tec ZkConnection into Helix code base for customization.

This is the preparation to address a potential reconnect issue in ZkConnection. This change
does not change any logic.


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/060ef363
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/060ef363
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/060ef363

Branch: refs/heads/master
Commit: 060ef363dbe28df326b377d5844a84459cf7aae4
Parents: e8125e8
Author: Jiajun Wang <jjwang@linkedin.com>
Authored: Tue Jan 8 15:27:21 2019 -0800
Committer: jiajunwang <ericwang1985@gmail.com>
Committed: Thu Jan 24 14:27:03 2019 -0800

----------------------------------------------------------------------
 .../org/apache/helix/manager/zk/ZkClient.java   |   2 +-
 .../manager/zk/client/HelixZkClientFactory.java |   2 +-
 .../helix/manager/zk/client/SharedZkClient.java |   2 +-
 .../helix/manager/zk/zookeeper/ZkClient.java    |   1 -
 .../manager/zk/zookeeper/ZkConnection.java      | 163 +++++++++++++++++++
 .../java/org/apache/helix/ZkTestHelper.java     |   2 +-
 .../org/apache/helix/common/ZkTestBase.java     |   2 +-
 .../helix/manager/zk/TestRawZkClient.java       |   2 +-
 .../manager/zk/client/TestHelixZkClient.java    |   2 +-
 9 files changed, 170 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/060ef363/helix-core/src/main/java/org/apache/helix/manager/zk/ZkClient.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkClient.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkClient.java
index 89676db..55c7048 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkClient.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkClient.java
@@ -20,11 +20,11 @@ package org.apache.helix.manager.zk;
  */
 
 import org.I0Itec.zkclient.IZkConnection;
-import org.I0Itec.zkclient.ZkConnection;
 import org.I0Itec.zkclient.serialize.SerializableSerializer;
 import org.I0Itec.zkclient.serialize.ZkSerializer;
 import org.apache.helix.HelixException;
 import org.apache.helix.manager.zk.client.HelixZkClient;
+import org.apache.helix.manager.zk.zookeeper.ZkConnection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

http://git-wip-us.apache.org/repos/asf/helix/blob/060ef363/helix-core/src/main/java/org/apache/helix/manager/zk/client/HelixZkClientFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/client/HelixZkClientFactory.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/client/HelixZkClientFactory.java
index 9d10cd3..e6dc90e 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/client/HelixZkClientFactory.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/client/HelixZkClientFactory.java
@@ -1,8 +1,8 @@
 package org.apache.helix.manager.zk.client;
 
 import org.I0Itec.zkclient.IZkConnection;
-import org.I0Itec.zkclient.ZkConnection;
 import org.apache.helix.HelixException;
+import org.apache.helix.manager.zk.zookeeper.ZkConnection;
 
 /**
  * Abstract class of the ZkClient factory.

http://git-wip-us.apache.org/repos/asf/helix/blob/060ef363/helix-core/src/main/java/org/apache/helix/manager/zk/client/SharedZkClient.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/client/SharedZkClient.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/client/SharedZkClient.java
index 242dea0..5c6ade0 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/client/SharedZkClient.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/client/SharedZkClient.java
@@ -3,8 +3,8 @@ package org.apache.helix.manager.zk.client;
 import java.util.List;
 
 import org.I0Itec.zkclient.IZkConnection;
-import org.I0Itec.zkclient.ZkConnection;
 import org.apache.helix.HelixException;
+import org.apache.helix.manager.zk.zookeeper.ZkConnection;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.data.ACL;
 import org.slf4j.Logger;

http://git-wip-us.apache.org/repos/asf/helix/blob/060ef363/helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkClient.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkClient.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkClient.java
index 132d9e3..5fa2f91 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkClient.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkClient.java
@@ -28,7 +28,6 @@ import org.I0Itec.zkclient.IZkChildListener;
 import org.I0Itec.zkclient.IZkConnection;
 import org.I0Itec.zkclient.IZkDataListener;
 import org.I0Itec.zkclient.IZkStateListener;
-import org.I0Itec.zkclient.ZkConnection;
 import org.I0Itec.zkclient.ZkLock;
 import org.I0Itec.zkclient.exception.ZkBadVersionException;
 import org.I0Itec.zkclient.exception.ZkException;

http://git-wip-us.apache.org/repos/asf/helix/blob/060ef363/helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkConnection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkConnection.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkConnection.java
new file mode 100644
index 0000000..b4a78bb
--- /dev/null
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/zookeeper/ZkConnection.java
@@ -0,0 +1,163 @@
+/**
+ * Copyright 2010 the original author or authors.
+ * Licensed 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.helix.manager.zk.zookeeper;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.I0Itec.zkclient.IZkConnection;
+import org.I0Itec.zkclient.exception.ZkException;
+import org.apache.log4j.Logger;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.Op;
+import org.apache.zookeeper.OpResult;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
+import org.apache.zookeeper.ZooKeeper.States;
+import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Stat;
+
+public class ZkConnection implements IZkConnection {
+
+  private static final Logger LOG = Logger.getLogger(ZkConnection.class);
+
+  /** It is recommended to use quite large sessions timeouts for ZooKeeper. */
+  private static final int DEFAULT_SESSION_TIMEOUT = 30000;
+
+  private ZooKeeper _zk = null;
+  private Lock _zookeeperLock = new ReentrantLock();
+
+  private final String _servers;
+  private final int _sessionTimeOut;
+
+  public ZkConnection(String zkServers) {
+    this(zkServers, DEFAULT_SESSION_TIMEOUT);
+  }
+
+  public ZkConnection(String zkServers, int sessionTimeOut) {
+    _servers = zkServers;
+    _sessionTimeOut = sessionTimeOut;
+  }
+
+  @Override
+  public void connect(Watcher watcher) {
+    _zookeeperLock.lock();
+    try {
+      if (_zk != null) {
+        throw new IllegalStateException("zk client has already been started");
+      }
+      try {
+        LOG.debug("Creating new ZookKeeper instance to connect to " + _servers + ".");
+        _zk = new ZooKeeper(_servers, _sessionTimeOut, watcher);
+      } catch (IOException e) {
+        throw new ZkException("Unable to connect to " + _servers, e);
+      }
+    } finally {
+      _zookeeperLock.unlock();
+    }
+  }
+
+  @Override
+  public void close() throws InterruptedException {
+    _zookeeperLock.lock();
+    try {
+      if (_zk != null) {
+        LOG.debug("Closing ZooKeeper connected to " + _servers);
+        _zk.close();
+        _zk = null;
+      }
+    } finally {
+      _zookeeperLock.unlock();
+    }
+  }
+
+  @Override
+  public String create(String path, byte[] data, CreateMode mode) throws KeeperException,
InterruptedException {
+    return _zk.create(path, data, Ids.OPEN_ACL_UNSAFE, mode);
+  }
+
+  @Override
+  public String create(String path, byte[] data, List<ACL> acl, CreateMode mode) throws
KeeperException, InterruptedException {
+    return _zk.create(path, data, acl, mode);
+  }
+
+  @Override
+  public void delete(String path) throws InterruptedException, KeeperException {
+    _zk.delete(path, -1);
+  }
+
+  @Override
+  public boolean exists(String path, boolean watch) throws KeeperException, InterruptedException
{
+    return _zk.exists(path, watch) != null;
+  }
+
+  @Override
+  public List<String> getChildren(final String path, final boolean watch) throws KeeperException,
InterruptedException {
+    return _zk.getChildren(path, watch);
+  }
+
+  @Override
+  public byte[] readData(String path, Stat stat, boolean watch) throws KeeperException, InterruptedException
{
+    return _zk.getData(path, watch, stat);
+  }
+
+  public void writeData(String path, byte[] data) throws KeeperException, InterruptedException
{
+    writeData(path, data, -1);
+  }
+
+  @Override
+  public void writeData(String path, byte[] data, int version) throws KeeperException, InterruptedException
{
+    _zk.setData(path, data, version);
+  }
+
+  @Override
+  public Stat writeDataReturnStat(String path, byte[] data, int version) throws KeeperException,
InterruptedException {
+    return _zk.setData(path, data, version);
+  }
+
+  @Override
+  public States getZookeeperState() {
+    return _zk != null ? _zk.getState() : null;
+  }
+
+  public ZooKeeper getZookeeper() {
+    return _zk;
+  }
+
+  @Override
+  public long getCreateTime(String path) throws KeeperException, InterruptedException {
+    Stat stat = _zk.exists(path, false);
+    if (stat != null) {
+      return stat.getCtime();
+    }
+    return -1;
+  }
+
+  @Override
+  public String getServers() {
+    return _servers;
+  }
+
+  @Override
+  public List<OpResult> multi(Iterable<Op> ops) throws KeeperException, InterruptedException
{
+    return _zk.multi(ops);
+  }
+
+  @Override
+  public void addAuthInfo(String scheme, byte[] auth) {
+    _zk.addAuthInfo(scheme, auth);
+  }
+}

http://git-wip-us.apache.org/repos/asf/helix/blob/060ef363/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java b/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java
index 19cd2e8..f701ae4 100644
--- a/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java
+++ b/helix-core/src/test/java/org/apache/helix/ZkTestHelper.java
@@ -40,12 +40,12 @@ import java.util.concurrent.TimeUnit;
 import org.I0Itec.zkclient.IZkChildListener;
 import org.I0Itec.zkclient.IZkDataListener;
 import org.I0Itec.zkclient.IZkStateListener;
-import org.I0Itec.zkclient.ZkConnection;
 import org.apache.helix.PropertyKey.Builder;
 import org.apache.helix.manager.zk.ZKHelixDataAccessor;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.manager.zk.ZkClient;
 import org.apache.helix.manager.zk.client.HelixZkClient;
+import org.apache.helix.manager.zk.zookeeper.ZkConnection;
 import org.apache.helix.model.ExternalView;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;

http://git-wip-us.apache.org/repos/asf/helix/blob/060ef363/helix-core/src/test/java/org/apache/helix/common/ZkTestBase.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/common/ZkTestBase.java b/helix-core/src/test/java/org/apache/helix/common/ZkTestBase.java
index b0c44e1..700d204 100644
--- a/helix-core/src/test/java/org/apache/helix/common/ZkTestBase.java
+++ b/helix-core/src/test/java/org/apache/helix/common/ZkTestBase.java
@@ -29,7 +29,6 @@ import java.util.Set;
 import java.util.logging.Level;
 
 import org.I0Itec.zkclient.IZkStateListener;
-import org.I0Itec.zkclient.ZkConnection;
 import org.I0Itec.zkclient.ZkServer;
 import org.apache.helix.BaseDataAccessor;
 import org.apache.helix.ConfigAccessor;
@@ -59,6 +58,7 @@ import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.manager.zk.ZkClient;
 import org.apache.helix.manager.zk.client.DedicatedZkClientFactory;
 import org.apache.helix.manager.zk.client.HelixZkClient;
+import org.apache.helix.manager.zk.zookeeper.ZkConnection;
 import org.apache.helix.model.BuiltInStateModelDefinitions;
 import org.apache.helix.model.ClusterConfig;
 import org.apache.helix.model.ConfigScope;

http://git-wip-us.apache.org/repos/asf/helix/blob/060ef363/helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java b/helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
index 7b232fe..80b2eab 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/TestRawZkClient.java
@@ -31,12 +31,12 @@ import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import org.I0Itec.zkclient.IZkDataListener;
 import org.I0Itec.zkclient.IZkStateListener;
-import org.I0Itec.zkclient.ZkConnection;
 import org.I0Itec.zkclient.ZkServer;
 import org.apache.helix.HelixException;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZNRecord;
 import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.manager.zk.zookeeper.ZkConnection;
 import org.apache.helix.monitoring.mbeans.MBeanRegistrar;
 import org.apache.helix.monitoring.mbeans.MonitorDomainNames;
 import org.apache.helix.monitoring.mbeans.ZkClientMonitor;

http://git-wip-us.apache.org/repos/asf/helix/blob/060ef363/helix-core/src/test/java/org/apache/helix/manager/zk/client/TestHelixZkClient.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/manager/zk/client/TestHelixZkClient.java
b/helix-core/src/test/java/org/apache/helix/manager/zk/client/TestHelixZkClient.java
index 67e2731..aedea29 100644
--- a/helix-core/src/test/java/org/apache/helix/manager/zk/client/TestHelixZkClient.java
+++ b/helix-core/src/test/java/org/apache/helix/manager/zk/client/TestHelixZkClient.java
@@ -22,10 +22,10 @@ package org.apache.helix.manager.zk.client;
 import java.util.concurrent.TimeUnit;
 
 import org.I0Itec.zkclient.IZkDataListener;
-import org.I0Itec.zkclient.ZkConnection;
 import org.apache.helix.HelixException;
 import org.apache.helix.TestHelper;
 import org.apache.helix.ZkUnitTestBase;
+import org.apache.helix.manager.zk.zookeeper.ZkConnection;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 


Mime
View raw message