Search in sources :

Example 1 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class ReadVerbHandler method doVerb.

public void doVerb(Message message, String id) {
    if (StorageService.instance.isBootstrapMode()) {
        throw new RuntimeException("Cannot service reads while bootstrapping!");
    }
    try {
        FastByteArrayInputStream in = new FastByteArrayInputStream(message.getMessageBody());
        ReadCommand command = ReadCommand.serializer().deserialize(new DataInputStream(in), message.getVersion());
        Table table = Table.open(command.table);
        Row row = command.getRow(table);
        ReadResponse response = getResponse(command, row);
        byte[] bytes = FBUtilities.serialize(response, ReadResponse.serializer(), message.getVersion());
        Message reply = message.getReply(FBUtilities.getBroadcastAddress(), bytes, message.getVersion());
        if (logger_.isDebugEnabled())
            logger_.debug(String.format("Read key %s; sending response to %s@%s", ByteBufferUtil.bytesToHex(command.key), id, message.getFrom()));
        MessagingService.instance().sendReply(reply, id, message.getFrom());
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) Message(org.apache.cassandra.net.Message) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 2 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class AppliedOperations method sendDepCheckReply.

private static void sendDepCheckReply(Message depCheckMessage, String id) {
    logger.debug("Send dependency check reply. (dcm.lt={})", depCheckMessage.getLamportTimestamp());
    byte[] empty = new byte[0];
    Message reply = depCheckMessage.getReply(FBUtilities.getBroadcastAddress(), empty, depCheckMessage.getVersion());
    MessagingService.instance().sendReply(reply, id, depCheckMessage.getFrom());
}
Also used : Message(org.apache.cassandra.net.Message)

Example 3 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class CounterMutationVerbHandler method applyAndRespond.

protected void applyAndRespond(Message message, String id, CounterMutation cm) {
    try {
        String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress());
        StorageProxy.applyCounterMutationOnLeader(cm, localDataCenter).get();
        WriteResponse response = new WriteResponse(cm.getTable(), cm.key(), true);
        Message responseMessage = WriteResponse.makeWriteResponseMessage(message, response);
        MessagingService.instance().sendReply(responseMessage, id, message.getFrom());
    } catch (UnavailableException e) {
    // We check for UnavailableException in the coordinator not. It is
    // hence reasonable to let the coordinator timeout in the very
    // unlikely case we arrive here
    } catch (TimeoutException e) {
    // The coordinator node will have timeout itself so we let that goes
    } catch (IOException e) {
        logger.error("Error in counter mutation", e);
    }
}
Also used : Message(org.apache.cassandra.net.Message) UnavailableException(org.apache.cassandra.thrift.UnavailableException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class TruncateVerbHandler method respondError.

private static void respondError(Truncation t, Message truncateRequestMessage) throws IOException {
    TruncateResponse response = new TruncateResponse(t.keyspace, t.columnFamily, false);
    Message responseMessage = TruncateResponse.makeTruncateResponseMessage(truncateRequestMessage, response);
    MessagingService.instance().sendOneWay(responseMessage, truncateRequestMessage.getFrom());
}
Also used : Message(org.apache.cassandra.net.Message)

Example 5 with Message

use of org.apache.cassandra.net.Message in project eiger by wlloyd.

the class TruncateVerbHandler method doVerb.

public void doVerb(Message message, String id) {
    byte[] bytes = message.getMessageBody();
    FastByteArrayInputStream buffer = new FastByteArrayInputStream(bytes);
    try {
        Truncation t = Truncation.serializer().deserialize(new DataInputStream(buffer), message.getVersion());
        logger.debug("Applying {}", t);
        try {
            ColumnFamilyStore cfs = Table.open(t.keyspace).getColumnFamilyStore(t.columnFamily);
            cfs.truncate().get();
        } catch (Exception e) {
            logger.error("Error in truncation", e);
            respondError(t, message);
        }
        logger.debug("Truncate operation succeeded at this host");
        TruncateResponse response = new TruncateResponse(t.keyspace, t.columnFamily, true);
        Message responseMessage = TruncateResponse.makeTruncateResponseMessage(message, response);
        logger.debug("{} applied.  Sending response to {}@{} ", new Object[] { t, id, message.getFrom() });
        MessagingService.instance().sendReply(responseMessage, id, message.getFrom());
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) Message(org.apache.cassandra.net.Message) IOError(java.io.IOError) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException)

Aggregations

Message (org.apache.cassandra.net.Message)40 IOException (java.io.IOException)9 DataInputStream (java.io.DataInputStream)7 FastByteArrayOutputStream (org.apache.cassandra.io.util.FastByteArrayOutputStream)7 InetAddress (java.net.InetAddress)6 FastByteArrayInputStream (org.apache.cassandra.io.util.FastByteArrayInputStream)6 DataOutputStream (java.io.DataOutputStream)4 IOError (java.io.IOError)3 RangeSliceReply (org.apache.cassandra.db.RangeSliceReply)3 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)3 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TimeoutException (java.util.concurrent.TimeoutException)2 Row (org.apache.cassandra.db.Row)2 IPartitioner (org.apache.cassandra.dht.IPartitioner)2 IAsyncResult (org.apache.cassandra.net.IAsyncResult)2 Test (org.junit.Test)2 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1