Search in sources :

Example 41 with Error

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

the class RPCSendV2 method createReply.

@Override
protected Reply createReply(Values ret, String serviceName, Trace trace) {
    CompressionType compression = CompressionType.valueOf(ret.get(3).asInt8());
    byte[] slimeBytes = compressor.decompress(ret.get(5).asData(), compression, ret.get(4).asInt32());
    Slime slime = BinaryFormat.decode(slimeBytes);
    Inspector root = slime.get();
    Version version = new Version(root.field(VERSION_F).asString());
    byte[] payload = root.field(BLOB_F).asData();
    // Make sure that the owner understands the protocol.
    Reply reply = null;
    Error error = null;
    if (payload.length > 0) {
        Object retval = decode(new Utf8Array(root.field(PROTOCOL_F).asUtf8()), version, payload);
        if (retval instanceof Reply) {
            reply = (Reply) retval;
        } else {
            error = (Error) retval;
        }
    }
    if (reply == null) {
        reply = new EmptyReply();
    }
    if (error != null) {
        reply.addError(error);
    }
    reply.setRetryDelay(root.field(RETRYDELAY_F).asDouble());
    Inspector errors = root.field(ERRORS_F);
    for (int i = 0; i < errors.entries(); i++) {
        Inspector e = errors.entry(i);
        String service = e.field(SERVICE_F).asString();
        reply.addError(new Error((int) e.field(CODE_F).asLong(), e.field(MSG_F).asString(), (service != null && service.length() > 0) ? service : serviceName));
    }
    if (trace.getLevel() > 0) {
        trace.getRoot().addChild(TraceNode.decode(root.field(TRACE_F).asString()));
    }
    return reply;
}
Also used : Version(com.yahoo.component.Version) Inspector(com.yahoo.slime.Inspector) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) Slime(com.yahoo.slime.Slime) CompressionType(com.yahoo.compress.CompressionType) Utf8Array(com.yahoo.text.Utf8Array) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 42 with Error

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

the class RoutingNode method getUnconsumedErrors.

/**
 * Return any errors preventing transmitting along this routing tree to possibly succeed. This might happen if
 * either a) there are no leaf nodes to send to, or b) some leaf node contains a fatal error that is not masked by a
 * routing policy above it in the tree. If only transient errors would reach this, the resend flag is set to true.
 *
 * @return The errors concatenated or null.
 */
private String getUnconsumedErrors() {
    StringBuilder errors = null;
    Deque<RoutingNode> stack = new ArrayDeque<>();
    stack.push(this);
    while (!stack.isEmpty()) {
        RoutingNode node = stack.pop();
        if (node.reply != null) {
            for (int i = 0; i < node.reply.getNumErrors(); ++i) {
                Error error = node.reply.getError(i);
                int errorCode = error.getCode();
                RoutingNode it = node;
                while (it != null) {
                    if (it.routingContext != null && it.routingContext.isConsumableError(errorCode)) {
                        errorCode = ErrorCode.NONE;
                        break;
                    }
                    it = it.parent;
                }
                if (errorCode != ErrorCode.NONE) {
                    if (errors == null) {
                        errors = new StringBuilder();
                    } else {
                        errors.append("\n");
                    }
                    errors.append(error.toString());
                    shouldRetry = resender != null && resender.canRetry(errorCode);
                    if (!shouldRetry) {
                        // no need to continue
                        return errors.toString();
                    }
                }
            }
        } else {
            for (RoutingNode child : node.children) {
                stack.push(child);
            }
        }
    }
    return errors != null ? errors.toString() : null;
}
Also used : Error(com.yahoo.messagebus.Error)

Example 43 with Error

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

the class ReplyMergerTestCase method mergingSingleReplyWithOneErrorReturnsEmptyReplyWithError.

@Test
public void mergingSingleReplyWithOneErrorReturnsEmptyReplyWithError() {
    Reply r1 = new EmptyReply();
    Error error = new Error(1234, "oh no!");
    r1.addError(error);
    merger.merge(0, r1);
    Tuple2<Integer, Reply> ret = merger.mergedReply();
    assertThat(ret.first, nullValue());
    assertThat(ret.second, not(sameInstance(r1)));
    assertThatErrorsMatch(new Error[] { error }, ret);
}
Also used : Error(com.yahoo.messagebus.Error) Test(org.junit.Test)

Example 44 with Error

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

the class StoragePolicy method merge.

@Override
public void merge(RoutingContext context) {
    RoutingNodeIterator it = context.getChildIterator();
    Reply reply = (it.hasReply()) ? it.removeReply() : context.getReply();
    if (reply == null) {
        reply = new EmptyReply();
        reply.addError(new Error(ErrorCode.NO_ADDRESS_FOR_SERVICE, "No reply in any children, nor in the routing context: " + context));
    }
    if (reply instanceof WrongDistributionReply) {
        distributorSelectionLogic.handleWrongDistribution((WrongDistributionReply) reply, context);
    } else if (reply.hasErrors()) {
        distributorSelectionLogic.handleErrorReply(reply, context.getContext());
    } else if (reply instanceof WriteDocumentReply) {
        if (context.shouldTrace(9)) {
            context.trace(9, "Modification timestamp: " + ((WriteDocumentReply) reply).getHighestModificationTimestamp());
        }
    }
    context.setReply(reply);
}
Also used : Error(com.yahoo.messagebus.Error)

Example 45 with Error

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

the class MessageBusVisitorSessionTestCase method testVisitorTimeoutsNotConsideredFatal.

@Test
public void testVisitorTimeoutsNotConsideredFatal() {
    VisitorParameters visitorParameters = createVisitorParameters("id.user==1234");
    MockComponents mc = createDefaultMock(visitorParameters);
    mc.controlHandler.resetMock();
    mc.visitorSession.start();
    // create visitors
    mc.executor.expectAndProcessTasks(1);
    assertEquals(1, mc.sender.getMessageCount());
    replyErrorToCreateVisitor(mc.sender, new Error(ErrorCode.TIMEOUT, "out of time!"));
    // reply
    mc.executor.expectAndProcessTasks(1);
    // delayed create visitors
    mc.executor.expectAndProcessTasks(1, new long[] { 100 });
    assertEquals("CreateVisitorMessage(buckets=[\n" + "BucketId(0x80000000000004d2)\n" + "BucketId(0x0000000000000000)\n" + "]\n" + "selection='id.user==1234'\n)", replyToCreateVisitor(mc.sender, ProgressToken.FINISHED_BUCKET));
    // reply
    mc.executor.expectAndProcessTasks(1);
}
Also used : Error(com.yahoo.messagebus.Error) Test(org.junit.Test)

Aggregations

Error (com.yahoo.messagebus.Error)51 Test (org.junit.Test)22 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)10 EmptyReply (com.yahoo.messagebus.EmptyReply)9 Reply (com.yahoo.messagebus.Reply)9 Receptor (com.yahoo.messagebus.test.Receptor)9 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 ParseException (com.yahoo.document.select.parser.ParseException)4 CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)4 BucketId (com.yahoo.document.BucketId)3 Message (com.yahoo.messagebus.Message)3 Version (com.yahoo.component.Version)2 DataValue (com.yahoo.jrt.DataValue)2 Protocol (com.yahoo.messagebus.Protocol)2 Hop (com.yahoo.messagebus.routing.Hop)2 Slime (com.yahoo.slime.Slime)2 Utf8Array (com.yahoo.text.Utf8Array)2 Utf8String (com.yahoo.text.Utf8String)2 IOException (java.io.IOException)2