a) count==1 Got the lock b) otherwise
Look for stale locks a) count==1 Got the lock b) otherwise No lock
- Author:
- elandau
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LOCK_TIMEOUT
public static final int LOCK_TIMEOUT
- See Also:
- Constant Field Values
DEFAULT_OPERATION_TIMEOUT_UNITS
public static final TimeUnit DEFAULT_OPERATION_TIMEOUT_UNITS
DEFAULT_LOCK_PREFIX
public static final String DEFAULT_LOCK_PREFIX
- See Also:
- Constant Field Values
ColumnPrefixDistributedRowLock
public ColumnPrefixDistributedRowLock(Keyspace keyspace,
ColumnFamily<K,String> columnFamily,
K key)
withConsistencyLevel
public ColumnPrefixDistributedRowLock<K> withConsistencyLevel(ConsistencyLevel consistencyLevel)
- Modify the consistency level being used. Consistency should always be a
variant of quorum. The default is CL_QUORUM, which is OK for single
region. For multi region the consistency level should be CL_LOCAL_QUORUM.
CL_EACH_QUORUM can be used but will Incur substantial latency.
- Parameters:
consistencyLevel
-
- Returns:
withColumnPrefix
public ColumnPrefixDistributedRowLock<K> withColumnPrefix(String prefix)
- Specify the prefix that uniquely distinguishes the lock columns from data
column
- Parameters:
prefix
-
- Returns:
withLockColumn
public ColumnPrefixDistributedRowLock<K> withLockColumn(String column)
- Override the autogenerated lock column.
- Parameters:
column
-
- Returns:
failOnStaleLock
public ColumnPrefixDistributedRowLock<K> failOnStaleLock(boolean failOnStaleLock)
- When set to true the operation will fail if a stale lock is detected
- Parameters:
failOnStaleLock
-
- Returns:
expireLockAfter
public ColumnPrefixDistributedRowLock<K> expireLockAfter(long timeout,
TimeUnit unit)
- Time for failed locks. Under normal circumstances the lock column will be
deleted. If not then this lock column will remain and the row will remain
locked. The lock will expire after this timeout.
- Parameters:
timeout
- unit
-
- Returns:
withTtl
public ColumnPrefixDistributedRowLock<K> withTtl(Integer ttl)
acquire
public void acquire()
throws Exception
- Write a lock column using the current time
- Specified by:
acquire
in interface DistributedRowLock
- Throws:
Exception
verifyLock
public void verifyLock(long curTimeMicros)
throws Exception,
BusyLockException,
StaleLockException
- Verify that the lock was acquired
- Parameters:
curTimeMicros
-
- Throws:
Exception
BusyLockException
StaleLockException
release
public void release()
throws Exception
- Release the lock by releasing this and any other stale lock columns
- Specified by:
release
in interface DistributedRowLock
- Throws:
Exception
fillReleaseMutation
public void fillReleaseMutation(MutationBatch m)
- Fill a mutation that will release the locks. This may be used from a
separate recipe to release multiple locks.
- Parameters:
m
-
readLockColumns
public Map<String,Long> readLockColumns()
throws Exception
- Return a mapping of existing lock columns and their expiration time
- Returns:
-
- Throws:
Exception
releaseAllLocks
public Map<String,Long> releaseAllLocks()
throws Exception
- Release all locks. Use this carefully as it could release a lock for a
running operation
- Returns:
-
- Throws:
Exception
releaseExpiredLocks
public Map<String,Long> releaseExpiredLocks()
throws Exception
- Release all expired locks for this key.
- Returns:
-
- Throws:
Exception
releaseLocks
public Map<String,Long> releaseLocks(boolean force)
throws Exception
- Delete locks columns. Set force=true to remove locks that haven't been
expired yet.
- Parameters:
force
-
- Returns:
-
- Throws:
Exception
writeLockColumn
protected String writeLockColumn(long time)
throws Exception
- Write a lock for the specified time.
- Parameters:
time
-
- Returns:
- The column name for the lock
- Throws:
Exception
fillLockMutation
public void fillLockMutation(MutationBatch m,
Long time,
Integer ttl)
- Fill a mutation with the lock column. This may be used when the mutation
is executed externally but should be used with extreme caution to ensure
the lock is properly release
- Parameters:
m
- time
- ttl
-
getKeyspace
public Keyspace getKeyspace()
getConsistencyLevel
public ConsistencyLevel getConsistencyLevel()
getLockColumn
public String getLockColumn()
Copyright © 2012. All Rights Reserved.