Search in sources :

Example 31 with Message

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

the class MigrationManager method pushMigrations.

private static void pushMigrations(InetAddress endpoint, Collection<IColumn> migrations) {
    try {
        Message msg = makeMigrationMessage(migrations, Gossiper.instance.getVersion(endpoint));
        MessagingService.instance().sendOneWay(msg, endpoint);
    } catch (IOException ex) {
        throw new IOError(ex);
    }
}
Also used : Message(org.apache.cassandra.net.Message)

Example 32 with Message

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

the class RangeSliceResponseResolver method getData.

public List<Row> getData() throws IOException {
    Message response = responses.iterator().next();
    RangeSliceReply reply = RangeSliceReply.read(response.getMessageBody(), response.getVersion());
    return reply.rows;
}
Also used : Message(org.apache.cassandra.net.Message) RangeSliceReply(org.apache.cassandra.db.RangeSliceReply)

Example 33 with Message

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

the class RowDigestResolver method resolve.

/*
     * This method handles two different scenarios:
     *
     * a) we're handling the initial read, of data from the closest replica + digests
     *    from the rest.  In this case we check the digests against each other,
     *    throw an exception if there is a mismatch, otherwise return the data row.
     *
     * b) we're checking additional digests that arrived after the minimum to handle
     *    the requested ConsistencyLevel, i.e. asynchronous read repair check
     */
public Row resolve() throws DigestMismatchException, IOException {
    if (logger.isDebugEnabled())
        logger.debug("resolving " + replies.size() + " responses");
    long startTime = System.currentTimeMillis();
    // validate digests against each other; throw immediately on mismatch.
    // also extract the data reply, if any.
    ColumnFamily data = null;
    ByteBuffer digest = null;
    for (Map.Entry<Message, ReadResponse> entry : replies.entrySet()) {
        ReadResponse response = entry.getValue();
        if (response.isDigestQuery()) {
            if (digest == null) {
                digest = response.digest();
            } else {
                ByteBuffer digest2 = response.digest();
                if (!digest.equals(digest2))
                    throw new DigestMismatchException(key, digest, digest2);
            }
        } else {
            data = response.row().cf;
        }
    }
    // that can only happen when we're doing the repair post-mismatch, and will be handled by RowRepairResolver.
    if (digest != null) {
        ByteBuffer digest2 = ColumnFamily.digest(data);
        if (!digest.equals(digest2))
            throw new DigestMismatchException(key, digest, digest2);
        if (logger.isDebugEnabled())
            logger.debug("digests verified");
    }
    if (logger.isDebugEnabled())
        logger.debug("resolve: " + (System.currentTimeMillis() - startTime) + " ms.");
    return new Row(key, data);
}
Also used : Message(org.apache.cassandra.net.Message) ReadResponse(org.apache.cassandra.db.ReadResponse) Row(org.apache.cassandra.db.Row) ByteBuffer(java.nio.ByteBuffer) Map(java.util.Map) ColumnFamily(org.apache.cassandra.db.ColumnFamily)

Example 34 with Message

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

the class Gossiper method makeGossipDigestAck2Message.

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

Example 35 with Message

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

the class GossipDigestAckVerbHandler method doVerb.

public void doVerb(Message message, String id) {
    InetAddress from = message.getFrom();
    if (logger_.isTraceEnabled())
        logger_.trace("Received a GossipDigestAckMessage from {}", from);
    if (!Gossiper.instance.isEnabled()) {
        if (logger_.isTraceEnabled())
            logger_.trace("Ignoring GossipDigestAckMessage because gossip is disabled");
        return;
    }
    byte[] bytes = message.getMessageBody();
    DataInputStream dis = new DataInputStream(new FastByteArrayInputStream(bytes));
    try {
        GossipDigestAckMessage gDigestAckMessage = GossipDigestAckMessage.serializer().deserialize(dis, message.getVersion());
        List<GossipDigest> gDigestList = gDigestAckMessage.getGossipDigestList();
        Map<InetAddress, EndpointState> epStateMap = gDigestAckMessage.getEndpointStateMap();
        if (epStateMap.size() > 0) {
            /* Notify the Failure Detector */
            Gossiper.instance.notifyFailureDetector(epStateMap);
            Gossiper.instance.applyStateLocally(epStateMap);
        }
        /* Get the state required to send to this gossipee - construct GossipDigestAck2Message */
        Map<InetAddress, EndpointState> deltaEpStateMap = new HashMap<InetAddress, EndpointState>();
        for (GossipDigest gDigest : gDigestList) {
            InetAddress addr = gDigest.getEndpoint();
            EndpointState localEpStatePtr = Gossiper.instance.getStateForVersionBiggerThan(addr, gDigest.getMaxVersion());
            if (localEpStatePtr != null)
                deltaEpStateMap.put(addr, localEpStatePtr);
        }
        GossipDigestAck2Message gDigestAck2 = new GossipDigestAck2Message(deltaEpStateMap);
        Message gDigestAck2Message = Gossiper.instance.makeGossipDigestAck2Message(gDigestAck2, message.getVersion());
        if (logger_.isTraceEnabled())
            logger_.trace("Sending a GossipDigestAck2Message to {}", from);
        MessagingService.instance().sendOneWay(gDigestAck2Message, from);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : Message(org.apache.cassandra.net.Message) HashMap(java.util.HashMap) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) InetAddress(java.net.InetAddress)

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