Search in sources :

Example 66 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class RoutedStoreTest method testPutIncrementsVersion.

@Test
public void testPutIncrementsVersion() throws Exception {
    Store<ByteArray, byte[], byte[]> store = getStore();
    VectorClock clock = new VectorClock();
    VectorClock copy = clock.clone();
    store.put(aKey, new Versioned<byte[]>(getValue(), clock), aTransform);
    List<Versioned<byte[]>> found = store.get(aKey, aTransform);
    assertEquals("Invalid number of items found.", 1, found.size());
    assertEquals("Version not incremented properly", Occurred.BEFORE, copy.compare(found.get(0).getVersion()));
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Example 67 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class RoutedStoreTest method testReadRepairWithFailures.

/**
     * See Issue #89: Sequential retrieval in RoutedStore.get doesn't consider
     * repairReads.
     */
@Test
public void testReadRepairWithFailures() throws Exception {
    cluster = getNineNodeCluster();
    RoutedStore routedStore = getStore(cluster, 2, 2, 1, 0);
    BaseStoreRoutingPlan routingPlan = new BaseStoreRoutingPlan(cluster, this.storeDef);
    List<Integer> replicatingNodes = routingPlan.getReplicationNodeList(aKey.get());
    // This is node 1
    Node primaryNode = Iterables.get(cluster.getNodes(), replicatingNodes.get(0));
    // This is node 6
    Node secondaryNode = Iterables.get(cluster.getNodes(), replicatingNodes.get(1));
    // Disable primary node so that the first put happens with 6 as the
    // pseudo master
    recordException(failureDetector, primaryNode);
    Store<ByteArray, byte[], byte[]> store = new InconsistencyResolvingStore<ByteArray, byte[], byte[]>(routedStore, new VectorClockInconsistencyResolver<byte[]>());
    store.put(aKey, new Versioned<byte[]>(aValue), null);
    byte[] anotherValue = "john".getBytes();
    /*
         * Disable the secondary node and enable primary node to prevent the
         * secondary from getting the new version
         */
    recordException(failureDetector, secondaryNode);
    recordSuccess(failureDetector, primaryNode);
    // Generate the clock based off secondary so that the resulting clock
    // will be [1:1, 6:1] across the replicas, except for the secondary
    // which will be [6:1]
    VectorClock clock = getClock(6);
    store.put(aKey, new Versioned<byte[]>(anotherValue, clock), null);
    // Enable secondary and disable primary, the following get should cause
    // a read repair on the secondary in the code path that is only executed
    // if there are failures. This should repair the secondary with the
    // superceding clock [1:1,6:1]
    recordException(failureDetector, primaryNode);
    recordSuccess(failureDetector, secondaryNode);
    List<Versioned<byte[]>> versioneds = store.get(aKey, null);
    assertEquals(1, versioneds.size());
    assertEquals(new ByteArray(anotherValue), new ByteArray(versioneds.get(0).getValue()));
    // Read repairs are done asynchronously, so we sleep for a short period.
    // It may be a good idea to use a synchronous executor service.
    Thread.sleep(500);
    for (Map.Entry<Integer, Store<ByteArray, byte[], byte[]>> innerStoreEntry : routedStore.getInnerStores().entrySet()) {
        // Only look at the nodes in the pref list
        if (replicatingNodes.contains(innerStoreEntry.getKey())) {
            List<Versioned<byte[]>> innerVersioneds = innerStoreEntry.getValue().get(aKey, null);
            assertEquals(1, versioneds.size());
            assertEquals(new ByteArray(anotherValue), new ByteArray(innerVersioneds.get(0).getValue()));
        }
    }
}
Also used : Versioned(voldemort.versioning.Versioned) Node(voldemort.cluster.Node) VectorClock(voldemort.versioning.VectorClock) Store(voldemort.store.Store) SleepyStore(voldemort.store.SleepyStore) StatTrackingStore(voldemort.store.stats.StatTrackingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) FailingStore(voldemort.store.FailingStore) FailingReadsStore(voldemort.store.FailingReadsStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) ByteArray(voldemort.utils.ByteArray) BaseStoreRoutingPlan(voldemort.routing.BaseStoreRoutingPlan) Map(java.util.Map) HashMap(java.util.HashMap) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Example 68 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class RoutedStoreTest method testBasicOperations.

private void testBasicOperations(int reads, int writes, int failures, int threads, RoutedStore customRoutedStore, long customSleepTime) throws Exception {
    RoutedStore routedStore = null;
    if (customRoutedStore == null) {
        routedStore = getStore(cluster, reads, writes, threads, failures);
    } else {
        routedStore = customRoutedStore;
    }
    Store<ByteArray, byte[], byte[]> store = new InconsistencyResolvingStore<ByteArray, byte[], byte[]>(routedStore, new VectorClockInconsistencyResolver<byte[]>());
    VectorClock clock = getClock(1);
    Versioned<byte[]> versioned = new Versioned<byte[]>(aValue, clock);
    routedStore.put(aKey, versioned, aTransform);
    waitForOperationToComplete(customSleepTime);
    assertNOrMoreEqual(routedStore, cluster.getNumberOfNodes() - failures, aKey, versioned);
    List<Versioned<byte[]>> found = store.get(aKey, aTransform);
    assertEquals(1, found.size());
    assertEquals(versioned, found.get(0));
    waitForOperationToComplete(customSleepTime);
    assertNOrMoreEqual(routedStore, cluster.getNumberOfNodes() - failures, aKey, versioned);
    assertTrue(routedStore.delete(aKey, versioned.getVersion()));
    waitForOperationToComplete(customSleepTime);
    assertNEqual(routedStore, 0, aKey, versioned);
    assertTrue(!routedStore.delete(aKey, versioned.getVersion()));
}
Also used : InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray)

