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