Search in sources :

Example 11 with FastByteArrayInputStream

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

the class MigrationManager method makeColumns.

// other half of this transformation is in MigrationManager.
public static Collection<Column> makeColumns(Message msg) throws IOException {
    Collection<Column> cols = new ArrayList<Column>();
    DataInputStream in = new DataInputStream(new FastByteArrayInputStream(msg.getMessageBody()));
    int count = in.readInt();
    for (int i = 0; i < count; i++) {
        byte[] name = new byte[in.readInt()];
        in.readFully(name);
        byte[] value = new byte[in.readInt()];
        in.readFully(value);
        cols.add(new Column(ByteBuffer.wrap(name), ByteBuffer.wrap(value)));
    }
    in.close();
    return cols;
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) Column(org.apache.cassandra.db.Column) IColumn(org.apache.cassandra.db.IColumn)

Example 12 with FastByteArrayInputStream

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

the class StreamReplyVerbHandler method doVerb.

public void doVerb(Message message, String id) {
    byte[] body = message.getMessageBody();
    FastByteArrayInputStream bufIn = new FastByteArrayInputStream(body);
    try {
        StreamReply reply = StreamReply.serializer.deserialize(new DataInputStream(bufIn), message.getVersion());
        logger.debug("Received StreamReply {}", reply);
        StreamOutSession session = StreamOutSession.get(message.getFrom(), reply.sessionId);
        if (session == null) {
            logger.debug("Received stream action " + reply.action + " for an unknown session from " + message.getFrom());
            return;
        }
        switch(reply.action) {
            case FILE_FINISHED:
                logger.info("Successfully sent {} to {}", reply.file, message.getFrom());
                session.validateCurrentFile(reply.file);
                session.startNext();
                break;
            case FILE_RETRY:
                session.validateCurrentFile(reply.file);
                logger.info("Need to re-stream file {} to {}", reply.file, message.getFrom());
                session.retry();
                break;
            case SESSION_FINISHED:
                session.close();
                break;
            default:
                throw new RuntimeException("Cannot handle FileStatus.Action: " + reply.action);
        }
    } catch (IOException ex) {
        throw new IOError(ex);
    }
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) IOError(java.io.IOError) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 13 with FastByteArrayInputStream

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

the class StreamRequestVerbHandler method doVerb.

public void doVerb(Message message, String id) {
    if (logger.isDebugEnabled())
        logger.debug("Received a StreamRequestMessage from {}", message.getFrom());
    byte[] body = message.getMessageBody();
    FastByteArrayInputStream bufIn = new FastByteArrayInputStream(body);
    try {
        StreamRequestMessage srm = StreamRequestMessage.serializer().deserialize(new DataInputStream(bufIn), message.getVersion());
        if (logger.isDebugEnabled())
            logger.debug(srm.toString());
        StreamOutSession session = StreamOutSession.create(srm.table, message.getFrom(), srm.sessionId);
        StreamOut.transferRanges(session, srm.columnFamilies, srm.ranges, srm.type);
    } catch (IOException ex) {
        throw new IOError(ex);
    }
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) IOError(java.io.IOError) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 14 with FastByteArrayInputStream

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

the class RowMutationVerbHandler method forwardToLocalNodes.

/**
     * Older version (< 1.0) will not send this message at all, hence we don't
     * need to check the version of the data.
     */
private void forwardToLocalNodes(Message message, byte[] forwardBytes) throws IOException {
    DataInputStream dis = new DataInputStream(new FastByteArrayInputStream(forwardBytes));
    int size = dis.readInt();
    // remove fwds from message to avoid infinite loop
    Message messageCopy = message.withHeaderRemoved(RowMutation.FORWARD_HEADER);
    for (int i = 0; i < size; i++) {
        // Send a message to each of the addresses on our Forward List
        InetAddress address = CompactEndpointSerializationHelper.deserialize(dis);
        String id = dis.readUTF();
        if (logger_.isDebugEnabled())
            logger_.debug("Forwarding message to " + address + " with= ID: " + id);
        // Let the response go back to the coordinator
        MessagingService.instance().sendOneWay(messageCopy, id, address);
    }
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) Message(org.apache.cassandra.net.Message) DataInputStream(java.io.DataInputStream) InetAddress(java.net.InetAddress)

Example 15 with FastByteArrayInputStream

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

the class RangeSliceCommandSerializer method read.

public static RangeSliceCommand 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)

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