|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.hadoop.hbase.zookeeper.lock.ZKInterProcessLockBase
@InterfaceAudience.Private public abstract class ZKInterProcessLockBase
ZooKeeper based HLock implementation. Based on the Shared Locks recipe. (see: ZooKeeper Recipes and Solutions )
| Nested Class Summary | |
|---|---|
protected static class |
ZKInterProcessLockBase.AcquiredLock
Represents information about a lock held by this thread. |
protected static class |
ZKInterProcessLockBase.ZNodeComparator
|
| Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.InterProcessLock |
|---|
InterProcessLock.MetadataHandler |
| Field Summary | |
|---|---|
protected AtomicReference<ZKInterProcessLockBase.AcquiredLock> |
acquiredLock
|
protected String |
childZNode
|
protected String |
fullyQualifiedZNode
|
protected InterProcessLock.MetadataHandler |
handler
|
protected byte[] |
metadata
|
protected String |
parentLockNode
|
protected static String |
READ_LOCK_CHILD_NODE_PREFIX
ZNode prefix used by processes acquiring reader locks |
protected static String |
WRITE_LOCK_CHILD_NODE_PREFIX
ZNode prefix used by processes acquiring writer locks |
protected ZooKeeperWatcher |
zkWatcher
|
| Constructor Summary | |
|---|---|
protected |
ZKInterProcessLockBase(ZooKeeperWatcher zkWatcher,
String parentLockNode,
byte[] metadata,
InterProcessLock.MetadataHandler handler,
String childNode)
Called by implementing classes. |
| Method Summary | |
|---|---|
void |
acquire()
Acquire the lock, waiting indefinitely until the lock is released or the thread is interrupted. |
protected abstract String |
getLockPath(String myZNode,
List<String> children)
Determine based on a list of children under a ZNode, whether or not a process which created a specified ZNode has obtained a lock. |
protected boolean |
handleLockMetadata(String lockZNode)
Process metadata stored in a ZNode using a callback |
protected boolean |
handleLockMetadata(String lockZNode,
InterProcessLock.MetadataHandler handler)
Process metadata stored in a ZNode using a callback object passed to this instance. |
protected boolean |
isChildOfSameType(String child)
Check if a child znode represents the same type(read or write) of lock |
protected static boolean |
isChildReadLock(String child)
Check if a child znode represents a read lock. |
protected static boolean |
isChildWriteLock(String child)
Check if a child znode represents a write lock. |
void |
reapAllLocks()
If supported, attempts to reap all the locks of this type by forcefully deleting the locks (both held and attempted). |
void |
reapExpiredLocks(long timeout)
Will delete all lock znodes of this type (either read or write) which are "expired" according to timeout. |
void |
release()
Release the lock. |
boolean |
tryAcquire(long timeoutMs)
Acquire the lock within a wait time. |
protected void |
updateAcquiredLock(String createdZNode)
Update state as to indicate that a lock is held |
void |
visitLocks(InterProcessLock.MetadataHandler handler)
Visits the locks (both held and attempted) with the given MetadataHandler. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final String READ_LOCK_CHILD_NODE_PREFIX
protected static final String WRITE_LOCK_CHILD_NODE_PREFIX
protected final ZooKeeperWatcher zkWatcher
protected final String parentLockNode
protected final String fullyQualifiedZNode
protected final String childZNode
protected final byte[] metadata
protected final InterProcessLock.MetadataHandler handler
protected final AtomicReference<ZKInterProcessLockBase.AcquiredLock> acquiredLock
| Constructor Detail |
|---|
protected ZKInterProcessLockBase(ZooKeeperWatcher zkWatcher,
String parentLockNode,
byte[] metadata,
InterProcessLock.MetadataHandler handler,
String childNode)
zkWatcher - parentLockNode - The lock ZNode pathmetadata - handler - childNode - The prefix for child nodes created under the parent| Method Detail |
|---|
public void acquire()
throws IOException,
InterruptedException
acquire in interface InterProcessLockIOException - If there is an unrecoverable error releasing the lock
InterruptedException - If current thread is interrupted while
waiting for the lock
public boolean tryAcquire(long timeoutMs)
throws IOException,
InterruptedException
tryAcquire in interface InterProcessLocktimeoutMs - The maximum time (in milliseconds) to wait for the lock,
-1 to wait indefinitely
IOException - If there is an unrecoverable error talking talking
(e.g., when talking to a lock service) when acquiring
the lock
InterruptedException - If the thread is interrupted while waiting to
acquire the lockprotected static boolean isChildReadLock(String child)
child - The child znode we want to check.
protected static boolean isChildWriteLock(String child)
child - The child znode we want to check.
protected boolean isChildOfSameType(String child)
child - The child znode we want to check.
protected void updateAcquiredLock(String createdZNode)
throws IOException
createdZNode - The lock znode
IOException - If an unrecoverable ZooKeeper error occurs
public void release()
throws IOException,
InterruptedException
release in interface InterProcessLockIOException - If there is an unrecoverable error releasing the lock
InterruptedException - If the thread is interrupted while releasing
the lockprotected boolean handleLockMetadata(String lockZNode)
lockZNode - The node holding the metadata
protected boolean handleLockMetadata(String lockZNode,
InterProcessLock.MetadataHandler handler)
lockZNode - The node holding the metadatahandler - the metadata handler
public void reapAllLocks()
throws IOException
InterProcessLockInterProcessLock.reapExpiredLocks(long)
with timeout=0.
reapAllLocks in interface InterProcessLockIOException - If there is an unrecoverable error reaping the locks
public void reapExpiredLocks(long timeout)
throws IOException
reapExpiredLocks in interface InterProcessLockIOException - If there is an unrecoverable error reaping the locks
public void visitLocks(InterProcessLock.MetadataHandler handler)
throws IOException
visitLocks in interface InterProcessLockInterruptedException - If there is an unrecoverable error
IOException
protected abstract String getLockPath(String myZNode,
List<String> children)
throws IOException
myZNode - The ZNode created by the process attempting to acquire
a lockchildren - List of all child ZNodes under the lock's parent ZNode
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||