Search in sources :

Example 61 with Versioned

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

the class StorageServiceTest method testMetadataVersionsInit.

@Test
public void testMetadataVersionsInit() {
    Store<ByteArray, byte[], byte[]> versionStore = storeRepository.getLocalStore(SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name());
    Properties props = new Properties();
    try {
        ByteArray metadataVersionsKey = new ByteArray(SystemStoreConstants.VERSIONS_METADATA_KEY.getBytes());
        List<Versioned<byte[]>> versionList = versionStore.get(metadataVersionsKey, null);
        if (versionList != null && versionList.size() > 0) {
            byte[] versionsByteArray = versionList.get(0).getValue();
            if (versionsByteArray != null) {
                props.load(new ByteArrayInputStream(versionsByteArray));
            } else {
                fail("Illegal value returned for metadata key: " + SystemStoreConstants.VERSIONS_METADATA_KEY);
            }
        } else {
            fail("Illegal value returned for metadata key: " + SystemStoreConstants.VERSIONS_METADATA_KEY);
        }
        // Check if version exists for cluster.xml
        if (!props.containsKey(SystemStoreConstants.CLUSTER_VERSION_KEY)) {
            fail(SystemStoreConstants.CLUSTER_VERSION_KEY + " not present in " + SystemStoreConstants.VERSIONS_METADATA_KEY);
        }
        // Check if version exists for stores.xml
        if (!props.containsKey(SystemStoreConstants.STORES_VERSION_KEY)) {
            fail(SystemStoreConstants.STORES_VERSION_KEY + " not present in " + SystemStoreConstants.VERSIONS_METADATA_KEY);
        }
        // Check if version exists for each store
        for (StoreDefinition def : storeDefs) {
            if (!props.containsKey(def.getName())) {
                fail(def.getName() + " store not present in " + SystemStoreConstants.VERSIONS_METADATA_KEY);
            }
        }
    } catch (Exception e) {
        fail("Error in retrieving : " + SystemStoreConstants.VERSIONS_METADATA_KEY + " key from " + SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name() + " store. ");
    }
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArrayInputStream(java.io.ByteArrayInputStream) StoreDefinition(voldemort.store.StoreDefinition) ByteArray(voldemort.utils.ByteArray) Properties(java.util.Properties) IOException(java.io.IOException) Test(org.junit.Test)

Example 62 with Versioned

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

the class CacheStorageEngineTest method testNoPressureBehavior.

public void testNoPressureBehavior() {
    StorageEngine<ByteArray, byte[], byte[]> engine = getStorageEngine();
    byte[] bytes = "abc".getBytes();
    ByteArray key = new ByteArray(bytes);
    engine.put(key, new Versioned<byte[]>(bytes), null);
    List<Versioned<byte[]>> found = engine.get(key, null);
    assertEquals(1, found.size());
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray)

Example 63 with Versioned

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

the class VersionedPutPruningTest method testPruningLogic.

@Test
public void testPruningLogic() {
    List<Versioned<byte[]>> vals = new ArrayList<Versioned<byte[]>>();
    VectorClock clock1 = TestUtils.getClock(0, 2, 1, 3);
    VectorClock clock2 = TestUtils.getClock(9, 4);
    VectorClock clock3 = TestUtils.getClock(0, 1);
    VectorClock clock4 = TestUtils.getClock(8, 0);
    vals.add(new Versioned<byte[]>(key, clock1));
    vals.add(new Versioned<byte[]>(key, clock2));
    vals.add(new Versioned<byte[]>(key, clock3));
    vals.add(new Versioned<byte[]>(key, clock4));
    MutableBoolean didPrune = new MutableBoolean(false);
    List<Versioned<byte[]>> prunedVals = VersionedPutPruneJob.pruneNonReplicaEntries(vals, keyReplicas, didPrune);
    assertEquals("Must have pruned some versions", true, didPrune.booleanValue());
    assertEquals("Not pruned properly", TestUtils.getClock(0, 1, 2), prunedVals.get(0).getVersion());
    assertEquals("Not pruned properly", TestUtils.getClock(), prunedVals.get(1).getVersion());
    assertEquals("Not pruned properly", TestUtils.getClock(0, 1), prunedVals.get(2).getVersion());
    assertEquals("Not pruned properly", TestUtils.getClock(0), prunedVals.get(3).getVersion());
    List<Versioned<byte[]>> resolvedVals = VectorClockUtils.resolveVersions(prunedVals);
    assertEquals("Must be exactly one winning version", 1, resolvedVals.size());
    assertEquals("Incorrect winning version", TestUtils.getClock(0, 1, 2), resolvedVals.get(0).getVersion());
    assertEquals("Incorrect winning version", clock1.getTimestamp(), ((VectorClock) resolvedVals.get(0).getVersion()).getTimestamp());
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 64 with Versioned

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

the class VersionedPutPruningTest method testOnlineBehavior.

@Test
public void testOnlineBehavior() {
    long now = System.currentTimeMillis();
    // let's assume previous replicas are [4, 5, 0]
    VectorClock fetchedClock = TestUtils.getVersionedPutClock(now, 4, 4, 5, 0);
    VectorClock onlineClock = TestUtils.getVersionedPutClock(now, 0, 0, 2, 1);
    assertEquals("fetched and online versions should conflict", Occurred.CONCURRENTLY, VectorClockUtils.compare(fetchedClock, onlineClock));
    // case where key has received writes before the prune job
    List<Versioned<byte[]>> vals = new ArrayList<Versioned<byte[]>>();
    vals.add(new Versioned<byte[]>(key, fetchedClock));
    vals.add(new Versioned<byte[]>(key, onlineClock));
    MutableBoolean didPrune = new MutableBoolean();
    vals = pruneAndResolve(vals, didPrune);
    assertEquals("Must have pruned something", true, didPrune.booleanValue());
    assertEquals("Must have one winning version", 1, vals.size());
    assertEquals("Must resolve to onlineClock", onlineClock, vals.get(0).getVersion());
    // case where key has not received any writes before the prune job
    vals = new ArrayList<Versioned<byte[]>>();
    vals.add(new Versioned<byte[]>(key, fetchedClock));
    didPrune = new MutableBoolean();
    vals = pruneAndResolve(vals, didPrune);
    assertEquals("Must have pruned something", true, didPrune.booleanValue());
    assertEquals("Must have one winning version", 1, vals.size());
    assertEquals("Must resolve to [0:ts] clock", TestUtils.getVersionedPutClock(now, -1, 0), vals.get(0).getVersion());
    VectorClock nextOnlineClock = TestUtils.getVersionedPutClock(now + Time.MS_PER_SECOND, 0, 0, 2, 1);
    assertFalse("Next online write would not result in conflict", Occurred.CONCURRENTLY == VectorClockUtils.compare((VectorClock) vals.get(0).getVersion(), nextOnlineClock));
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 65 with Versioned

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

the class AbstractByteArrayStoreTest method testEmptyByteArray.

@Test
public void testEmptyByteArray() throws Exception {
    Store<ByteArray, byte[], byte[]> store = getStore();
    Versioned<byte[]> bytes = new Versioned<byte[]>(new byte[0]);
    store.put(new ByteArray(new byte[0]), bytes, null);
    List<Versioned<byte[]>> found = store.get(new ByteArray(new byte[0]), null);
    assertEquals("Incorrect number of results.", 1, found.size());
    assertEquals("Get doesn't equal put.", bytes, found.get(0));
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) Test(org.junit.Test)

Aggregations

Versioned (voldemort.versioning.Versioned)214 ByteArray (voldemort.utils.ByteArray)130 Test (org.junit.Test)88 VectorClock (voldemort.versioning.VectorClock)73 ArrayList (java.util.ArrayList)56 VoldemortException (voldemort.VoldemortException)48 List (java.util.List)36 StoreDefinition (voldemort.store.StoreDefinition)29 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 Node (voldemort.cluster.Node)27 Pair (voldemort.utils.Pair)25 Slop (voldemort.store.slop.Slop)22 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)22 Map (java.util.Map)21 Cluster (voldemort.cluster.Cluster)17 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)15 InvalidMetadataException (voldemort.store.InvalidMetadataException)13 PersistenceFailureException (voldemort.store.PersistenceFailureException)13 Version (voldemort.versioning.Version)13