Search in sources :

Example 1 with ForwardingInfo

use of org.apache.cassandra.net.ForwardingInfo in project cassandra by apache.

the class StorageProxy method sendMessagesToNonlocalDC.

/*
     * Send the message to the first replica of targets, and have it forward the message to others in its DC
     */
private static void sendMessagesToNonlocalDC(Message<? extends IMutation> message, EndpointsForToken targets, AbstractWriteResponseHandler<IMutation> handler) {
    final Replica target;
    if (targets.size() > 1) {
        target = targets.get(ThreadLocalRandom.current().nextInt(0, targets.size()));
        EndpointsForToken forwardToReplicas = targets.filter(r -> r != target, targets.size());
        for (Replica replica : forwardToReplicas) {
            MessagingService.instance().callbacks.addWithExpiration(handler, message, replica, handler.replicaPlan.consistencyLevel(), true);
            logger.trace("Adding FWD message to {}@{}", message.id(), replica);
        }
        // starting with 4.0, use the same message id for all replicas
        long[] messageIds = new long[forwardToReplicas.size()];
        Arrays.fill(messageIds, message.id());
        message = message.withForwardTo(new ForwardingInfo(forwardToReplicas.endpointList(), messageIds));
    } else {
        target = targets.get(0);
    }
    MessagingService.instance().sendWriteWithCallback(message, target, handler, true);
    logger.trace("Sending message to {}@{}", message.id(), target);
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) Replica(org.apache.cassandra.locator.Replica) ForwardingInfo(org.apache.cassandra.net.ForwardingInfo)

Aggregations

EndpointsForToken (org.apache.cassandra.locator.EndpointsForToken)1 Replica (org.apache.cassandra.locator.Replica)1 ForwardingInfo (org.apache.cassandra.net.ForwardingInfo)1