public void handleWrongDistribution(WrongDistributionReply reply, RoutingContext routingContext) { final MessageContext context = (MessageContext) routingContext.getContext(); final Optional<ClusterState> replyState = clusterStateFromReply(reply); if (!replyState.isPresent()) { return; } final ClusterState newState = replyState.get(); resetCachedStateIfClusterStateVersionLikelyRolledBack(newState); markReplyAsImmediateRetryIfNewStateObserved(reply, context, newState); if (context.calculatedDistributor == null) { traceReplyFromRandomDistributor(reply, newState); } else { traceReplyFromSpecificDistributor(reply, context, newState); } updateCachedRoutingStateFromWrongDistribution(context, newState); }
@Override public void doSelect(RoutingContext context) { if (context.shouldTrace(1)) { context.trace(1, "Selecting route"); } BucketId bucketId = bucketIdCalculator.handleBucketIdCalculation(context); if (context.hasReply()) return; String targetSpec = distributorSelectionLogic.getTargetSpec(context, bucketId); if (context.hasReply()) return; if (targetSpec != null) { Route route = new Route(context.getRoute()); route.setHop(0, new Hop().addDirective(new VerbatimDirective(targetSpec))); context.addChild(route); } else { context.setError(ErrorCode.NO_ADDRESS_FOR_SERVICE, "Could not resolve any distributors to send to in cluster " + parameters.clusterName); } }
@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); }
@Override public void destroy() { distributorSelectionLogic.destroy(); }
@Override public void init() { super.init(); this.distributorSelectionLogic = new DistributorSelectionLogic(parameters, this); }