Search in sources :

Example 11 with Message

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

the class GossipDigestSynVerbHandler method doVerb.

public void doVerb(Message message, String id) {
    InetAddress from = message.getFrom();
    if (logger_.isTraceEnabled())
        logger_.trace("Received a GossipDigestSynMessage from {}", from);
    if (!Gossiper.instance.isEnabled()) {
        if (logger_.isTraceEnabled())
            logger_.trace("Ignoring GossipDigestSynMessage because gossip is disabled");
        return;
    }
    byte[] bytes = message.getMessageBody();
    DataInputStream dis = new DataInputStream(new FastByteArrayInputStream(bytes));
    try {
        GossipDigestSynMessage gDigestMessage = GossipDigestSynMessage.serializer().deserialize(dis, message.getVersion());
        /* If the message is from a different cluster throw it away. */
        if (!gDigestMessage.clusterId_.equals(DatabaseDescriptor.getClusterName())) {
            logger_.warn("ClusterName mismatch from " + from + " " + gDigestMessage.clusterId_ + "!=" + DatabaseDescriptor.getClusterName());
            return;
        }
        List<GossipDigest> gDigestList = gDigestMessage.getGossipDigests();
        if (logger_.isTraceEnabled()) {
            StringBuilder sb = new StringBuilder();
            for (GossipDigest gDigest : gDigestList) {
                sb.append(gDigest);
                sb.append(" ");
            }
            logger_.trace("Gossip syn digests are : " + sb.toString());
        }
        /* Notify the Failure Detector */
        Gossiper.instance.notifyFailureDetector(gDigestList);
        doSort(gDigestList);
        List<GossipDigest> deltaGossipDigestList = new ArrayList<GossipDigest>();
        Map<InetAddress, EndpointState> deltaEpStateMap = new HashMap<InetAddress, EndpointState>();
        Gossiper.instance.examineGossiper(gDigestList, deltaGossipDigestList, deltaEpStateMap);
        GossipDigestAckMessage gDigestAck = new GossipDigestAckMessage(deltaGossipDigestList, deltaEpStateMap);
        Message gDigestAckMessage = Gossiper.instance.makeGossipDigestAckMessage(gDigestAck, message.getVersion());
        if (logger_.isTraceEnabled())
            logger_.trace("Sending a GossipDigestAckMessage to {}", from);
        MessagingService.instance().sendOneWay(gDigestAckMessage, from);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Message(org.apache.cassandra.net.Message) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) InetAddress(java.net.InetAddress)

Example 12 with Message

use of org.apache.cassandra.net.Message 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 13 with Message

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

the class IndexScanVerbHandler method doVerb.

public void doVerb(Message message, String id) {
    try {
        IndexScanCommand command = IndexScanCommand.read(message);
        ColumnFamilyStore cfs = Table.open(command.keyspace).getColumnFamilyStore(command.column_family);
        List<Row> rows = cfs.search(command.index_clause.expressions, command.range, command.index_clause.count, QueryFilter.getFilter(command.predicate, cfs.getComparator()));
        RangeSliceReply reply = new RangeSliceReply(rows);
        Message response = reply.getReply(message);
        if (logger.isDebugEnabled())
            logger.debug("Sending " + reply + " to " + id + "@" + message.getFrom());
        MessagingService.instance().sendReply(response, id, message.getFrom());
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : Message(org.apache.cassandra.net.Message)

Example 14 with Message

use of org.apache.cassandra.net.Message 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 15 with Message

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

the class RangeSliceResponseResolver method resolve.

// Note: this would deserialize the response a 2nd time if getData was called first.
// (this is not currently an issue since we don't do read repair for range queries.)
public Iterable<Row> resolve() throws IOException {
    ArrayList<RowIterator> iters = new ArrayList<RowIterator>(responses.size());
    int n = 0;
    for (Message response : responses) {
        RangeSliceReply reply = RangeSliceReply.read(response.getMessageBody(), response.getVersion());
        n = Math.max(n, reply.rows.size());
        iters.add(new RowIterator(reply.rows.iterator(), response.getFrom()));
    }
    // for each row, compute the combination of all different versions seen, and repair incomplete versions
    // TODO do we need to call close?
    CloseableIterator<Row> iter = MergeIterator.get(iters, pairComparator, new Reducer());
    List<Row> resolvedRows = new ArrayList<Row>(n);
    while (iter.hasNext()) resolvedRows.add(iter.next());
    return resolvedRows;
}
Also used : Message(org.apache.cassandra.net.Message) RangeSliceReply(org.apache.cassandra.db.RangeSliceReply) Row(org.apache.cassandra.db.Row)

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