use of voldemort.store.memory.InMemoryPutAssertionStorageEngine in project voldemort by voldemort.
the class SlopStreamingTest method testSlopStreaming.
/*
* Does streaming puts with one node marked down. Then we drain all slops
* and ensure all keys end up on the right nodes
*/
@Test
public void testSlopStreaming() throws InterruptedException {
testEnv = new SlopStreamingTestEnvironment(1, false);
// 3-2-2 setup
testEnv.setPreferredWrite(2).setRequiredWrite(2);
testEnv.start();
Set<Integer> nodeIds = new HashSet<Integer>();
long startMs = System.currentTimeMillis();
long endMs = startMs + MAX_TOTAL_TIME_MS;
long totalPuts = 0;
long numRejectedPuts = 0;
long numAssertPuts = 0;
streamer = testEnv.makeSlopStreamingClient();
while (true) {
if (System.currentTimeMillis() > endMs) {
break;
}
// generate key
ByteArray key = new ByteArray(TestUtils.randomBytes(KEY_LENGTH));
byte[] value = TestUtils.randomBytes(VALUE_LENGTH);
Versioned<byte[]> outputValue = Versioned.value(value);
// put to nodes
try {
// if put does not throw exception
List<Node> routes = testEnv.routeRequest(key.get());
for (Node node : routes) {
numAssertPuts++;
nodeIds.add(node.getId());
Store<ByteArray, byte[], byte[]> realStore = testEnv.getRealStore(node.getId());
if (realStore instanceof InMemoryPutAssertionStorageEngine) {
((InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>) realStore).assertPut(key);
} else {
fail("realStore is not InMemoryPutAssertionStorageEngine. Test setup is wrong");
}
}
streamer.streamingPut(key, outputValue, testEnv.STORE_NAME);
} catch (InsufficientOperationalNodesException e) {
numRejectedPuts++;
if (logger.isDebugEnabled()) {
logger.debug("Key " + key + " is rejected for InsufficientOperationalNodes");
}
} finally {
totalPuts++;
}
}
streamer.commitToVoldemort();
streamer.closeStreamingSessions();
// bring all servers up
testEnv.warpUp();
try {
streamer.commitToVoldemort();
streamer.closeStreamingSessions();
} catch (Exception e) {
logger.warn(e);
}
// check
long numFailedAssertions = 0;
for (Integer nodeId : nodeIds) {
Store<ByteArray, byte[], byte[]> realStore = testEnv.getRealStore(nodeId);
if (realStore instanceof InMemoryPutAssertionStorageEngine) {
Set<ByteArray> keys = ((InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>) realStore).getFailedAssertions();
for (ByteArray key : keys) {
logger.error("key [" + key + "] is asserted but not recorded on node [" + nodeId + "]");
}
numFailedAssertions += keys.size();
} else {
fail("realStore is not InMemoryPutAssertionStorageEngine");
}
}
logger.info("Total Client Puts Rejected (InsufficientOperationalNodes): " + numRejectedPuts);
logger.info("Total Client Put Operations: " + totalPuts);
logger.info("Total Server Put Assertions: " + numAssertPuts);
logger.info("Total Server Put Lost: " + numFailedAssertions);
assertEquals(numFailedAssertions + " server puts are lost: " + numFailedAssertions, 0L, numFailedAssertions);
}
use of voldemort.store.memory.InMemoryPutAssertionStorageEngine in project voldemort by voldemort.
the class SlopStreamingTestEnvironment method run.
@Override
public void run() {
Random random = new Random(System.currentTimeMillis());
cluster = VoldemortTestConstants.getEightNodeClusterWithZones();
bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
storeDef = storeDefBuilder.build();
// setup store engines
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
// do only once
createInnerStore(nodeId);
}
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
try {
startServer(nodeId);
} catch (IOException e) {
logger.error("Server " + nodeId + "failed to start", e);
}
}
factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
// wait for start of servers
startFinishLatch.countDown();
try {
Set<Integer> nodesToFail = new HashSet<Integer>();
nodesToFail.add(1);
boolean wrapUpSignal = false;
if (logger.isInfoEnabled()) {
if (wrapUpSignal) {
logger.info("Wake Up and wrap up. Make all servers NORMAL");
} else {
logger.info("Wake Up and decide new failure statuses");
}
for (Map.Entry<Integer, Store<ByteArray, byte[], byte[]>> entry : realStores.entrySet()) {
InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]> engine = (InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>) entry.getValue();
logger.info("Outstanding Put Assertions of node [" + entry.getKey() + "]: " + engine.getFailedAssertions().size());
}
}
if (logger.isInfoEnabled()) {
logger.info("Setting nodes to Fail: " + nodesToFail.toString());
}
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
makeNodeNormal(nodeId);
}
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
if (nodesToFail.contains(nodeId)) {
// fail a node if it's normal
if (nodesStatus.get(nodeId) == NodeStatus.NORMAL) {
makeNodeDown(nodeId);
}
} else {
// make node normal if not normal
if (nodesStatus.get(nodeId) != NodeStatus.NORMAL) {
makeNodeNormal(nodeId);
}
}
}
if (throwIntermittentException)
waitForFaultyNodeLatch.countDown();
if (!throwIntermittentException) {
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
makeNodeNormal(nodeId);
}
}
} catch (Exception e) {
} finally {
wrapUpFinishLatch.countDown();
}
}
use of voldemort.store.memory.InMemoryPutAssertionStorageEngine in project voldemort by voldemort.
the class HintedHandoffTestEnvironment method run.
@Override
public void run() {
Random random = new Random(System.currentTimeMillis());
cluster = VoldemortTestConstants.getEightNodeClusterWithZones();
storeDef = storeDefBuilder.build();
// setup store engines
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
// do only once
createInnerStore(nodeId);
}
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
try {
startServer(nodeId);
} catch (IOException e) {
logger.error("Server " + nodeId + "failed to start", e);
}
}
// setup client factory
String bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
// wait for start of servers
startFinishLatch.countDown();
try {
boolean wrapUpSignal = false;
while (!wrapUpSignal) {
if (logger.isInfoEnabled()) {
logger.info("Will sleep for a while or until seeing wrapUpSignal. sleep time: " + statusRefreshIntervalSecond + " Seconds");
}
wrapUpSignal = wrapUpRequestLatch.await(statusRefreshIntervalSecond, TimeUnit.SECONDS);
if (logger.isInfoEnabled()) {
if (wrapUpSignal) {
logger.info("Wake Up and wrap up. Make all servers NORMAL");
minNodesAvailable = NUM_NODES_TOTAL;
} else {
logger.info("Wake Up and decide new failure statuses");
}
for (Map.Entry<Integer, Store<ByteArray, byte[], byte[]>> entry : realStores.entrySet()) {
InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]> engine = (InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>) entry.getValue();
logger.info("Outstanding Put Assertions of node [" + entry.getKey() + "]: " + engine.getFailedAssertions().size());
}
}
// decide random number of cluster nodes(at least 1 alive) with
// random ids to fail
Integer numNodesToFail = random.nextInt(NUM_NODES_TOTAL - minNodesAvailable + 1);
Set<Integer> nodesToFail = getUniqueRandomNumbers(NUM_NODES_TOTAL, numNodesToFail);
if (logger.isInfoEnabled()) {
logger.info("Setting nodes to Fail: " + nodesToFail.toString());
}
for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
if (nodesToFail.contains(nodeId)) {
// fail a node if it's normal
if (nodesStatus.get(nodeId) == NodeStatus.NORMAL) {
// random pick one failure node
Integer failureMode = random.nextInt(3);
switch(failureMode) {
case 0:
makeNodeDown(nodeId);
break;
case 1:
makeNodeSlow(nodeId);
break;
case 2:
makeNodeBdbError(nodeId);
break;
}
}
// otherwise, leave unchanged
} else {
// make node normal if not normal
if (nodesStatus.get(nodeId) != NodeStatus.NORMAL) {
makeNodeNormal(nodeId);
}
// otherwise, leave unchanged
}
}
}
} catch (InterruptedException e) {
} finally {
wrapUpFinishLatch.countDown();
}
}
use of voldemort.store.memory.InMemoryPutAssertionStorageEngine in project voldemort by voldemort.
the class HintedHandoffTestEnvironment method createInnerStore.
/**
* Create inner store and storage engines before server starts
*
* @param nodeId
*/
public void createInnerStore(int nodeId) {
Store<ByteArray, byte[], byte[]> realStore = new InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>(STORE_NAME);
ForceFailStore<ByteArray, byte[], byte[]> forceFailStore = new ForceFailStore<ByteArray, byte[], byte[]>(realStore, new PersistenceFailureException("Force failed"));
SleepyStore<ByteArray, byte[], byte[]> sleepyStore = new SleepyStore<ByteArray, byte[], byte[]>(0, forceFailStore);
realStores.put(nodeId, realStore);
forceFailStores.put(nodeId, forceFailStore);
sleepyStores.put(nodeId, sleepyStore);
}
use of voldemort.store.memory.InMemoryPutAssertionStorageEngine in project voldemort by voldemort.
the class LongHintedHandoffTest method testHintedHandoff.
@Test
public void testHintedHandoff() throws InterruptedException {
Set<Integer> nodeIds = new HashSet<Integer>();
long startMs = System.currentTimeMillis();
long endMs = startMs + MAX_TOTAL_TIME_MS;
long totalPuts = 0;
long numRejectedPuts = 0;
long numAssertPuts = 0;
StoreClient<byte[], byte[]> client = testEnv.makeClient();
while (true) {
if (System.currentTimeMillis() > endMs) {
break;
}
// generate key
ByteArray key = new ByteArray(TestUtils.randomBytes(KEY_LENGTH));
byte[] value = TestUtils.randomBytes(VALUE_LENGTH);
// put to nodes
try {
client.put(key.get(), value);
// if put does not throw exception
List<Node> routes = testEnv.routeRequest(key.get());
for (Node node : routes) {
numAssertPuts++;
nodeIds.add(node.getId());
Store<ByteArray, byte[], byte[]> realStore = testEnv.getRealStore(node.getId());
if (realStore instanceof InMemoryPutAssertionStorageEngine) {
((InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>) realStore).assertPut(key);
} else {
fail("realStore is not InMemoryPutAssertionStorageEngine. Test setup is wrong");
}
}
} catch (InsufficientOperationalNodesException e) {
numRejectedPuts++;
if (logger.isDebugEnabled()) {
logger.debug("Key " + key + " is rejected for InsufficientOperationalNodes");
}
} finally {
totalPuts++;
}
}
// bring all servers up
testEnv.warpUp();
// check
long numFailedAssertions = 0;
for (Integer nodeId : nodeIds) {
Store<ByteArray, byte[], byte[]> realStore = testEnv.getRealStore(nodeId);
if (realStore instanceof InMemoryPutAssertionStorageEngine) {
Set<ByteArray> keys = ((InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>) realStore).getFailedAssertions();
for (ByteArray key : keys) {
logger.error("key [" + key + "] is asserted but not recorded on node [" + nodeId + "]");
}
numFailedAssertions += keys.size();
} else {
fail("realStore is not InMemoryPutAssertionStorageEngine");
}
}
logger.info("Total Client Puts Rejected (InsufficientOperationalNodes): " + numRejectedPuts);
logger.info("Total Client Put Operations: " + totalPuts);
logger.info("Total Server Put Assertions: " + numAssertPuts);
logger.info("Total Server Put Lost: " + numFailedAssertions);
assertEquals(numFailedAssertions + " server puts are lost: " + numFailedAssertions, 0L, numFailedAssertions);
}
Aggregations