Search in sources :

Example 1 with RoutingNode

use of com.yahoo.messagebus.routing.RoutingNode in project vespa by vespa-engine.

the class RPCNetwork method send.

@Override
public void send(Message msg, List<RoutingNode> recipients) {
    SendContext ctx = new SendContext(this, msg, recipients);
    double timeout = ctx.msg.getTimeRemainingNow() / 1000.0;
    for (RoutingNode recipient : ctx.recipients) {
        RPCServiceAddress address = (RPCServiceAddress) recipient.getServiceAddress();
        address.getTarget().resolveVersion(timeout, ctx);
    }
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode)

Example 2 with RoutingNode

use of com.yahoo.messagebus.routing.RoutingNode in project vespa by vespa-engine.

the class RPCNetwork method replyError.

/**
 * Deliver an error reply to the recipients of a {@link SendContext} in a way that avoids entanglement.
 *
 * @param ctx     The send context that contains the recipient data.
 * @param errCode The error code to return.
 * @param errMsg  The error string to return.
 */
private void replyError(SendContext ctx, int errCode, String errMsg) {
    for (RoutingNode recipient : ctx.recipients) {
        Reply reply = new EmptyReply();
        reply.getTrace().setLevel(ctx.traceLevel);
        reply.addError(new Error(errCode, errMsg));
        owner.deliverReply(reply, recipient);
    }
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode) EmptyReply(com.yahoo.messagebus.EmptyReply) Reply(com.yahoo.messagebus.Reply) Error(com.yahoo.messagebus.Error) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 3 with RoutingNode

use of com.yahoo.messagebus.routing.RoutingNode in project vespa by vespa-engine.

the class SendProxy method handleMessage.

public void handleMessage(Message msg) {
    Trace trace = msg.getTrace();
    if (trace.getLevel() == 0) {
        if (log.isLoggable(LogLevel.SPAM)) {
            trace.setLevel(9);
            logTrace = true;
        } else if (log.isLoggable(LogLevel.DEBUG)) {
            trace.setLevel(6);
            logTrace = true;
        }
    }
    this.msg = msg;
    RoutingNode root = new RoutingNode(mbus, net, resender, this, msg);
    root.send();
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode)

Example 4 with RoutingNode

use of com.yahoo.messagebus.routing.RoutingNode 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)

Example 5 with RoutingNode

use of com.yahoo.messagebus.routing.RoutingNode in project vespa by vespa-engine.

the class BasicTests method testNormalUsage.

/**
 * Test that we can send a message through the policy.
 */
public void testNormalUsage() {
    setClusterNodes(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
    // First we want a wrong distribution reply, so make sure we don't try correct node on random
    policyFactory.avoidPickingAtRandom(bucketOneNodePreference[0]);
    RoutingNode target = select();
    replyWrongDistribution(target, "foo", 5, "version:1 bits:16 distributor:10 storage:10");
    // Then send to correct node and verify that
    sendToCorrectNode("foo", bucketOneNodePreference[0]);
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode)

Aggregations

RoutingNode (com.yahoo.messagebus.routing.RoutingNode)7 Reply (com.yahoo.messagebus.Reply)3 EmptyReply (com.yahoo.messagebus.EmptyReply)2 WrongDistributionReply (com.yahoo.documentapi.messagebus.protocol.WrongDistributionReply)1 Error (com.yahoo.messagebus.Error)1 RandomGen (com.yahoo.vdslib.distribution.RandomGen)1