Search in sources :

Example 1 with LocalReadRunnable

use of org.apache.cassandra.service.StorageProxy.LocalReadRunnable in project cassandra by apache.

the class AbstractReadExecutor method makeRequests.

private void makeRequests(ReadCommand readCommand, Iterable<InetAddress> endpoints) {
    boolean hasLocalEndpoint = false;
    for (InetAddress endpoint : endpoints) {
        if (StorageProxy.canDoLocalRequest(endpoint)) {
            hasLocalEndpoint = true;
            continue;
        }
        if (traceState != null)
            traceState.trace("reading {} from {}", readCommand.isDigestQuery() ? "digest" : "data", endpoint);
        logger.trace("reading {} from {}", readCommand.isDigestQuery() ? "digest" : "data", endpoint);
        MessageOut<ReadCommand> message = readCommand.createMessage();
        MessagingService.instance().sendRRWithFailure(message, endpoint, handler);
    }
    // We delay the local (potentially blocking) read till the end to avoid stalling remote requests.
    if (hasLocalEndpoint) {
        logger.trace("reading {} locally", readCommand.isDigestQuery() ? "digest" : "data");
        StageManager.getStage(Stage.READ).maybeExecuteImmediately(new LocalReadRunnable(command, handler));
    }
}
Also used : ReadCommand(org.apache.cassandra.db.ReadCommand) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) LocalReadRunnable(org.apache.cassandra.service.StorageProxy.LocalReadRunnable) InetAddress(java.net.InetAddress)

Example 2 with LocalReadRunnable

use of org.apache.cassandra.service.StorageProxy.LocalReadRunnable in project cassandra by apache.

the class AbstractReadExecutor method makeRequests.

private void makeRequests(ReadCommand readCommand, Iterable<Replica> replicas) {
    boolean hasLocalEndpoint = false;
    Message<ReadCommand> message = null;
    for (Replica replica : replicas) {
        assert replica.isFull() || readCommand.acceptsTransient();
        InetAddressAndPort endpoint = replica.endpoint();
        if (replica.isSelf()) {
            hasLocalEndpoint = true;
            continue;
        }
        if (traceState != null)
            traceState.trace("reading {} from {}", readCommand.isDigestQuery() ? "digest" : "data", endpoint);
        if (null == message)
            message = readCommand.createMessage(false);
        MessagingService.instance().sendWithCallback(message, endpoint, handler);
    }
    // We delay the local (potentially blocking) read till the end to avoid stalling remote requests.
    if (hasLocalEndpoint) {
        logger.trace("reading {} locally", readCommand.isDigestQuery() ? "digest" : "data");
        Stage.READ.maybeExecuteImmediately(new LocalReadRunnable(readCommand, handler));
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) ReadCommand(org.apache.cassandra.db.ReadCommand) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) LocalReadRunnable(org.apache.cassandra.service.StorageProxy.LocalReadRunnable) Replica(org.apache.cassandra.locator.Replica)

Aggregations

ReadCommand (org.apache.cassandra.db.ReadCommand)2 SinglePartitionReadCommand (org.apache.cassandra.db.SinglePartitionReadCommand)2 LocalReadRunnable (org.apache.cassandra.service.StorageProxy.LocalReadRunnable)2 InetAddress (java.net.InetAddress)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 Replica (org.apache.cassandra.locator.Replica)1