Search in sources :

Example 1 with ExpectedValueCheckingTransaction

use of org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction in project janusgraph by JanusGraph.

the class LocalLockMediatorTest method testLockExpiration.

@Test
public void testLockExpiration() {
    TimestampProvider times = TimestampProviders.MICRO;
    LocalLockMediator<ExpectedValueCheckingTransaction> llm = new LocalLockMediator<>(LOCK_NAMESPACE, times);
    assertTrue(llm.lock(kc, mockTx1, Instant.EPOCH));
    assertTrue(llm.lock(kc, mockTx2, Instant.MAX));
    llm = new LocalLockMediator<>(LOCK_NAMESPACE, times);
    assertTrue(llm.lock(kc, mockTx1, Instant.MAX));
    assertFalse(llm.lock(kc, mockTx2, Instant.MAX));
}
Also used : TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) ExpectedValueCheckingTransaction(org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction) Test(org.junit.Test)

Example 2 with ExpectedValueCheckingTransaction

use of org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction in project janusgraph by JanusGraph.

the class LockKeyColumnValueStoreTest method testLocksOnMultipleStores.

@Test
public void testLocksOnMultipleStores() throws Exception {
    // the number of stores must be a multiple of 3
    final int numStores = 6;
    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.of())));
        }
    }
    // Mutate
    expManager.mutateMany(builder.build(), tx);
    // Shutdown
    expManager.close();
    // Check the mocks
    verify(mockLockerProvider);
    verify(mockLocker);
}
Also used : Locker(org.janusgraph.diskstorage.locking.Locker) ConsistentKeyLocker(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker) ExpectedValueCheckingStoreManager(org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingStoreManager) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) LockerProvider(org.janusgraph.diskstorage.locking.LockerProvider) ExpectedValueCheckingTransaction(org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction) KeyColumn(org.janusgraph.diskstorage.util.KeyColumn) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 3 with ExpectedValueCheckingTransaction

use of org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction in project janusgraph by JanusGraph.

the class LockKeyColumnValueStoreTest method open.

public void open() throws BackendException {
    manager = new KeyColumnValueStoreManager[CONCURRENCY];
    tx = new StoreTransaction[CONCURRENCY][NUM_TX];
    store = new KeyColumnValueStore[CONCURRENCY];
    for (int i = 0; i < CONCURRENCY; i++) {
        final ModifiableConfiguration sc = GraphDatabaseConfiguration.buildGraphConfiguration();
        sc.set(GraphDatabaseConfiguration.LOCK_LOCAL_MEDIATOR_GROUP, concreteClassName + i);
        sc.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "inst" + i);
        sc.set(GraphDatabaseConfiguration.LOCK_RETRY, 10);
        sc.set(GraphDatabaseConfiguration.LOCK_EXPIRE, Duration.ofMillis(EXPIRE_MS));
        manager[i] = openStorageManager(i, sc);
        StoreFeatures storeFeatures = manager[i].getFeatures();
        store[i] = manager[i].openDatabase(DB_NAME);
        for (int j = 0; j < NUM_TX; j++) {
            tx[i][j] = manager[i].beginTransaction(getTxConfig());
            log.debug("Began transaction of class {}", tx[i][j].getClass().getCanonicalName());
        }
        if (!storeFeatures.hasLocking()) {
            Preconditions.checkArgument(storeFeatures.isKeyConsistent(), "Store needs to support some form of locking");
            KeyColumnValueStore lockerStore = manager[i].openDatabase(DB_NAME + "_lock_");
            ConsistentKeyLocker c = new ConsistentKeyLocker.Builder(lockerStore, manager[i]).fromConfig(sc).mediatorName(concreteClassName + i).build();
            store[i] = new ExpectedValueCheckingStore(store[i], c);
            for (int j = 0; j < NUM_TX; j++) tx[i][j] = new ExpectedValueCheckingTransaction(tx[i][j], manager[i].beginTransaction(getConsistentTxConfig(manager[i])), GraphDatabaseConfiguration.STORAGE_READ_WAITTIME.getDefaultValue());
        }
    }
}
Also used : ExpectedValueCheckingStore(org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingStore) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ConsistentKeyLocker(org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker) ExpectedValueCheckingTransaction(org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction)

Aggregations

ExpectedValueCheckingTransaction (org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction)3 ConsistentKeyLocker (org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)1 Locker (org.janusgraph.diskstorage.locking.Locker)1 LockerProvider (org.janusgraph.diskstorage.locking.LockerProvider)1 ExpectedValueCheckingStore (org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingStore)1 ExpectedValueCheckingStoreManager (org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingStoreManager)1 KeyColumn (org.janusgraph.diskstorage.util.KeyColumn)1 StandardBaseTransactionConfig (org.janusgraph.diskstorage.util.StandardBaseTransactionConfig)1 TimestampProvider (org.janusgraph.diskstorage.util.time.TimestampProvider)1