You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by jx...@apache.org on 2020/04/23 19:35:03 UTC

[helix] branch distributed-lock updated: Change DistributedLock interface APIs (#961)

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

jxue pushed a commit to branch distributed-lock
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/distributed-lock by this push:
     new 3244aa8  Change DistributedLock interface APIs (#961)
3244aa8 is described below

commit 3244aa8b32ffe5c50a608fcfdf730d1b3cc0dd54
Author: Molly Gao <31...@users.noreply.github.com>
AuthorDate: Thu Apr 23 12:34:57 2020 -0700

    Change DistributedLock interface APIs (#961)
    
    Change DistributedLock interface API names to follow Java convention
---
 .../main/java/org/apache/helix/lock/DistributedLock.java | 10 +++++-----
 .../src/main/java/org/apache/helix/lock/LockInfo.java    |  2 +-
 .../java/org/apache/helix/lock/helix/HelixLockScope.java |  1 -
 .../helix/lock/helix/ZKDistributedNonblockingLock.java   |  8 ++++----
 .../helix/lock/helix/TestZKHelixNonblockingLock.java     | 16 ++++++++--------
 5 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/helix-lock/src/main/java/org/apache/helix/lock/DistributedLock.java b/helix-lock/src/main/java/org/apache/helix/lock/DistributedLock.java
index 594ccf4..87247c2 100644
--- a/helix-lock/src/main/java/org/apache/helix/lock/DistributedLock.java
+++ b/helix-lock/src/main/java/org/apache/helix/lock/DistributedLock.java
@@ -24,18 +24,18 @@ package org.apache.helix.lock;
  */
 public interface DistributedLock {
   /**
-   * Blocking call to acquire a lock
+   * Blocking call to acquire a lock if it is free at the time of request
    * @return true if the lock was successfully acquired,
    * false if the lock could not be acquired
    */
-  boolean acquireLock();
+  boolean tryLock();
 
   /**
-   * Blocking call to release a lock
+   * Blocking call to unlock a lock
    * @return true if the lock was successfully released or if the locked is not currently locked,
-   * false if the lock is not locked by the user or the release operation failed
+   * false if the lock is not locked by the user or the unlock operation failed
    */
-  boolean releaseLock();
+  boolean unlock();
 
   /**
    * Retrieve the information of the current lock on the resource this lock object specifies, e.g. lock timeout, lock message, etc.
diff --git a/helix-lock/src/main/java/org/apache/helix/lock/LockInfo.java b/helix-lock/src/main/java/org/apache/helix/lock/LockInfo.java
index 71f7258..a07eb99 100644
--- a/helix-lock/src/main/java/org/apache/helix/lock/LockInfo.java
+++ b/helix-lock/src/main/java/org/apache/helix/lock/LockInfo.java
@@ -19,7 +19,7 @@
 
 package org.apache.helix.lock;
 
-import org.apache.helix.ZNRecord;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
 
 
 /**
diff --git a/helix-lock/src/main/java/org/apache/helix/lock/helix/HelixLockScope.java b/helix-lock/src/main/java/org/apache/helix/lock/helix/HelixLockScope.java
index 8eec472..1a7d98f 100644
--- a/helix-lock/src/main/java/org/apache/helix/lock/helix/HelixLockScope.java
+++ b/helix-lock/src/main/java/org/apache/helix/lock/helix/HelixLockScope.java
@@ -22,7 +22,6 @@ package org.apache.helix.lock.helix;
 import java.util.List;
 
 import org.apache.helix.lock.LockScope;
-import org.apache.helix.model.HelixConfigScope;
 import org.apache.helix.util.StringTemplate;
 
 
diff --git a/helix-lock/src/main/java/org/apache/helix/lock/helix/ZKDistributedNonblockingLock.java b/helix-lock/src/main/java/org/apache/helix/lock/helix/ZKDistributedNonblockingLock.java
index 8fe8c8c..d5ad3a2 100644
--- a/helix-lock/src/main/java/org/apache/helix/lock/helix/ZKDistributedNonblockingLock.java
+++ b/helix-lock/src/main/java/org/apache/helix/lock/helix/ZKDistributedNonblockingLock.java
@@ -21,15 +21,15 @@ package org.apache.helix.lock.helix;
 
 import java.util.Date;
 
-import org.I0Itec.zkclient.DataUpdater;
 import org.apache.helix.AccessOption;
 import org.apache.helix.BaseDataAccessor;
 import org.apache.helix.HelixException;
-import org.apache.helix.ZNRecord;
 import org.apache.helix.lock.DistributedLock;
 import org.apache.helix.lock.LockInfo;
 import org.apache.helix.lock.LockScope;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
+import org.apache.helix.zookeeper.zkclient.DataUpdater;
 import org.apache.log4j.Logger;
 
 
@@ -80,7 +80,7 @@ public class ZKDistributedNonblockingLock implements DistributedLock {
   }
 
   @Override
-  public boolean acquireLock() {
+  public boolean tryLock() {
 
     // Set lock information fields
     long deadline;
@@ -96,7 +96,7 @@ public class ZKDistributedNonblockingLock implements DistributedLock {
 
   //TODO: update release lock logic so it would not leave empty znodes after the lock is released
   @Override
-  public boolean releaseLock() {
+  public boolean unlock() {
     // Initialize the lock updater with a default lock info represents the state of a unlocked lock
     LockUpdater updater = new LockUpdater(LockInfo.defaultLockInfo);
     return _baseDataAccessor.update(_lockPath, updater, AccessOption.PERSISTENT);
diff --git a/helix-lock/src/test/java/org/apache/helix/lock/helix/TestZKHelixNonblockingLock.java b/helix-lock/src/test/java/org/apache/helix/lock/helix/TestZKHelixNonblockingLock.java
index 08cf33b..758c729 100644
--- a/helix-lock/src/test/java/org/apache/helix/lock/helix/TestZKHelixNonblockingLock.java
+++ b/helix-lock/src/test/java/org/apache/helix/lock/helix/TestZKHelixNonblockingLock.java
@@ -27,9 +27,9 @@ import java.util.UUID;
 import java.util.concurrent.Callable;
 
 import org.apache.helix.TestHelper;
-import org.apache.helix.ZNRecord;
 import org.apache.helix.common.ZkTestBase;
 import org.apache.helix.lock.LockInfo;
+import org.apache.helix.zookeeper.datamodel.ZNRecord;
 import org.apache.zookeeper.CreateMode;
 import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
@@ -75,7 +75,7 @@ public class TestZKHelixNonblockingLock extends ZkTestBase {
   public void testAcquireLock() {
 
     // Acquire lock
-    _lock.acquireLock();
+    _lock.tryLock();
     Assert.assertTrue(_gZkClient.exists(_lockPath));
 
     // Get lock information
@@ -87,7 +87,7 @@ public class TestZKHelixNonblockingLock extends ZkTestBase {
     Assert.assertTrue(_lock.isCurrentOwner());
 
     // Release lock
-    _lock.releaseLock();
+    _lock.unlock();
     Assert.assertFalse(_lock.isCurrentOwner());
   }
 
@@ -106,11 +106,11 @@ public class TestZKHelixNonblockingLock extends ZkTestBase {
     Assert.assertFalse(_lock.isCurrentOwner());
 
     // Acquire lock
-    Assert.assertFalse(_lock.acquireLock());
+    Assert.assertFalse(_lock.tryLock());
     Assert.assertFalse(_lock.isCurrentOwner());
 
     // Release lock
-    Assert.assertFalse(_lock.releaseLock());
+    Assert.assertFalse(_lock.unlock());
   }
 
   @Test
@@ -125,11 +125,11 @@ public class TestZKHelixNonblockingLock extends ZkTestBase {
     _gZkClient.create(_lockPath, fakeRecord, CreateMode.PERSISTENT);
 
     // Acquire lock
-    Assert.assertTrue(_lock.acquireLock());
+    Assert.assertTrue(_lock.tryLock());
     Assert.assertTrue(_lock.isCurrentOwner());
 
     // Release lock
-    Assert.assertTrue(_lock.releaseLock());
+    Assert.assertTrue(_lock.unlock());
     Assert.assertFalse(_lock.isCurrentOwner());
   }
 
@@ -156,7 +156,7 @@ public class TestZKHelixNonblockingLock extends ZkTestBase {
 
     @Override
     public Boolean call() throws Exception {
-      return _lock.acquireLock();
+      return _lock.tryLock();
     }
   }
 }