/** * Indicates if tracing is enabled at this level. * @param level the level * @return true if tracing is enabled at this level */ public boolean shouldTrace(int level) { return node.getTrace().shouldTrace(level); }
if (!shouldTrace(level)) { return false;
/** * This method invokes the {@link #resolve(int)} method of all the child nodes of this. If any of these exceed the * depth limit, this method returns false. * * @param childDepth The depth of the children. * @return False if depth limit was exceeded. */ private boolean resolveChildren(int childDepth) { int numActiveChildren = 0; boolean ret = true; for (RoutingNode child : children) { if (child.trace.shouldTrace(TraceLevel.SPLIT_MERGE)) { child.trace.trace(TraceLevel.SPLIT_MERGE, "Resolving '" + child.route + "'."); } child.isActive = (child.reply == null); if (child.isActive) { ++numActiveChildren; if (!child.resolve(childDepth)) { ret = false; break; } } else { if (child.trace.shouldTrace(TraceLevel.SPLIT_MERGE)) { child.trace.trace(TraceLevel.SPLIT_MERGE, "Already completed."); } } } pending.set(numActiveChildren); return ret; }
/** * Filter a message against the current sequencing state. If this method returns true, the message has been cleared * for sending and its sequencing information has been added to the state. If this method returns false, it has been * queued for later sending due to sequencing restrictions. This method also sets the sequence id as message * context. * * @param msg The message to filter. * @return True if the message was consumed. */ private boolean filter(Message msg) { long seqId = msg.getSequenceId(); msg.setContext(seqId); synchronized (this) { if (seqMap.containsKey(seqId)) { Queue<Message> queue = seqMap.get(seqId); if (queue == null) { queue = new LinkedList<Message>(); seqMap.put(seqId, queue); } if (msg.getTrace().shouldTrace(TraceLevel.COMPONENT)) { msg.getTrace().trace(TraceLevel.COMPONENT, "Sequencer queued message with sequence id '" + seqId + "'."); } queue.add(msg); return false; } seqMap.put(seqId, null); } return true; }
public void handleErrorReply(Reply reply, Object untypedContext) { MessageContext messageContext = (MessageContext) untypedContext; if (messageContext.calculatedDistributor != null) { persistentFailureChecker.addFailure(messageContext.calculatedDistributor); if (reply.getTrace().shouldTrace(1)) { reply.getTrace().trace(1, "Failed with " + messageContext.toString()); } } } }
if (reply.getTrace().shouldTrace(TraceLevel.COMPONENT)) { reply.getTrace().trace(TraceLevel.COMPONENT, "Sequencer received reply with sequence id '" + seqId + "'.");
@Override public void handleReply(Reply reply) { if (destroyed.get()) { reply.discard(); return; } boolean done; synchronized (lock) { --pendingCount; if (throttlePolicy != null) { throttlePolicy.processReply(reply); } done = (closed && pendingCount == 0); sendBlockedMessages(); } if (reply.getTrace().shouldTrace(TraceLevel.COMPONENT)) { reply.getTrace().trace(TraceLevel.COMPONENT, "Source session received reply. " + pendingCount + " message(s) now pending."); } ReplyHandler handler = reply.popHandler(); handler.handleReply(reply); if (done) { this.done.countDown(); } }
/** * Internal method for forwarding a sequenced message to the underlying sender. * * @param msg The message to forward. */ private void sequencedSend(Message msg) { if (msg.getTrace().shouldTrace(TraceLevel.COMPONENT)) { msg.getTrace().trace(TraceLevel.COMPONENT, "Sequencer sending message with sequence id '" + msg.getContext() + "'."); } msg.pushHandler(this); sender.handleMessage(msg); }
@Override public void handleMessage(Message msg) { if (!running.get()) { dispatchErrorReply(msg, ErrorCode.SESSION_BUSY, "Session temporarily closed."); return; } if (msg.getTrace().shouldTrace(6)) { msg.getTrace().trace(6, "Message received by MbusServer."); } Request request = null; ContentChannel content = null; try { request = new MbusRequest(container, uri, msg); content = request.connect(new ServerResponseHandler(msg)); } catch (RuntimeException e) { dispatchErrorReply(msg, ErrorCode.APP_FATAL_ERROR, e.toString()); } finally { if (request != null) { request.release(); } } if (content != null) { content.close(IgnoredCompletionHandler.INSTANCE); } }
private void traceReplyFromSpecificDistributor(WrongDistributionReply reply, MessageContext context, ClusterState newState) { if (context.usedState == null) { String msg = "Used state must be set as distributor is calculated. Bug."; reply.getTrace().trace(1, msg); log.log(LogLevel.ERROR, msg); } else if (newState.getVersion() == context.usedState.getVersion()) { String msg = "Message sent to distributor " + context.calculatedDistributor + " retrieved cluster state version " + newState.getVersion() + " which was the state we used to calculate distributor as target last time."; reply.getTrace().trace(1, msg); // Client load can be rejected towards distributors even with a matching cluster state version. // This usually happens during a node fail-over transition, where the target distributor will // reject an operation bound to a particular bucket if it does not own the bucket in _both_ // the current and the next (transition target) state. Since it can happen during normal operation // and will happen per client operation, we keep this as debug level to prevent spamming the logs. log.log(LogLevel.DEBUG, msg); } else if (newState.getVersion() > context.usedState.getVersion()) { if (reply.getTrace().shouldTrace(1)) { reply.getTrace().trace(1, "Message sent to distributor " + context.calculatedDistributor + " updated cluster state from version " + context.usedState.getVersion() + " to " + newState.getVersion()); } } else { if (reply.getTrace().shouldTrace(1)) { reply.getTrace().trace(1, "Message sent to distributor " + context.calculatedDistributor + " returned older cluster state version " + newState.getVersion()); } } }
/** * This method checks to see whether the string representation of the current hop is actually the name of another. * If a hop is found, the first hop of the current route is replaced by this. * * @return True if a hop was found and added. */ private boolean lookupHop() { RoutingTable table = mbus.getRoutingTable(msg.getProtocol()); if (table != null) { String name = route.getHop(0).getServiceName(); if (table.hasHop(name)) { HopBlueprint hop = table.getHop(name); configureFromBlueprint(hop); if (trace.shouldTrace(TraceLevel.SPLIT_MERGE)) { trace.trace(TraceLevel.SPLIT_MERGE, "Recognized '" + name + "' as " + hop + "."); } return true; } } return false; }
if (trace.shouldTrace(TraceLevel.SPLIT_MERGE)) { trace.trace(TraceLevel.SPLIT_MERGE, "Route '" + dir.getName() + "' retrieved by directive; new route is '" + route + "'."); if (table.hasRoute(name)) { insertRoute(table.getRoute(name)); if (trace.shouldTrace(TraceLevel.SPLIT_MERGE)) { trace.trace(TraceLevel.SPLIT_MERGE, "Recognized '" + name + "' as route '" + route + "'.");
private Result sendInternal(Message message) { synchronized (lock) { if (closed) { return new Result(ErrorCode.SEND_QUEUE_CLOSED, "Source session is closed."); } if (throttlePolicy != null && ! throttlePolicy.canSend(message, pendingCount)) { return new Result(ErrorCode.SEND_QUEUE_FULL, "Too much pending data (" + pendingCount + " messages)."); } message.pushHandler(replyHandler); if (throttlePolicy != null) { throttlePolicy.processMessage(message); } ++pendingCount; } if (message.getTrace().shouldTrace(TraceLevel.COMPONENT)) { message.getTrace().trace(TraceLevel.COMPONENT, "Source session accepted a " + message.getApproxSize() + " byte message. " + pendingCount + " message(s) now pending."); } message.pushHandler(this); sequencer.handleMessage(message); return Result.ACCEPTED; }
@Override public final void send(RoutingNode recipient, Version version, byte[] payload, long timeRemaining) { SendContext ctx = new SendContext(recipient, timeRemaining); RPCServiceAddress address = (RPCServiceAddress)recipient.getServiceAddress(); Message msg = recipient.getMessage(); Route route = new Route(recipient.getRoute()); Hop hop = route.removeHop(0); Request req = encodeRequest(version, route, address,msg, timeRemaining, payload, ctx.trace.getLevel()); if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) { ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Sending message (version " + version + ") from " + clientIdent + " to '" + address.getServiceName() + "' with " + ctx.timeout + " seconds timeout."); } if (hop.getIgnoreResult()) { address.getTarget().getJRTTarget().invokeVoid(req); if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) { ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Not waiting for a reply from '" + address.getServiceName() + "'."); } Reply reply = new EmptyReply(); reply.getTrace().swap(ctx.trace); net.getOwner().deliverReply(reply, recipient); } else { req.setContext(ctx); address.getTarget().getJRTTarget().invokeAsync(req, ctx.timeout, this); } req.discardParameters(); // allow garbage collection of request parameters }
private void traceReplyFromRandomDistributor(WrongDistributionReply reply, ClusterState newState) { if (!reply.getTrace().shouldTrace(1)) { return; } if (cachedClusterState == null) { reply.getTrace().trace(1, "Message sent to * with no previous state, received version " + newState.getVersion()); } else if (newState.getVersion() == cachedClusterState.getVersion()) { reply.getTrace().trace(1, "Message sent to * found that cluster state version " + newState.getVersion() + " was correct."); } else if (newState.getVersion() > cachedClusterState.getVersion()) { reply.getTrace().trace(1, "Message sent to * updated cluster state to version " + newState.getVersion()); } else { reply.getTrace().trace(1, "Message sent to * retrieved older cluster state version " + newState.getVersion()); } }
@Override public ContentChannel handleResponse(Response response) { Reply reply; if (response instanceof MbusResponse) { reply = ((MbusResponse)response).getReply(); } else { reply = new EmptyReply(); reply.swapState(msg); } Error err = StatusCodes.toMbusError(response.getStatus()); if (err != null) { if (err.isFatal()) { if (!reply.hasFatalErrors()) { reply.addError(err); } } else { if (!reply.hasErrors()) { reply.addError(err); } } } if (reply.getTrace().shouldTrace(6)) { reply.getTrace().trace(6, "Sending reply from MbusServer."); } session.sendReply(reply); return null; } }
@Override public final void handleReply(Reply reply) { ReplyContext ctx = (ReplyContext)reply.getContext(); reply.setContext(null); // Add trace information. if (reply.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) { reply.getTrace().trace(TraceLevel.SEND_RECEIVE, "Sending reply (version " + ctx.version + ") from " + serverIdent + "."); } // Encode and return the reply through the RPC request. byte[] payload = new byte[0]; if (reply.getType() != 0) { Protocol protocol = net.getOwner().getProtocol(reply.getProtocol()); if (protocol != null) { payload = protocol.encode(ctx.version, reply); } if (payload == null || payload.length == 0) { reply.addError(new Error(ErrorCode.ENCODE_ERROR, "An error occured while encoding the reply.")); } } createResponse(ctx.request.returnValues(), reply, ctx.version, payload); ctx.request.returnRequest(); }
if (trace.shouldTrace(TraceLevel.SPLIT_MERGE)) { trace.trace(TraceLevel.SPLIT_MERGE, "Routing policy '" + dir.getName() + "' merging replies.");
msg.setTimeRemaining(p.timeRemaining); msg.getTrace().setLevel(p.traceLevel); if (msg.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) { msg.getTrace().trace(TraceLevel.SEND_RECEIVE, "Message (type " + msg.getType() + ") received at " + serverIdent + " for session '" + p.session + "'.");
reply = createReply(req.returnValues(), serviceName, ctx.trace); if (ctx.trace.shouldTrace(TraceLevel.SEND_RECEIVE)) { ctx.trace.trace(TraceLevel.SEND_RECEIVE, "Reply (type " + reply.getType() + ") received at " + clientIdent + ".");