Search in sources :

Example 1 with RandomGen

use of com.yahoo.vdslib.distribution.RandomGen in project vespa by vespa-engine.

the class Simulator method runSimulation.

public void runSimulation(String expected, PersistentFailureTestParameters params) {
    params.validate();
    // Set nodes in slobrok
    setClusterNodes(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
    for (BadNode node : params.getBadNodes().values()) {
        if (node.getFailureType() == FailureType.NODE_NOT_IN_SLOBROK)
            removeNode(node.getIndex());
    }
    {
        RoutingNode target = select();
        replyWrongDistribution(target, "foo", null, params.getInitialClusterState().toString());
    }
    RandomGen randomizer = new RandomGen(432121);
    int[] correctnode = new int[2], wrongnode = new int[2], failed = new int[2], worked = new int[2], downnode = new int[2];
    for (int step = 0, steps = (params.getTotalRequests() / params.getParallellRequests()); step < steps; ++step) {
        int half = (step < steps / 2 ? 0 : 1);
        if (debug)
            System.err.println("Starting step " + step + " in half " + half);
        String[] docId = new String[params.getParallellRequests()];
        RoutingNode[] targets = new RoutingNode[params.getParallellRequests()];
        for (int i = 0; i < params.getParallellRequests(); ++i) {
            docId[i] = "doc:ns:" + (step * params.getParallellRequests() + i);
            frame.setMessage(createMessage(docId[i]));
            targets[i] = select();
        }
        for (int i = 0; i < params.getParallellRequests(); ++i) {
            RoutingNode target = targets[i];
            int index = getAddress(target).getSecond();
            if (!params.getCurrentClusterState(null).getNodeState(new Node(NodeType.DISTRIBUTOR, index)).getState().oneOf(StoragePolicy.owningBucketStates)) {
                ++downnode[half];
            }
            BadNode badNode = params.getBadNodes().get(index);
            if (getAddress(target).getSecond() == getIdealTarget(docId[i], params.getCurrentClusterState(null).toString())) {
                ++correctnode[half];
            } else {
                ++wrongnode[half];
            }
            if (badNode != null && randomizer.nextDouble() < badNode.getFailureRate()) {
                ++failed[half];
                switch(badNode.getFailureType()) {
                    case TRANSIENT_ERROR:
                        replyError(target, new com.yahoo.messagebus.Error(DocumentProtocol.ERROR_BUSY, "Transient error"));
                        break;
                    case FATAL_ERROR:
                        replyError(target, new com.yahoo.messagebus.Error(DocumentProtocol.ERROR_UNPARSEABLE, "Fatal error"));
                        break;
                    case OLD_CLUSTER_STATE:
                    case RESET_CLUSTER_STATE:
                    case RESET_CLUSTER_STATE_NO_GOOD_NODES:
                        replyWrongDistribution(target, "foo", null, params.getCurrentClusterState(index).toString());
                        break;
                    case NODE_NOT_IN_SLOBROK:
                        throw new IllegalStateException("This point in code should not be reachable");
                }
            } else {
                ++worked[half];
                boolean correctTarget = (getAddress(target).getSecond() == getIdealTarget(docId[i], params.getCurrentClusterState(index).toString()));
                if (correctTarget) {
                    replyOk(target);
                } else {
                    replyWrongDistribution(target, "foo", null, params.getCurrentClusterState(index).toString());
                }
            }
        }
    }
    StringBuilder actual = new StringBuilder();
    String[][] result = new String[2][];
    for (int i = 0; i < 2; ++i) {
        actual.append(i == 0 ? "First " : " Last ").append("correctnode ").append(correctnode[i]).append(", wrongnode ").append(wrongnode[i]).append(", downnode ").append(downnode[i]).append(", worked ").append(worked[i]).append(", failed ").append(failed[i]);
    }
    if (!Pattern.matches(expected, actual.toString())) {
        assertEquals(expected, actual.toString());
    }
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode) RandomGen(com.yahoo.vdslib.distribution.RandomGen) RoutingNode(com.yahoo.messagebus.routing.RoutingNode)

Aggregations

RoutingNode (com.yahoo.messagebus.routing.RoutingNode)1 RandomGen (com.yahoo.vdslib.distribution.RandomGen)1