Search in sources :

Example 1 with KeyColumn

use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project titan by thinkaurelius.

the class AbstractLocker method checkLocks.

@Override
public void checkLocks(StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {
    if (null != tx.getConfiguration().getGroupName()) {
        MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
    }
    Map<KeyColumn, S> m = lockState.getLocksForTx(tx);
    if (m.isEmpty()) {
        // no locks for this tx
        return;
    }
    // We never receive interrupts in normal operation; one can only appear
    // during Thread.sleep(), and in that case it probably means the entire
    // Titan process is shutting down; for this reason, we return ASAP on an
    // interrupt
    boolean ok = false;
    try {
        for (KeyColumn kc : m.keySet()) {
            checkSingleLock(kc, m.get(kc), tx);
        }
        ok = true;
    } catch (TemporaryLockingException tle) {
        throw tle;
    } catch (PermanentLockingException ple) {
        throw ple;
    } catch (AssertionError ae) {
        // Concession to ease testing with mocks & behavior verification
        throw ae;
    } catch (InterruptedException e) {
        throw new TemporaryLockingException(e);
    } catch (TemporaryBackendException tse) {
        throw new TemporaryLockingException(tse);
    } catch (Throwable t) {
        throw new PermanentLockingException(t);
    } finally {
        if (!ok && null != tx.getConfiguration().getGroupName()) {
            MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
        }
    }
}
Also used : TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn)

Example 2 with KeyColumn

use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project titan by thinkaurelius.

the class ExpectedValueCheckingTest method testMutateManyWithLockUsesConsistentTx.

@Test
public void testMutateManyWithLockUsesConsistentTx() throws BackendException {
    final ImmutableList<Entry> adds = ImmutableList.of(StaticArrayEntry.of(DATA_COL, DATA_VAL));
    final ImmutableList<StaticBuffer> dels = ImmutableList.<StaticBuffer>of();
    Map<String, Map<StaticBuffer, KCVMutation>> mutations = ImmutableMap.<String, Map<StaticBuffer, KCVMutation>>of(STORE_NAME, ImmutableMap.<StaticBuffer, KCVMutation>of(DATA_KEY, new KCVMutation(adds, dels)));
    final KeyColumn kc = new KeyColumn(LOCK_KEY, LOCK_COL);
    // Acquire a lock
    backingLocker.writeLock(kc, consistentTx);
    // 2. Run mutateMany
    // 2.1. Check locks & expected values before mutating data
    backingLocker.checkLocks(consistentTx);
    StaticBuffer nextBuf = BufferUtil.nextBiggerBuffer(kc.getColumn());
    KeySliceQuery expectedValueQuery = new KeySliceQuery(kc.getKey(), kc.getColumn(), nextBuf);
    // expected value read must use strong consistency
    expect(backingStore.getSlice(expectedValueQuery, consistentTx)).andReturn(StaticArrayEntryList.of(StaticArrayEntry.of(LOCK_COL, LOCK_VAL)));
    // 2.2. Run mutateMany on backing manager to modify data
    // writes by txs with locks must use strong consistency
    backingManager.mutateMany(mutations, consistentTx);
    ctrl.replay();
    // Lock acquisition
    expectStore.acquireLock(LOCK_KEY, LOCK_COL, LOCK_VAL, expectTx);
    // Mutate
    expectManager.mutateMany(mutations, expectTx);
}
Also used : StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn) KCVMutation(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KCVMutation) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.Test)

Example 3 with KeyColumn

use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project titan by thinkaurelius.

the class LockKeyColumnValueStoreTest method testLocksOnMultipleStores.

