Search in sources :

Example 1 with InMemoryPutAssertionStorageEngine

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);
}
Also used : Node(voldemort.cluster.Node) VoldemortException(voldemort.VoldemortException) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) ByteArray(voldemort.utils.ByteArray) InMemoryPutAssertionStorageEngine(voldemort.store.memory.InMemoryPutAssertionStorageEngine) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with InMemoryPutAssertionStorageEngine

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();
    }
}
Also used : Store(voldemort.store.Store) IOException(java.io.IOException) IOException(java.io.IOException) Random(java.util.Random) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ByteArray(voldemort.utils.ByteArray) InMemoryPutAssertionStorageEngine(voldemort.store.memory.InMemoryPutAssertionStorageEngine) StreamingClientConfig(voldemort.client.protocol.admin.StreamingClientConfig) ClientConfig(voldemort.client.ClientConfig) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with InMemoryPutAssertionStorageEngine

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();
    }
}
Also used : Store(voldemort.store.Store) SleepyStore(voldemort.store.SleepyStore) ForceFailStore(voldemort.store.ForceFailStore) IOException(java.io.IOException) Random(java.util.Random) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ByteArray(voldemort.utils.ByteArray) InMemoryPutAssertionStorageEngine(voldemort.store.memory.InMemoryPutAssertionStorageEngine) ClientConfig(voldemort.client.ClientConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with InMemoryPutAssertionStorageEngine

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);
}
Also used : ByteArray(voldemort.utils.ByteArray) InMemoryPutAssertionStorageEngine(voldemort.store.memory.InMemoryPutAssertionStorageEngine) SleepyStore(voldemort.store.SleepyStore) ForceFailStore(voldemort.store.ForceFailStore) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Example 5 with InMemoryPutAssertionStorageEngine

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);
}
Also used : Node(voldemort.cluster.Node) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) ByteArray(voldemort.utils.ByteArray) InMemoryPutAssertionStorageEngine(voldemort.store.memory.InMemoryPutAssertionStorageEngine) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

InMemoryPutAssertionStorageEngine (voldemort.store.memory.InMemoryPutAssertionStorageEngine)5 ByteArray (voldemort.utils.ByteArray)5 HashSet (java.util.HashSet)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Random (java.util.Random)2 Test (org.junit.Test)2 ClientConfig (voldemort.client.ClientConfig)2 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)2 Node (voldemort.cluster.Node)2 ForceFailStore (voldemort.store.ForceFailStore)2 InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)2 SleepyStore (voldemort.store.SleepyStore)2 Store (voldemort.store.Store)2 HashMap (java.util.HashMap)1 VoldemortException (voldemort.VoldemortException)1 StreamingClientConfig (voldemort.client.protocol.admin.StreamingClientConfig)1 PersistenceFailureException (voldemort.store.PersistenceFailureException)1