@InterfaceAudience.Public public class EntityLock extends Object
Use LockServiceClient
to build instances. Then call requestLock()
.
requestLock()
will contact master to queue the lock and start the heartbeat thread
which will check lock's status periodically and once the lock is acquired, it will send the
heartbeats to the master.
Use await(long, java.util.concurrent.TimeUnit)
or await(long, TimeUnit)
to wait for the lock to be acquired.
Always call unlock()
irrespective of whether lock was acquired or not. If the lock
was acquired, it'll be released. If it was not acquired, it is possible that master grants the
lock in future and the heartbeat thread keeps it alive forever by sending heartbeats.
Calling unlock()
will stop the heartbeat thread and cancel the lock queued on master.
There are 4 ways in which these remote locks may be released/can be lost:
unlock()
.
EntityLock lock = lockServiceClient.*Lock(...., "exampled lock", abortable);
lock.requestLock();
....
....can do other initializations here since lock is 'asynchronous'...
....
if (lock.await(timeout)) {
....logic requiring mutual exclusion
}
lock.unlock();
Modifier and Type | Class and Description |
---|---|
protected class |
EntityLock.LockHeartbeatWorker |
Modifier and Type | Field and Description |
---|---|
static String |
HEARTBEAT_TIME_BUFFER |
Modifier and Type | Method and Description |
---|---|
void |
await() |
boolean |
await(long timeout,
TimeUnit timeUnit) |
boolean |
isLocked() |
void |
requestLock()
Sends rpc to the master to request lock.
|
String |
toString() |
void |
unlock() |
public static final String HEARTBEAT_TIME_BUFFER
public boolean isLocked()
public void requestLock() throws IOException
await()
to wait on lock.
Always call unlock()
after calling the below, even after error.IOException
public boolean await(long timeout, TimeUnit timeUnit) throws InterruptedException
timeout
- in milliseconds. If set to 0, waits indefinitely.InterruptedException
public void await() throws InterruptedException
InterruptedException
public void unlock() throws IOException
IOException
Copyright © 2007–2019 Cloudera. All rights reserved.