Search in sources :

Example 6 with KeyColumn

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.");
}
Also used : StandardDuration(com.thinkaurelius.titan.diskstorage.util.time.StandardDuration) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn) Timepoint(com.thinkaurelius.titan.diskstorage.util.time.Timepoint) Test(org.testng.annotations.Test)

Example 7 with KeyColumn

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);
}
Also used : KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn) Timepoint(com.thinkaurelius.titan.diskstorage.util.time.Timepoint) Timepoint(com.thinkaurelius.titan.diskstorage.util.time.Timepoint)

Example 8 with KeyColumn

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();
    }
}
Also used : KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn)

Example 9 with KeyColumn

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));
    }
}
Also used : PermanentLockingException(com.thinkaurelius.titan.diskstorage.locking.PermanentLockingException) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn)

Example 10 with KeyColumn

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));
}
Also used : StandardDuration(com.thinkaurelius.titan.diskstorage.util.time.StandardDuration) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn) Timepoint(com.thinkaurelius.titan.diskstorage.util.time.Timepoint) Test(org.testng.annotations.Test)

Aggregations

KeyColumn (com.thinkaurelius.titan.diskstorage.util.KeyColumn)11 Timepoint (com.thinkaurelius.titan.diskstorage.util.time.Timepoint)4 StandardDuration (com.thinkaurelius.titan.diskstorage.util.time.StandardDuration)3 Test (org.junit.Test)3 Test (org.testng.annotations.Test)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 KeySliceQuery (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery)2 StaticArrayEntry (com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry)2 Map (java.util.Map)2 TemporaryBackendException (com.thinkaurelius.titan.diskstorage.TemporaryBackendException)1 KCVMutation (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation)1 Locker (com.thinkaurelius.titan.diskstorage.locking.Locker)1 LockerProvider (com.thinkaurelius.titan.diskstorage.locking.LockerProvider)1 PermanentLockingException (com.thinkaurelius.titan.diskstorage.locking.PermanentLockingException)1 ConsistentKeyLocker (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLocker)1 ExpectedValueCheckingStoreManager (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ExpectedValueCheckingStoreManager)1 ExpectedValueCheckingTransaction (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction)1 StandardBaseTransactionConfig (com.thinkaurelius.titan.diskstorage.util.StandardBaseTransactionConfig)1