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