use of voldemort.store.versioned.InconsistencyResolvingStore in project voldemort by voldemort.
the class RoutedStoreTest method testReadRepairWithFailuresZZZ.
/**
* Test to ensure that read repair happens correctly across zones in case of
* inconsistent writes in a 3 zone cluster.
*
* @throws Exception
*/
@Test
public void testReadRepairWithFailuresZZZ() throws Exception {
cluster = VoldemortTestConstants.getSixNodeClusterWith3Zones();
HashMap<Integer, Integer> zoneReplicationFactor = Maps.newHashMap();
zoneReplicationFactor.put(0, cluster.getNumberOfNodesInZone(0));
zoneReplicationFactor.put(1, cluster.getNumberOfNodesInZone(0));
zoneReplicationFactor.put(2, cluster.getNumberOfNodesInZone(0));
// PR = RR = 6
// PW = RW = 4
// Zone Reads = # Zones - 1
// Zone Writes = 1
// Threads = 1
RoutedStore routedStore = getStore(cluster, 6, 4, cluster.getNumberOfZones() - 1, 1, 1, zoneReplicationFactor);
Store<ByteArray, byte[], byte[]> store = new InconsistencyResolvingStore<ByteArray, byte[], byte[]>(routedStore, new VectorClockInconsistencyResolver<byte[]>());
BaseStoreRoutingPlan routingPlan = new BaseStoreRoutingPlan(cluster, this.storeDef);
List<Integer> replicatingNodes = routingPlan.getReplicationNodeList(aKey.get());
try {
// Do the initial put with all nodes up
store.put(aKey, new Versioned<byte[]>(aValue), null);
List<Version> initialVersions = store.getVersions(aKey);
assertEquals(6, initialVersions.size());
Version mainVersion = initialVersions.get(0);
for (int i = 1; i < initialVersions.size(); i++) {
assertEquals(mainVersion, initialVersions.get(i));
}
// Do another put with all nodes in the zone 0 marked as
// unavailable. This will force the put to use a different pseudo
// master than before.
byte[] anotherValue = "john".getBytes();
// In this cluster, nodes 0 and 1 are in Zone 0. Mark them
// unavailable
recordException(failureDetector, cluster.getNodeById(0));
recordException(failureDetector, cluster.getNodeById(1));
Version newVersion = ((VectorClock) mainVersion).clone();
store.put(aKey, new Versioned<byte[]>(anotherValue, newVersion), null);
waitForOperationToComplete(500);
// Mark the nodes in Zone 0 as available and do a get. The Required
// reads = 4 and Zone count reads = 2 will force the client to read
// from all the zones and do the essential read repairs.
recordSuccess(failureDetector, cluster.getNodeById(0));
recordSuccess(failureDetector, cluster.getNodeById(1));
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()));
}
}
} catch (VoldemortException ve) {
fail("Unexpected error occurred : " + ve);
}
}
use of voldemort.store.versioned.InconsistencyResolvingStore in project voldemort by voldemort.
the class RoutedStoreTest method testPutWithOneNodeDownAndOneNodeSlow.
/**
* See issue #134: RoutedStore put() doesn't wait for enough attempts to
* succeed
*
* This issue would only happen with one node down and another that was slow
* to respond.
*/
@Test
public void testPutWithOneNodeDownAndOneNodeSlow() throws Exception {
cluster = VoldemortTestConstants.getThreeNodeCluster();
StoreDefinition storeDef = ServerTestUtils.getStoreDef("test", 3, 2, 2, 2, 2, RoutingStrategyType.CONSISTENT_STRATEGY);
/* The key used causes the nodes selected for writing to be [2, 0, 1] */
Map<Integer, Store<ByteArray, byte[], byte[]>> subStores = Maps.newHashMap();
int id1 = Iterables.get(cluster.getNodes(), 0).getId();
int id2 = Iterables.get(cluster.getNodes(), 1).getId();
int id3 = Iterables.get(cluster.getNodes(), 2).getId();
subStores.put(id3, new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test"));
subStores.put(id1, new FailingStore<ByteArray, byte[], byte[]>("test"));
/*
* The bug would only show itself if the second successful required
* write was slow (but still within the timeout).
*/
subStores.put(id2, new SleepyStore<ByteArray, byte[], byte[]>(100, new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test")));
setFailureDetector(subStores);
routedStoreThreadPool = Executors.newFixedThreadPool(1);
RoutedStoreFactory routedStoreFactory = createFactory();
RoutedStore routedStore = routedStoreFactory.create(cluster, storeDef, subStores, failureDetector, createConfig(BANNAGE_PERIOD));
Store<ByteArray, byte[], byte[]> store = new InconsistencyResolvingStore<ByteArray, byte[], byte[]>(routedStore, new VectorClockInconsistencyResolver<byte[]>());
store.put(aKey, new Versioned<byte[]>(aValue), aTransform);
}
Aggregations