You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ma...@apache.org on 2015/05/26 17:06:15 UTC

[2/2] incubator-kylin git commit: KYLIN-697 refine zookeeperjoblock

KYLIN-697 refine zookeeperjoblock


Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/6d4bbea5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/6d4bbea5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/6d4bbea5

Branch: refs/heads/new697
Commit: 6d4bbea57ae54509d9b8d83e53dc44d6a2edd9bc
Parents: b4726c5
Author: honma <ho...@ebay.com>
Authored: Tue May 26 23:03:57 2015 +0800
Committer: honma <ho...@ebay.com>
Committed: Tue May 26 23:03:57 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/common/lock/ZookeeperJobLock.java   | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/6d4bbea5/common/src/main/java/org/apache/kylin/common/lock/ZookeeperJobLock.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/kylin/common/lock/ZookeeperJobLock.java b/common/src/main/java/org/apache/kylin/common/lock/ZookeeperJobLock.java
index 7a755a3..78da480 100644
--- a/common/src/main/java/org/apache/kylin/common/lock/ZookeeperJobLock.java
+++ b/common/src/main/java/org/apache/kylin/common/lock/ZookeeperJobLock.java
@@ -23,11 +23,14 @@ public class ZookeeperJobLock implements JobLock {
     private Logger logger = LoggerFactory.getLogger(ZookeeperJobLock.class);
 
     private static final String ZOOKEEPER_LOCK_PATH = "/kylin/job_engine/lock";
+
+    private String scheduleID;
     private InterProcessMutex sharedLock;
     private CuratorFramework zkClient;
 
     @Override
     public boolean lock() {
+        this.scheduleID = schedulerId();
         String ZKConnectString = getZKConnectString();
         if (StringUtils.isEmpty(ZKConnectString)) {
             throw new IllegalArgumentException("ZOOKEEPER_QUORUM is empty!");
@@ -36,7 +39,7 @@ public class ZookeeperJobLock implements JobLock {
         RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
         this.zkClient = CuratorFrameworkFactory.newClient(ZKConnectString, retryPolicy);
         this.zkClient.start();
-        this.sharedLock = new InterProcessMutex(zkClient, schedulerId());
+        this.sharedLock = new InterProcessMutex(zkClient, this.scheduleID);
         boolean hasLock = false;
         try {
             hasLock = sharedLock.acquire(3, TimeUnit.SECONDS);
@@ -65,12 +68,12 @@ public class ZookeeperJobLock implements JobLock {
         try {
             if (zkClient.getState().equals(CuratorFrameworkState.STARTED)) {
                 // client.setData().forPath(ZOOKEEPER_LOCK_PATH, null);
-                if (zkClient.checkExists().forPath(schedulerId()) != null) {
-                    zkClient.delete().guaranteed().deletingChildrenIfNeeded().forPath(schedulerId());
+                if (zkClient.checkExists().forPath(scheduleID) != null) {
+                    zkClient.delete().guaranteed().deletingChildrenIfNeeded().forPath(scheduleID);
                 }
             }
         } catch (Exception e) {
-            logger.error("error release lock:" + schedulerId());
+            logger.error("error release lock:" + scheduleID);
             throw new RuntimeException(e);
         }
     }