Search in sources :

Example 1 with FastByteArrayOutputStream

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

the class Gossiper method makeGossipDigestAckMessage.

Message makeGossipDigestAckMessage(GossipDigestAckMessage gDigestAckMessage, int version) throws IOException {
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    GossipDigestAckMessage.serializer().serialize(gDigestAckMessage, dos, version);
    return new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.GOSSIP_DIGEST_ACK, bos.toByteArray(), version);
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) Message(org.apache.cassandra.net.Message) DataOutputStream(java.io.DataOutputStream)

Example 2 with FastByteArrayOutputStream

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

the class Gossiper method makeGossipDigestSynMessage.

Message makeGossipDigestSynMessage(List<GossipDigest> gDigests, int version) throws IOException {
    GossipDigestSynMessage gDigestMessage = new GossipDigestSynMessage(DatabaseDescriptor.getClusterName(), gDigests);
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    GossipDigestSynMessage.serializer().serialize(gDigestMessage, dos, version);
    return new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.GOSSIP_DIGEST_SYN, bos.toByteArray(), version);
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) Message(org.apache.cassandra.net.Message) DataOutputStream(java.io.DataOutputStream)

Example 3 with FastByteArrayOutputStream

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

the class MigrationManager method makeMigrationMessage.

// other half of transformation is in DefinitionsUpdateResponseVerbHandler.
private static Message makeMigrationMessage(Collection<IColumn> migrations, int version) throws IOException {
    FastByteArrayOutputStream bout = new FastByteArrayOutputStream();
    DataOutputStream dout = new DataOutputStream(bout);
    dout.writeInt(migrations.size());
    // problem during upgrades.
    for (IColumn col : migrations) {
        assert col instanceof Column;
        ByteBufferUtil.writeWithLength(col.name(), dout);
        ByteBufferUtil.writeWithLength(col.value(), dout);
    }
    dout.close();
    byte[] body = bout.toByteArray();
    return new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.DEFINITIONS_UPDATE, body, version);
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) Message(org.apache.cassandra.net.Message) IColumn(org.apache.cassandra.db.IColumn) Column(org.apache.cassandra.db.Column) IColumn(org.apache.cassandra.db.IColumn)

Example 4 with FastByteArrayOutputStream

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

the class StorageProxy method sendMessages.

/**
     * for each datacenter, send a message to one node to relay the write to other replicas
     */
public static void sendMessages(String localDataCenter, Map<String, Multimap<Message, InetAddress>> dcMessages, IWriteResponseHandler handler) throws IOException {
    for (Map.Entry<String, Multimap<Message, InetAddress>> entry : dcMessages.entrySet()) {
        String dataCenter = entry.getKey();
        // send the messages corresponding to this datacenter
        for (Map.Entry<Message, Collection<InetAddress>> messages : entry.getValue().asMap().entrySet()) {
            Message message = messages.getKey();
            // a single message object is used for unhinted writes, so clean out any forwards
            // from previous loop iterations
            message = message.withHeaderRemoved(RowMutation.FORWARD_HEADER);
            Iterator<InetAddress> iter = messages.getValue().iterator();
            InetAddress target = iter.next();
            // direct writes to local DC or old Cassadra versions
            if (dataCenter.equals(localDataCenter) || Gossiper.instance.getVersion(target) < MessagingService.VERSION_11) {
                // yes, the loop and non-loop code here are the same; this is clunky but we want to avoid
                // creating a second iterator since we already have a perfectly good one
                MessagingService.instance().sendRR(message, target, handler);
                while (iter.hasNext()) {
                    target = iter.next();
                    MessagingService.instance().sendRR(message, target, handler);
                }
                continue;
            }
            // Add all the other destinations of the same message as a FORWARD_HEADER entry
            FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(bos);
            dos.writeInt(messages.getValue().size() - 1);
            while (iter.hasNext()) {
                InetAddress destination = iter.next();
                CompactEndpointSerializationHelper.serialize(destination, dos);
                String id = MessagingService.instance().addCallback(handler, message, destination);
                dos.writeUTF(id);
                if (logger.isDebugEnabled())
                    logger.debug("Adding FWD message to: " + destination + " with ID " + id);
            }
            message = message.withHeaderAdded(RowMutation.FORWARD_HEADER, bos.toByteArray());
            // send the combined message + forward headers
            String id = MessagingService.instance().sendRR(message, target, handler);
            if (logger.isDebugEnabled())
                logger.debug("Sending message to: " + target + " with ID " + id);
        }
    }
}
Also used : Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap) FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) DataOutputStream(java.io.DataOutputStream) InetAddress(java.net.InetAddress)

Example 5 with FastByteArrayOutputStream

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

the class StreamRequestMessage method getMessage.

public Message getMessage(Integer version) {
    FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    try {
        StreamRequestMessage.serializer().serialize(this, dos, version);
    } catch (IOException e) {
        throw new IOError(e);
    }
    return new Message(FBUtilities.getBroadcastAddress(), StorageService.Verb.STREAM_REQUEST, bos.toByteArray(), version);
}
Also used : FastByteArrayOutputStream(org.apache.cassandra.io.util.FastByteArrayOutputStream) Message(org.apache.cassandra.net.Message)

Aggregations

FastByteArrayOutputStream (org.apache.cassandra.io.util.FastByteArrayOutputStream)10 Message (org.apache.cassandra.net.Message)7 DataOutputStream (java.io.DataOutputStream)4 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InetAddress (java.net.InetAddress)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 DataFormatException (java.util.zip.DataFormatException)1 Inflater (java.util.zip.Inflater)1 Column (org.apache.cassandra.db.Column)1 IColumn (org.apache.cassandra.db.IColumn)1