use of org.janusgraph.diskstorage.locking.Locker 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.Locker in project janusgraph by JanusGraph.
the class Backend method openManagedLocker.
private static Locker openManagedLocker(String classname, String lockerName) {
try {
Class c = Class.forName(classname);
Constructor constructor = c.getConstructor();
Object instance = constructor.newInstance();
Method method = c.getMethod("openLocker", String.class);
Object o = method.invoke(instance, lockerName);
return (Locker) o;
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find implementation class: " + classname);
} catch (InstantiationException | ClassCastException e) {
throw new IllegalArgumentException("Could not instantiate implementation: " + classname, e);
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("Could not find method when configuring locking for: " + classname, e);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access method when configuring locking for: " + classname, e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("Could not invoke method when configuring locking for: " + classname, e);
}
}
use of org.janusgraph.diskstorage.locking.Locker in project janusgraph by JanusGraph.
the class ExpectedValueCheckingTransaction method checkAllLocks.
/**
* Check all locks attempted by earlier
* {@link KeyColumnValueStore#acquireLock(StaticBuffer, StaticBuffer, StaticBuffer, StoreTransaction)}
* calls using this transaction.
*
* @throws org.janusgraph.diskstorage.BackendException
*/
void checkAllLocks() throws BackendException {
StoreTransaction lt = getConsistentTx();
for (ExpectedValueCheckingStore store : expectedValuesByStore.keySet()) {
Locker locker = store.getLocker();
// Ignore locks on stores without a locker
if (null == locker)
continue;
locker.checkLocks(lt);
}
}
use of org.janusgraph.diskstorage.locking.Locker in project janusgraph by JanusGraph.
the class Backend method getLocker.
@Override
public Locker getLocker(String lockerName) {
Preconditions.checkNotNull(lockerName);
Locker l = lockers.get(lockerName);
if (null == l) {
l = lockerCreator.apply(lockerName);
final Locker x = lockers.putIfAbsent(lockerName, l);
if (null != x) {
l = x;
}
}
return l;
}
Aggregations