Search in sources :

Example 1 with ReadResponse

use of org.apache.cassandra.db.ReadResponse in project eiger by wlloyd.

the class AbstractRowResolver method preprocess.

public void preprocess(Message message) {
    byte[] body = message.getMessageBody();
    FastByteArrayInputStream bufIn = new FastByteArrayInputStream(body);
    try {
        ReadResponse result = ReadResponse.serializer().deserialize(new DataInputStream(bufIn), message.getVersion());
        if (logger.isDebugEnabled())
            logger.debug("Preprocessed {} response", result.isDigestQuery() ? "digest" : "data");
        replies.put(message, result);
    } catch (IOException e) {
        throw new IOError(e);
    }
}
Also used : FastByteArrayInputStream(org.apache.cassandra.io.util.FastByteArrayInputStream) ReadResponse(org.apache.cassandra.db.ReadResponse) IOError(java.io.IOError) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 2 with ReadResponse

use of org.apache.cassandra.db.ReadResponse 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)

Aggregations

ReadResponse (org.apache.cassandra.db.ReadResponse)2 DataInputStream (java.io.DataInputStream)1 IOError (java.io.IOError)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 Map (java.util.Map)1 ColumnFamily (org.apache.cassandra.db.ColumnFamily)1 Row (org.apache.cassandra.db.Row)1 FastByteArrayInputStream (org.apache.cassandra.io.util.FastByteArrayInputStream)1 Message (org.apache.cassandra.net.Message)1