@Test
public void testLocksOnMultipleStores() throws Exception {
    final int numStores = 6;
    Preconditions.checkState(numStores % 3 == 0);
    final StaticBuffer key = BufferUtil.getLongBuffer(1);
    final StaticBuffer col = BufferUtil.getLongBuffer(2);
    final StaticBuffer val2 = BufferUtil.getLongBuffer(8);
    // Create mocks
    LockerProvider mockLockerProvider = createStrictMock(LockerProvider.class);
    Locker mockLocker = createStrictMock(Locker.class);
    // Create EVCSManager with mockLockerProvider
    ExpectedValueCheckingStoreManager expManager = new ExpectedValueCheckingStoreManager(manager[0], "multi_store_lock_mgr", mockLockerProvider, Duration.ofMillis(100L));
    // Begin EVCTransaction
    BaseTransactionConfig txCfg = StandardBaseTransactionConfig.of(times);
    ExpectedValueCheckingTransaction tx = expManager.beginTransaction(txCfg);
    // openDatabase calls getLocker, and we do it numStores times
    expect(mockLockerProvider.getLocker(anyObject(String.class))).andReturn(mockLocker).times(numStores);
    // acquireLock calls writeLock, and we do it 2/3 * numStores times
    mockLocker.writeLock(eq(new KeyColumn(key, col)), eq(tx.getConsistentTx()));
    expectLastCall().times(numStores / 3 * 2);
    // mutateMany calls checkLocks, and we do it 2/3 * numStores times
    mockLocker.checkLocks(tx.getConsistentTx());
    expectLastCall().times(numStores / 3 * 2);
    replay(mockLockerProvider);
    replay(mockLocker);
    /*
         * Acquire a lock on several distinct stores (numStores total distinct
         * stores) and build mutations.
         */
    ImmutableMap.Builder<String, Map<StaticBuffer, KCVMutation>> builder = ImmutableMap.builder();
    for (int i = 0; i < numStores; i++) {
        String storeName = "multi_store_lock_" + i;
        KeyColumnValueStore s = expManager.openDatabase(storeName);
        if (i % 3 < 2)
            s.acquireLock(key, col, null, tx);
        if (i % 3 > 0)
            builder.put(storeName, ImmutableMap.of(key, new KCVMutation(ImmutableList.of(StaticArrayEntry.of(col, val2)), ImmutableList.<StaticBuffer>of())));
    }
    // Mutate
    expManager.mutateMany(builder.build(), tx);
    // Shutdown
    expManager.close();
    // Check the mocks
    verify(mockLockerProvider);
    verify(mockLocker);
}
Also used : Locker(com.thinkaurelius.titan.diskstorage.locking.Locker) ConsistentKeyLocker(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLocker) ExpectedValueCheckingStoreManager(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ExpectedValueCheckingStoreManager) StandardBaseTransactionConfig(com.thinkaurelius.titan.diskstorage.util.StandardBaseTransactionConfig) LockerProvider(com.thinkaurelius.titan.diskstorage.locking.LockerProvider) ExpectedValueCheckingTransaction(com.thinkaurelius.titan.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 4 with KeyColumn

use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project titan by thinkaurelius.

the class ExpectedValueCheckingTest method testMutateWithLockUsesConsistentTx.

@Test
public void testMutateWithLockUsesConsistentTx() throws BackendException {
    final ImmutableList<Entry> adds = ImmutableList.of(StaticArrayEntry.of(DATA_COL, DATA_VAL));
    final ImmutableList<StaticBuffer> dels = ImmutableList.<StaticBuffer>of();
    final KeyColumn kc = new KeyColumn(LOCK_KEY, LOCK_COL);
    // 1. Acquire a lock
    backingLocker.writeLock(kc, consistentTx);
    // 2. Run a mutation
    // N.B. mutation coordinates do not overlap with the lock, but consistentTx should be used anyway
    // 2.1. Check locks & expected values before mutating data
    backingLocker.checkLocks(consistentTx);
    StaticBuffer nextBuf = BufferUtil.nextBiggerBuffer(kc.getColumn());
    KeySliceQuery expectedValueQuery = new KeySliceQuery(kc.getKey(), kc.getColumn(), nextBuf);
    // expected value read must use strong consistency
    expect(backingStore.getSlice(expectedValueQuery, consistentTx)).andReturn(StaticArrayEntryList.of(StaticArrayEntry.of(LOCK_COL, LOCK_VAL)));
    // 2.2. Mutate data
    // writes by txs with locks must use strong consistency
    backingStore.mutate(DATA_KEY, adds, dels, consistentTx);
    ctrl.replay();
    // 1. Lock acquisition
    expectStore.acquireLock(LOCK_KEY, LOCK_COL, LOCK_VAL, expectTx);
    // 2. Mutate
    expectStore.mutate(DATA_KEY, adds, dels, expectTx);
}
Also used : StaticArrayEntry(com.thinkaurelius.titan.diskstorage.util.StaticArrayEntry) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn) KeySliceQuery(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeySliceQuery) Test(org.junit.Test)

Example 5 with KeyColumn

use of com.thinkaurelius.titan.diskstorage.util.KeyColumn in project incubator-atlas by apache.

the class HBaseKeyColumnValueStoreTest method shouldSucceedInLockingIfLockMediatorSucceeds.

@Test
public void shouldSucceedInLockingIfLockMediatorSucceeds() 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(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(1)).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