@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 |
---|---|
private Abortable |
abort |
static String |
HEARTBEAT_TIME_BUFFER |
private int |
heartbeatTimeBuffer |
private CountDownLatch |
latch |
private AtomicBoolean |
locked |
private org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockRequest |
lockRequest |
private static org.slf4j.Logger |
LOG |
private Long |
procId |
private org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockService.BlockingInterface |
stub |
private long |
testingSleepTime |
private EntityLock.LockHeartbeatWorker |
worker |
Constructor and Description |
---|
EntityLock(org.apache.hadoop.conf.Configuration conf,
org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockService.BlockingInterface stub,
org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockRequest request,
Abortable abort)
Abortable.abort() is called when the lease of the lock will expire.
|
Modifier and Type | Method and Description |
---|---|
void |
await() |
boolean |
await(long timeout,
TimeUnit timeUnit) |
(package private) EntityLock.LockHeartbeatWorker |
getWorker() |
boolean |
isLocked() |
void |
requestLock()
Sends rpc to the master to request lock.
|
(package private) void |
setTestingSleepTime(long timeInMillis) |
String |
toString() |
void |
unlock() |
private static final org.slf4j.Logger LOG
public static final String HEARTBEAT_TIME_BUFFER
private final AtomicBoolean locked
private final CountDownLatch latch
private final org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockService.BlockingInterface stub
private final EntityLock.LockHeartbeatWorker worker
private final org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockRequest lockRequest
private final int heartbeatTimeBuffer
private long testingSleepTime
EntityLock(org.apache.hadoop.conf.Configuration conf, org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockService.BlockingInterface stub, org.apache.hadoop.hbase.shaded.protobuf.generated.LockServiceProtos.LockRequest request, Abortable abort)
@InterfaceAudience.Private void setTestingSleepTime(long timeInMillis)
@InterfaceAudience.Private EntityLock.LockHeartbeatWorker getWorker()
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–2020 The Apache Software Foundation. All rights reserved.