use of voldemort.store.SleepyStore in project voldemort by voldemort.
the class RoutedStoreTest method testSlowStoreDowngradesFromPreferredToRequired.
@Test
public void testSlowStoreDowngradesFromPreferredToRequired() throws Exception {
cluster = VoldemortTestConstants.getThreeNodeCluster();
StoreDefinition storeDef = ServerTestUtils.getStoreDef("test", 3, 3, 2, 3, 1, RoutingStrategyType.CONSISTENT_STRATEGY);
int sleepTimeMs = 500;
Map<Integer, Store<ByteArray, byte[], byte[]>> subStores = Maps.newHashMap();
for (Node node : cluster.getNodes()) {
Store<ByteArray, byte[], byte[]> store = new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test");
if (subStores.isEmpty()) {
store = new SleepyStore<ByteArray, byte[], byte[]>(sleepTimeMs, store);
}
subStores.put(node.getId(), store);
}
setFailureDetector(subStores);
routedStoreThreadPool = Executors.newFixedThreadPool(cluster.getNumberOfNodes());
RoutedStoreFactory routedStoreFactory = createFactory();
RoutedStore routedStore = routedStoreFactory.create(cluster, storeDef, subStores, failureDetector, createConfig(10000L));
routedStore.put(aKey, Versioned.value(aValue), null);
routedStoreFactory = createFactory();
routedStore = routedStoreFactory.create(cluster, storeDef, subStores, failureDetector, createConfig(sleepTimeMs / 2));
List<Versioned<byte[]>> versioneds = routedStore.get(aKey, null);
assertEquals(2, versioneds.size());
}
use of voldemort.store.SleepyStore in project voldemort by voldemort.
the class RoutedStoreTest method testOperationSpecificTimeouts.
@Test
public void testOperationSpecificTimeouts() throws Exception {
StoreDefinition definition = new StoreDefinitionBuilder().setName("test").setType("foo").setKeySerializer(new SerializerDefinition("test")).setValueSerializer(new SerializerDefinition("test")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(3).setPreferredReads(3).setRequiredReads(3).setPreferredWrites(3).setRequiredWrites(3).build();
Map<Integer, Store<ByteArray, byte[], byte[]>> stores = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
List<Node> nodes = new ArrayList<Node>();
for (int i = 0; i < 3; i++) {
Store<ByteArray, byte[], byte[]> store = new SleepyStore<ByteArray, byte[], byte[]>(200, new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test"));
stores.put(i, store);
List<Integer> partitions = Arrays.asList(i);
nodes.add(new Node(i, "none", 0, 0, 0, partitions));
}
setFailureDetector(stores);
routedStoreThreadPool = Executors.newFixedThreadPool(3);
// with a 500ms general timeout and a 100ms get timeout, only get should
// fail
TimeoutConfig timeoutConfig = new TimeoutConfig(1500, false);
timeoutConfig.setOperationTimeout(VoldemortOpCode.GET_OP_CODE, 100);
RoutedStoreFactory routedStoreFactory = createFactory();
RoutedStore routedStore = routedStoreFactory.create(new Cluster("test", nodes), definition, stores, failureDetector, createConfig(timeoutConfig));
try {
routedStore.put(new ByteArray("test".getBytes()), new Versioned<byte[]>(new byte[] { 1 }), null);
} catch (InsufficientOperationalNodesException e) {
fail("Should not have failed");
}
try {
routedStore.get(new ByteArray("test".getBytes()), null);
fail("Should have thrown");
} catch (InsufficientOperationalNodesException e) {
}
}
use of voldemort.store.SleepyStore in project voldemort by voldemort.
the class RoutedStoreTest method getStore.
private RoutedStore getStore(Cluster cluster, int reads, int writes, int zonereads, int zonewrites, int threads, Set<Integer> failing, Set<Integer> sleepy, HashMap<Integer, Integer> zoneReplicationFactor, String strategy, long sleepMs, long timeOutMs, VoldemortException e) throws Exception {
Map<Integer, Store<ByteArray, byte[], byte[]>> subStores = Maps.newHashMap();
for (Node n : cluster.getNodes()) {
Store<ByteArray, byte[], byte[]> subStore = null;
if (failing != null && failing.contains(n.getId()))
subStore = new FailingStore<ByteArray, byte[], byte[]>("test", e);
else if (sleepy != null && sleepy.contains(n.getId()))
subStore = new SleepyStore<ByteArray, byte[], byte[]>(sleepMs, new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test"));
else
subStore = new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test");
subStores.put(n.getId(), subStore);
}
setFailureDetector(subStores);
this.storeDef = ServerTestUtils.getStoreDef("test", reads, reads, writes, writes, zonereads, zonewrites, zoneReplicationFactor, HintedHandoffStrategyType.PROXIMITY_STRATEGY, strategy);
routedStoreThreadPool = Executors.newFixedThreadPool(threads);
RoutedStoreFactory routedStoreFactory = createFactory();
return routedStoreFactory.create(cluster, storeDef, subStores, failureDetector, createConfig(timeOutMs));
}
use of voldemort.store.SleepyStore in project voldemort by voldemort.
the class RoutedStoreTest method testTardyResponsesNotIncludedInResult.
@Test
public void testTardyResponsesNotIncludedInResult() throws Exception {
cluster = VoldemortTestConstants.getThreeNodeCluster();
StoreDefinition storeDef = ServerTestUtils.getStoreDef("test", 3, 3, 2, 3, 1, RoutingStrategyType.CONSISTENT_STRATEGY);
int sleepTimeMs = 500;
Map<Integer, Store<ByteArray, byte[], byte[]>> subStores = Maps.newHashMap();
for (Node node : cluster.getNodes()) {
Store<ByteArray, byte[], byte[]> store = new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test");
if (subStores.isEmpty()) {
store = new SleepyStore<ByteArray, byte[], byte[]>(sleepTimeMs, store);
}
subStores.put(node.getId(), store);
}
setFailureDetector(subStores);
routedStoreThreadPool = Executors.newFixedThreadPool(cluster.getNumberOfNodes());
RoutedStoreFactory routedStoreFactory = createFactory();
RoutedStore routedStore = routedStoreFactory.create(cluster, storeDef, subStores, failureDetector, createConfig(10000L));
routedStore.put(aKey, Versioned.value(aValue), null);
routedStoreFactory = createFactory();
routedStore = routedStoreFactory.create(cluster, storeDef, subStores, failureDetector, createConfig(sleepTimeMs / 2));
List<Versioned<byte[]>> versioneds = routedStore.get(aKey, null);
assertEquals(2, versioneds.size());
// Let's make sure that if the response *does* come in late, that it
// doesn't alter the return value.
Thread.sleep(sleepTimeMs * 2);
assertEquals(2, versioneds.size());
}
use of voldemort.store.SleepyStore 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