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));
}
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);
}
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());
}
}
}
Aggregations