Search in sources :

Example 1 with FastByteArrayInputStream

use of org.apache.cassandra.io.util.FastByteArrayInputStream in project cassandra by apache.

the class MutationVerbHandler method forwardToLocalNodes.

private static void forwardToLocalNodes(Mutation mutation, MessagingService.Verb verb, byte[] forwardBytes, InetAddress from) throws IOException {
    try (DataInputStream in = new DataInputStream(new FastByteArrayInputStream(forwardBytes))) {
        int size = in.readInt();
        // tell the recipients who to send their ack to
        MessageOut<Mutation> message = new MessageOut<>(verb, mutation, Mutation.serializer).withParameter(Mutation.FORWARD_FROM, from.getAddress());
        // Send a message to each of the addresses on our Forward List
        for (int i = 0; i < size; i++) {
            InetAddress address = CompactEndpointSerializationHelper.deserialize(in);
            int id = in.readInt();
            Tracing.trace("Enqueuing forwarded write to {}", address);
            MessagingService.instance().sendOneWay(message, id, address);
        }
    }
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) DataInputStream(java.io.DataInputStream) InetAddress(java.net.InetAddress)

Example 2 with FastByteArrayInputStream

use of org.apache.cassandra.io.util.FastByteArrayInputStream in project eiger by wlloyd.

the class IndexScanCommand method read.

public static IndexScanCommand read(Message message) throws IOException {
    byte[] bytes = message.getMessageBody();
    FastByteArrayInputStream bis = new FastByteArrayInputStream(bytes);
    return serializer.deserialize(new DataInputStream(bis), message.getVersion());
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream)

Example 3 with FastByteArrayInputStream

use of org.apache.cassandra.io.util.FastByteArrayInputStream 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 4 with FastByteArrayInputStream

use of org.apache.cassandra.io.util.FastByteArrayInputStream in project eiger by wlloyd.

the class CounterMutationVerbHandler method doVerb.

@Override
public void doVerb(Message message, String id) {
    byte[] bytes = message.getMessageBody();
    FastByteArrayInputStream buffer = new FastByteArrayInputStream(bytes);
    try {
        DataInputStream is = new DataInputStream(buffer);
        CounterMutation cm = CounterMutation.serializer().deserialize(is, message.getVersion());
        if (logger.isDebugEnabled())
            logger.debug("Applying forwarded " + cm);
        //Check Dependencies
        assert VersionUtil.extractDatacenter(cm.extractTimestamp()) != ShortNodeId.getLocalDC() : "Do not expect replication mutations from the localDC (yet)";
        if (cm.getDependencies().size() > 0) {
            StorageProxy.checkDependencies(cm.getTable(), cm.key(), cm.extractTimestamp(), cm.getDependencies(), new CounterMutationCompletion(message, id, cm));
        } else {
            applyAndRespond(message, id, cm);
        }
    } catch (IOException e) {
        logger.error("Error in counter mutation", e);
    }
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 5 with FastByteArrayInputStream

use of org.apache.cassandra.io.util.FastByteArrayInputStream in project eiger by wlloyd.

the class RowMutation method fromBytes.

public static RowMutation fromBytes(byte[] raw, int version) throws IOException {
    RowMutation rm = serializer_.deserialize(new DataInputStream(new FastByteArrayInputStream(raw)), version);
    boolean hasCounters = false;
    for (Map.Entry<Integer, ColumnFamily> entry : rm.modifications_.entrySet()) {
        if (entry.getValue().metadata().getDefaultValidator().isCommutative()) {
            hasCounters = true;
            break;
        }
    }
    // We need to deserialize at least once for counters to cleanup the delta
    if (!hasCounters && version == MessagingService.version_)
        rm.preserializedBuffers.put(version, raw);
    return rm;
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) DataInputStream(java.io.DataInputStream)

Aggregations

FastByteArrayInputStream (org.apache.cassandra.io.util.FastByteArrayInputStream)19 DataInputStream (java.io.DataInputStream)14 IOException (java.io.IOException)10 Message (org.apache.cassandra.net.Message)6 IOError (java.io.IOError)5 InetAddress (java.net.InetAddress)5 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Future (java.util.concurrent.Future)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CRC32 (java.util.zip.CRC32)1 Checksum (java.util.zip.Checksum)1 Column (org.apache.cassandra.db.Column)1 IColumn (org.apache.cassandra.db.IColumn)1 ReadResponse (org.apache.cassandra.db.ReadResponse)1 WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)1