Search in sources :

Example 6 with Row

use of org.apache.cassandra.db.Row 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 7 with Row

use of org.apache.cassandra.db.Row in project brisk by riptano.

the class TrackerManager method getCurrentJobtrackerLocation.

/**
 * Retrieves the current job tracker IP.
 *
 * @return the current job tracker IP
 * @throws TrackerManagerException
 */
public static InetAddress getCurrentJobtrackerLocation() throws TrackerManagerException {
    ReadCommand rc = new SliceByNamesReadCommand(BriskSchema.KEYSPACE_NAME, currentJobtrackerKey, cp, Arrays.asList(columnName));
    String result;
    try {
        List<Row> rows = StorageProxy.read(Arrays.asList(rc), ConsistencyLevel.QUORUM);
        IColumn col = validateAndGetColumn(rows, columnName);
        // ByteBuffer util duplicates for us the value.
        result = ByteBufferUtil.string(col.value());
        return InetAddress.getByName(result);
    } catch (NotFoundException e) {
        return null;
    } catch (Exception e) {
        throw new TrackerManagerException(e);
    }
}
Also used : IColumn(org.apache.cassandra.db.IColumn) SliceByNamesReadCommand(org.apache.cassandra.db.SliceByNamesReadCommand) ReadCommand(org.apache.cassandra.db.ReadCommand) SliceByNamesReadCommand(org.apache.cassandra.db.SliceByNamesReadCommand) NotFoundException(org.apache.cassandra.thrift.NotFoundException) Row(org.apache.cassandra.db.Row) NotFoundException(org.apache.cassandra.thrift.NotFoundException)

Aggregations

Row (org.apache.cassandra.db.Row)7 ByteBuffer (java.nio.ByteBuffer)2 ColumnFamily (org.apache.cassandra.db.ColumnFamily)2 IColumn (org.apache.cassandra.db.IColumn)2 Message (org.apache.cassandra.net.Message)2 NotFoundException (org.apache.cassandra.thrift.NotFoundException)2 Utils (com.tuplejump.stargate.Utils)1 RowFetcher (com.tuplejump.stargate.cassandra.RowFetcher)1 IndexEntryCollector (com.tuplejump.stargate.lucene.IndexEntryCollector)1 Map (java.util.Map)1 DecoratedKey (org.apache.cassandra.db.DecoratedKey)1 RangeSliceReply (org.apache.cassandra.db.RangeSliceReply)1 ReadCommand (org.apache.cassandra.db.ReadCommand)1 ReadResponse (org.apache.cassandra.db.ReadResponse)1 SliceByNamesReadCommand (org.apache.cassandra.db.SliceByNamesReadCommand)1 CellName (org.apache.cassandra.db.composites.CellName)1