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/14 02:30:26 UTC

[helix] 13/19: simplified acquireLock logic

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

commit f1d7b319379477974f9831c2a66fcfac5204c6d4
Author: Molly Gao <mg...@mgao-mn1.linkedin.biz>
AuthorDate: Thu Feb 6 20:40:50 2020 -0800

    simplified acquireLock logic
---
 .../org/apache/helix/lock/ZKHelixNonblockingLock.java    | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/helix-lock/src/main/java/org/apache/helix/lock/ZKHelixNonblockingLock.java b/helix-lock/src/main/java/org/apache/helix/lock/ZKHelixNonblockingLock.java
index 0573228..03e712f 100644
--- a/helix-lock/src/main/java/org/apache/helix/lock/ZKHelixNonblockingLock.java
+++ b/helix-lock/src/main/java/org/apache/helix/lock/ZKHelixNonblockingLock.java
@@ -105,20 +105,8 @@ public class ZKHelixNonblockingLock implements HelixLock {
     }
     lockInfo.setLongField(ZKHelixNonblockingLockInfo.InfoKey.TIMEOUT.name(), deadline);
 
-    // Try to create the lock node
-    boolean success = _baseDataAccessor.create(_lockPath, lockInfo, AccessOption.PERSISTENT);
-
-    // If fail to create the lock node (acquire the lock), compare the timeout timestamp of current lock node with current time, if already passes the timeout, release current lock and try to acquire the lock again
-    if (!success) {
-      Stat stat = new Stat();
-      ZNRecord curLock = _baseDataAccessor.get(_lockPath, stat, AccessOption.PERSISTENT);
-      if (hasTimedOut(curLock)) {
-        // set may fail when the znode version changes in between the get and set, meaning there are some changes in the lock
-        success =
-            _baseDataAccessor.set(_lockPath, lockInfo, stat.getVersion(), AccessOption.PERSISTENT);
-      }
-    }
-    return success;
+    LockUpdater updater = new LockUpdater(lockInfo);
+    return _baseDataAccessor.update(_lockPath, updater, AccessOption.PERSISTENT);
   }
 
   @Override