Search in sources :

Example 1 with LockerProvider

use of org.janusgraph.diskstorage.locking.LockerProvider 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 2 with LockerProvider

use of org.janusgraph.diskstorage.locking.LockerProvider in project janusgraph by JanusGraph.

the class ExpectedValueCheckingTest method setupMocks.

@Before
public void setupMocks() throws BackendException {
    // Initialize mock controller
    ctrl = EasyMock.createStrictControl();
    ctrl.checkOrder(true);
    // Setup some config mocks and objects
    backingManager = ctrl.createMock(KeyColumnValueStoreManager.class);
    LockerProvider lockerProvider = ctrl.createMock(LockerProvider.class);
    ModifiableConfiguration globalConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    ModifiableConfiguration localConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    ModifiableConfiguration defaultConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    // Set some properties on the configs, just so that global/local/default can be easily distinguished
    globalConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "global");
    localConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "local");
    defaultConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "default");
    BaseTransactionConfig defaultTxConfig = new StandardBaseTransactionConfig.Builder().customOptions(defaultConfig).timestampProvider(TimestampProviders.MICRO).build();
    StoreFeatures backingFeatures = new StandardStoreFeatures.Builder().keyConsistent(globalConfig, localConfig).build();
    // Setup behavior specification starts below this line
    // 1. Construct manager
    // The EVCSManager ctor retrieves the backing store's features and stores it in an instance field
    expect(backingManager.getFeatures()).andReturn(backingFeatures).once();
    // 2. Begin transaction
    // EVCTx begins two transactions on the backingManager: one with globalConfig and one with localConfig
    // The capture is used in the @After method to check the config
    txConfigCapture = EasyMock.newCapture(CaptureType.ALL);
    inconsistentTx = ctrl.createMock(StoreTransaction.class);
    consistentTx = ctrl.createMock(StoreTransaction.class);
    expect(backingManager.beginTransaction(capture(txConfigCapture))).andReturn(inconsistentTx);
    expect(backingManager.beginTransaction(capture(txConfigCapture))).andReturn(consistentTx);
    // 3. Open a database
    backingLocker = ctrl.createMock(Locker.class);
    backingStore = ctrl.createMock(KeyColumnValueStore.class);
    expect(backingManager.openDatabase(STORE_NAME)).andReturn(backingStore);
    expect(backingStore.getName()).andReturn(STORE_NAME);
    expect(lockerProvider.getLocker(LOCKER_NAME)).andReturn(backingLocker);
    // Carry out setup behavior against mocks
    ctrl.replay();
    // 1. Construct manager
    expectManager = new ExpectedValueCheckingStoreManager(backingManager, LOCK_SUFFIX, lockerProvider, Duration.ofSeconds(1L));
    // 2. Begin transaction
    expectTx = expectManager.beginTransaction(defaultTxConfig);
    // 3. Open a database
    expectStore = expectManager.openDatabase(STORE_NAME);
    // Verify behavior and reset the mocks for test methods to use
    ctrl.verify();
    ctrl.reset();
}
Also used : StandardStoreFeatures(org.janusgraph.diskstorage.keycolumnvalue.StandardStoreFeatures) StoreFeatures(org.janusgraph.diskstorage.keycolumnvalue.StoreFeatures) Locker(org.janusgraph.diskstorage.locking.Locker) ExpectedValueCheckingStoreManager(org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingStoreManager) KeyColumnValueStore(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) KeyColumnValueStoreManager(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) LockerProvider(org.janusgraph.diskstorage.locking.LockerProvider) Before(org.junit.Before)

Aggregations

Locker (org.janusgraph.diskstorage.locking.Locker)2 LockerProvider (org.janusgraph.diskstorage.locking.LockerProvider)2 ExpectedValueCheckingStoreManager (org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingStoreManager)2 StandardBaseTransactionConfig (org.janusgraph.diskstorage.util.StandardBaseTransactionConfig)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)1 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)1 KeyColumnValueStoreManager (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager)1 StandardStoreFeatures (org.janusgraph.diskstorage.keycolumnvalue.StandardStoreFeatures)1 StoreFeatures (org.janusgraph.diskstorage.keycolumnvalue.StoreFeatures)1 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)1 ConsistentKeyLocker (org.janusgraph.diskstorage.locking.consistentkey.ConsistentKeyLocker)1 ExpectedValueCheckingTransaction (org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction)1 KeyColumn (org.janusgraph.diskstorage.util.KeyColumn)1 Before (org.junit.Before)1 Test (org.junit.Test)1