use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project incubator-atlas by apache.
the class HBaseKeyColumnValueStoreTest method shouldThrowExceptionAfterConfiguredRetriesIfLockMediationFails.
@Test(expectedExceptions = PermanentLockingException.class)
public void shouldThrowExceptionAfterConfiguredRetriesIfLockMediationFails() throws BackendException {
when(storeManager.getMetaDataSchema("hbase")).thenReturn(new EntryMetaData[] { EntryMetaData.TIMESTAMP });
when(storeManager.getStorageConfig()).thenReturn(storageConfig);
when(storageConfig.get(GraphDatabaseConfiguration.LOCK_EXPIRE)).thenReturn(new StandardDuration(300L, TimeUnit.MILLISECONDS));
when(storageConfig.get(GraphDatabaseConfiguration.LOCK_WAIT)).thenReturn(new StandardDuration(10L, TimeUnit.MILLISECONDS));
when(storageConfig.get(GraphDatabaseConfiguration.LOCK_RETRY)).thenReturn(3);
KeyColumn lockID = new KeyColumn(key, column);
when(localLockMediator.lock(eq(lockID), eq(transaction), any(Timepoint.class))).thenReturn(false).thenReturn(false).thenReturn(false);
HBaseKeyColumnValueStore hBaseKeyColumnValueStore = new HBaseKeyColumnValueStore(storeManager, connectionMask, "titan", "e", "hbase", localLockMediator);
hBaseKeyColumnValueStore.acquireLock(key, column, expectedValue, transaction);
fail("Should fail as lock could not be acquired after 3 retries.");
}
use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project incubator-atlas by apache.
the class HBaseKeyColumnValueStore method acquireLock.
@Override
public void acquireLock(StaticBuffer key, StaticBuffer column, StaticBuffer expectedValue, StoreTransaction txh) throws BackendException {
KeyColumn lockID = new KeyColumn(key, column);
logger.debug("Attempting to acquireLock on {} ", lockID);
int trialCount = 0;
boolean locked;
while (trialCount < lockMaxRetries) {
final Timepoint lockStartTime = Timestamps.MILLI.getTime(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
locked = localLockMediator.lock(lockID, txh, lockStartTime.add(lockExpiryTimeMs));
trialCount++;
if (!locked) {
handleLockFailure(txh, lockID, trialCount);
} else {
logger.debug("Acquired lock on {}, {}", lockID, txh);
break;
}
}
((HBaseTransaction) txh).updateLocks(lockID, expectedValue);
}
use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project titan by thinkaurelius.
the class AbstractLocker method deleteLocks.
@Override
public void deleteLocks(StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {
if (null != tx.getConfiguration().getGroupName()) {
MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_DELETE, M_CALLS).inc();
}
Map<KeyColumn, S> m = lockState.getLocksForTx(tx);
Iterator<KeyColumn> iter = m.keySet().iterator();
while (iter.hasNext()) {
KeyColumn kc = iter.next();
S ls = m.get(kc);
try {
deleteSingleLock(kc, ls, tx);
} catch (AssertionError ae) {
// Concession to ease testing with mocks & behavior verification
throw ae;
} catch (Throwable t) {
log.error("Exception while deleting lock on " + kc, t);
if (null != tx.getConfiguration().getGroupName()) {
MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_DELETE, M_CALLS).inc();
}
}
// Regardless of whether we successfully deleted the lock from storage, take it out of the local mediator
llm.unlock(kc, tx);
iter.remove();
}
}
use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project titan by thinkaurelius.
the class ExpectedValueCheckingStore method acquireLock.
/**
* {@inheritDoc}
* <p/>
* This implementation supports locking when {@code lockStore} is non-null.
* <p/>
* Consider the following scenario. This method is called twice with
* identical key, column, and txh arguments, but with different
* expectedValue arguments in each call. In testing, it seems titan's
* graphdb requires that implementations discard the second expectedValue
* and, when checking expectedValues vs actual values just prior to mutate,
* only the initial expectedValue argument should be considered.
*/
@Override
public void acquireLock(StaticBuffer key, StaticBuffer column, StaticBuffer expectedValue, StoreTransaction txh) throws BackendException {
if (locker != null) {
ExpectedValueCheckingTransaction tx = (ExpectedValueCheckingTransaction) txh;
if (tx.isMutationStarted())
throw new PermanentLockingException("Attempted to obtain a lock after mutations had been persisted");
KeyColumn lockID = new KeyColumn(key, column);
log.debug("Attempting to acquireLock on {} ev={}", lockID, expectedValue);
locker.writeLock(lockID, tx.getConsistentTx());
tx.storeExpectedValue(this, lockID, expectedValue);
} else {
store.acquireLock(key, column, expectedValue, unwrapTx(txh));
}
}
use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project incubator-atlas by apache.
the class HBaseKeyColumnValueStoreTest method shouldRetryRightNumberOfTimesIfLockMediationFails.
@Test
public void shouldRetryRightNumberOfTimesIfLockMediationFails() throws BackendException {
when(storeManager.getMetaDataSchema("hbase")).thenReturn(new EntryMetaData[] { EntryMetaData.TIMESTAMP });
when(storeManager.getStorageConfig()).thenReturn(storageConfig);
when(storageConfig.get(GraphDatabaseConfiguration.LOCK_EXPIRE)).thenReturn(new StandardDuration(300L, TimeUnit.MILLISECONDS));
when(storageConfig.get(GraphDatabaseConfiguration.LOCK_WAIT)).thenReturn(new StandardDuration(10L, TimeUnit.MILLISECONDS));
when(storageConfig.get(GraphDatabaseConfiguration.LOCK_RETRY)).thenReturn(3);
KeyColumn lockID = new KeyColumn(key, column);
when(localLockMediator.lock(eq(lockID), eq(transaction), any(Timepoint.class))).thenReturn(false).thenReturn(false).thenReturn(true);
HBaseKeyColumnValueStore hBaseKeyColumnValueStore = new HBaseKeyColumnValueStore(storeManager, connectionMask, "titan", "e", "hbase", localLockMediator);
hBaseKeyColumnValueStore.acquireLock(key, column, expectedValue, transaction);
verify(transaction).updateLocks(lockID, expectedValue);
verify(localLockMediator, times(3)).lock(eq(lockID), eq(transaction), any(Timepoint.class));
}
Aggregations