Example 69 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class RocksdbStorageEngineAPITest method generatePutWithConflictionVersions.

public List<Versioned<byte[]>> generatePutWithConflictionVersions(ByteArray key) {
    List<Versioned<byte[]>> versionedList = new ArrayList<Versioned<byte[]>>();
    VectorClock vectorClock1 = new VectorClock();
    vectorClock1.incrementVersion(voldemortConfig.getNodeId(), System.currentTimeMillis());
    Versioned<byte[]> value1 = new Versioned<byte[]>("valueOne".getBytes(), vectorClock1);
    try {
        // Do put
        this.rocksDbStore.put(key, value1, null);
    } catch (PersistenceFailureException pfe) {
        Assert.fail("initial put failed unexpectedly. Exception: " + pfe.getMessage());
    }
    versionedList.add(value1);
    VectorClock vectorClock2 = new VectorClock();
    vectorClock2.incrementVersion(1, System.currentTimeMillis());
    Versioned<byte[]> value2 = new Versioned<byte[]>("valueTwo".getBytes(), vectorClock2);
    try {
        // Do put
        this.rocksDbStore.put(key, value2, null);
    } catch (PersistenceFailureException pfe) {
        Assert.fail("initial put failed unexpectedly. Exception: " + pfe.getMessage());
    }
    versionedList.add(value2);
    return versionedList;
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ArrayList(java.util.ArrayList) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Example 70 with VectorClock

use of voldemort.versioning.VectorClock in project voldemort by voldemort.

the class ViewStorageEngineTest method testPutWithTransforms.

public void testPutWithTransforms() {
    Integer[] values1 = { 9, 90, 10, 15, 25, 106 };
    Integer[] filter1 = { 1, 10 };
    Versioned<List<Integer>> values = Versioned.value(Arrays.asList(values1));
    VectorClock clock = (VectorClock) values.getVersion();
    clock.incrementVersion(0, System.currentTimeMillis());
    view.put(1, Versioned.value(values.getValue(), clock), Arrays.asList(filter1));
    assertEquals(10, view.get(1, Arrays.asList(filter1)).get(0).getValue().size());
    Integer[] filter2 = { 5, 10 };
    assertEquals(6, view.get(1, Arrays.asList(filter2)).get(0).getValue().size());
    Version updatedVersion = view.get(1, Arrays.asList(filter2)).get(0).getVersion();
    Integer[] filter3 = { 1, 50 };
    Integer[] values2 = { 90, 15, 25, 106 };
    clock = (VectorClock) updatedVersion;
    VectorClock clock1 = clock.incremented(0, System.currentTimeMillis());
    view.put(1, Versioned.value(Arrays.asList(values2), clock1), Arrays.asList(filter3));
    assertEquals(12, view.get(1, Arrays.asList(filter3)).get(0).getValue().size());
}
Also used : Version(voldemort.versioning.Version) VectorClock(voldemort.versioning.VectorClock) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

VectorClock (voldemort.versioning.VectorClock)162 Versioned (voldemort.versioning.Versioned)73 Test (org.junit.Test)65 ByteArray (voldemort.utils.ByteArray)65 ArrayList (java.util.ArrayList)33 IOException (java.io.IOException)25 VoldemortException (voldemort.VoldemortException)24 List (java.util.List)22 HashMap (java.util.HashMap)21 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)21 Version (voldemort.versioning.Version)16 Node (voldemort.cluster.Node)15 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)11 StoreDefinition (voldemort.store.StoreDefinition)11 AdminClient (voldemort.client.protocol.admin.AdminClient)10 VoldemortServer (voldemort.server.VoldemortServer)10 Pair (voldemort.utils.Pair)10 ClockEntry (voldemort.versioning.ClockEntry)10 File (java.io.File)8 Map (java.util.Map)8