private static boolean isErrorOfType(Reply reply, int errorCode) { return reply.getError(0).getCode() == errorCode; }
@Override public void handleReply(Reply reply) { Object o = reply.getContext(); if (!(o instanceof ReplyContext)) { return; } ReplyContext context = (ReplyContext) o; final double latencyInSeconds = (System.currentTimeMillis() - context.creationTime) / 1000.0d; metric.set(MetricNames.LATENCY, latencyInSeconds, null); if (reply.hasErrors()) { Set<Integer> errorCodes = reply.getErrorCodes(); metricsHelper.reportFailure(DocumentOperationType.fromMessage(reply.getMessage()), DocumentOperationStatus.fromMessageBusErrorCodes(errorCodes)); metric.add(MetricNames.FAILED, 1, null); enqueue(context, reply.getError(0).getMessage(), ErrorCode.ERROR, reply.getError(0).getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED, reply.getTrace()); } else { metricsHelper.reportSuccessful(DocumentOperationType.fromMessage(reply.getMessage()), latencyInSeconds); metric.add(MetricNames.SUCCEEDED, 1, null); enqueue(context, "Document processed.", ErrorCode.OK, false, reply.getTrace()); } }
/** * Return whether a (transient) error shall be exempt from visitor * error reporting. This to prevent spamming handlers and output with * errors for things that are happening naturally in the system. * @return true if the error should be reported */ private boolean shouldReportError(Reply reply) { Error error = reply.getError(0); switch (error.getCode()) { case DocumentProtocol.ERROR_BUCKET_NOT_FOUND: case DocumentProtocol.ERROR_BUCKET_DELETED: return false; } return true; }
/** * Returns a concatenated error string from the errors contained in a reply. * * @param reply The reply whose errors to concatenate. * @return The error string. */ static String getErrorMessage(Reply reply) { if (!reply.hasErrors()) { return null; } StringBuilder errors = new StringBuilder(); for (int i = 0; i < reply.getNumErrors(); ++i) { errors.append(reply.getError(i)).append(" "); } return errors.toString(); }
public static int fromMbusReply(final Reply reply) { int statusCode = Response.Status.OK; for (int i = 0, len = reply.getNumErrors(); i < len; ++i) { statusCode = Math.max(statusCode, fromMbusError(reply.getError(i))); } return statusCode; }
private boolean isFatalError(Reply reply) { Error error = reply.getError(0); switch (error.getCode()) { case ErrorCode.TIMEOUT: case DocumentProtocol.ERROR_BUCKET_NOT_FOUND: case DocumentProtocol.ERROR_WRONG_DISTRIBUTION: return false; } return error.isFatal(); }
public Reply awaitErrors(Integer... errCodes) { Reply reply = awaitReply(); if (reply == null) { return null; } List<Integer> lst = new LinkedList<>(Arrays.asList(errCodes)); for (int i = 0, len = reply.getNumErrors(); i < len; ++i) { Error err = reply.getError(i); System.out.println(err); int idx = lst.indexOf(err.getCode()); if (idx < 0) { return null; } lst.remove(idx); } if (!lst.isEmpty()) { return null; } return reply; }
private boolean handleReplyWithOnlyIgnoredErrors(Reply r) { if (DocumentProtocol.hasOnlyErrorsOfType(r, DocumentProtocol.ERROR_MESSAGE_IGNORED)) { if (ignore == null) { ignore = new EmptyReply(); } ignore.addError(r.getError(0)); return true; } return false; }
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;
/** * Returns true if the given reply has at least one error, and all errors are of the given type. * * @param reply The reply to check for error. * @param errCode The error code to check for. * @return Whether or not the reply has only the given error code. */ public static boolean hasOnlyErrorsOfType(Reply reply, int errCode) { if (!reply.hasErrors()) { return false; } for (int i = 0; i < reply.getNumErrors(); ++i) { if (reply.getError(i).getCode() != errCode) { return false; } } return true; }
/** * Returns whether or not the given reply should be retried. * * @param reply The reply to check. * @return True if retry is required. */ public boolean shouldRetry(Reply reply) { int numErrors = reply.getNumErrors(); if (numErrors == 0) { return false; } for (int i = 0; i < numErrors; ++i) { if (!retryPolicy.canRetry(reply.getError(i).getCode())) { return false; } } return true; }
@Override public void handleReply(Reply reply) { setReply(reply); if (routeMetrics != null) { for (int i = 0; i < reply.getNumErrors(); i++) { routeMetrics.addError(reply.getError(i)); } } notifyParent(); } }
private void mergeAllReplyErrors(Reply r) { if (handleReplyWithOnlyIgnoredErrors(r)) { return; } if (error == null) { error = new EmptyReply(); r.swapState(error); return; } for (int j = 0; j < r.getNumErrors(); ++j) { error.addError(r.getError(j)); } }
public void merge(RoutingContext context) { List<String> lst = new ArrayList<String>(); Reply ret = new EmptyReply(); for (RoutingNodeIterator it = context.getChildIterator(); it.isValid(); it.next()) { lst.add(it.getRoute().toString()); Reply reply = it.getReplyRef(); for (int i = 0; i < reply.getNumErrors(); ++i) { ret.addError(reply.getError(i)); } } context.setReply(ret); context.trace(1, "Merged " + lst + "."); }
public void merge(RoutingContext context) { RoutingNodeIterator it = context.getChildIterator(); Reply reply = it.removeReply(); LoadBalancer.Node target = (LoadBalancer.Node)context.getContext(); boolean busy = false; for (int i = 0; i < reply.getNumErrors(); i++) { if (reply.getError(i).getCode() == ErrorCode.SESSION_BUSY) { busy = true; } } loadBalancer.received(target, busy); context.setReply(reply); }
private void handleErrorReply(Reply reply) { CreateVisitorMessage msg = (CreateVisitorMessage)reply.getMessage(); // Must reset bucket progress back to what it was before sending. BucketId bucket = msg.getBuckets().get(0); BucketId subProgress = msg.getBuckets().get(1); progress.getIterator().update(bucket, subProgress); String message = getErrorMessage(reply.getError(0)); log.log(LogLevel.DEBUG, sessionName + ": received error reply for bucket " + bucket + " with message '" + message + "'"); if (isFatalError(reply)) { if (params.skipBucketsOnFatalErrors()) { markBucketProgressAsFailed(bucket, subProgress, message); } else { reportVisitorError(message); transitionTo(new StateDescription(State.FAILED, message)); return; // no additional visitors will be scheduled post-failure } } if (isErrorOfType(reply, DocumentProtocol.ERROR_WRONG_DISTRIBUTION)) { handleWrongDistributionReply((WrongDistributionReply)reply); } else { if (shouldReportError(reply)) { reportVisitorError(message); } // Wait 100ms before new visitor task is executed. Will prevent // visitors from being scheduled from caller. scheduleSendCreateVisitorsIfApplicable(100, TimeUnit.MILLISECONDS); } }
RouteMetricSet metrics = mbus.getMetrics().getRouteMetrics(msg.getRoute()); for (int i = 0; i < reply.getNumErrors(); i++) { metrics.addFailure(reply.getError(i));
@Override public void run() { Reply reply = decode(envelope.reply.getProtocol(), payload, Reply.class); reply.setRetryDelay(envelope.reply.getRetryDelay()); reply.getTrace().getRoot().addChild(TraceNode.decode(envelope.reply.getTrace().getRoot().encode())); for (int i = 0, len = envelope.reply.getNumErrors(); i < len; ++i) { Error error = envelope.reply.getError(i); reply.addError(new Error(error.getCode(), error.getMessage(), error.getService() != null ? error.getService() : envelope.sender.hostId)); } owner.deliverReply(reply, envelope.parent.recipient); } });
@Override protected void createResponse(Values ret, Reply reply, Version version, byte [] payload) { int[] eCodes = new int[reply.getNumErrors()]; String[] eMessages = new String[reply.getNumErrors()]; String[] eServices = new String[reply.getNumErrors()]; for (int i = 0; i < reply.getNumErrors(); ++i) { Error error = reply.getError(i); eCodes[i] = error.getCode(); eMessages[i] = error.getMessage(); eServices[i] = error.getService() != null ? error.getService() : ""; } ret.add(new StringValue(version.toString())); ret.add(new DoubleValue(reply.getRetryDelay())); ret.add(new Int32Array(eCodes)); ret.add(new StringArray(eMessages)); ret.add(new StringArray(eServices)); ret.add(new StringValue(reply.getProtocol())); ret.add(new DataValue(payload)); ret.add(new StringValue(reply.getTrace().getRoot() != null ? reply.getTrace().getRoot().encode() : "")); }
for (int i = 0; i < reply.getNumErrors(); i++) { Cursor e = array.addObject(); Error mbusE = reply.getError(i); e.setLong(CODE_F, mbusE.getCode()); e.setString(MSG_F, mbusE.getMessage());