Search in sources :

Example 1 with SliceByNamesReadCommand

use of org.apache.cassandra.db.SliceByNamesReadCommand in project titan by thinkaurelius.

the class CassandraEmbeddedStoreManager method retryDummyRead.

private void retryDummyRead(String ks, String cf) throws PermanentBackendException {
    final long limit = System.currentTimeMillis() + (60L * 1000L);
    while (System.currentTimeMillis() < limit) {
        try {
            SortedSet<CellName> names = new TreeSet<>(new Comparator<CellName>() {

                // This is a singleton set.  We need to define a comparator because SimpleDenseCellName is not
                // comparable, but it doesn't have to be a useful comparator
                @Override
                public int compare(CellName o1, CellName o2) {
                    return 0;
                }
            });
            names.add(CellNames.simpleDense(ByteBufferUtil.zeroByteBuffer(1)));
            NamesQueryFilter nqf = new NamesQueryFilter(names);
            SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(ks, ByteBufferUtil.zeroByteBuffer(1), cf, 1L, nqf);
            StorageProxy.read(ImmutableList.<ReadCommand>of(cmd), ConsistencyLevel.QUORUM);
            log.info("Read on CF {} in KS {} succeeded", cf, ks);
            return;
        } catch (Throwable t) {
            log.warn("Failed to read CF {} in KS {} following creation", cf, ks, t);
        }
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            throw new PermanentBackendException(e);
        }
    }
    throw new PermanentBackendException("Timed out while attempting to read CF " + cf + " in KS " + ks + " following creation");
}
Also used : SliceByNamesReadCommand(org.apache.cassandra.db.SliceByNamesReadCommand) CellName(org.apache.cassandra.db.composites.CellName) NamesQueryFilter(org.apache.cassandra.db.filter.NamesQueryFilter)

Example 2 with SliceByNamesReadCommand

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

SliceByNamesReadCommand (org.apache.cassandra.db.SliceByNamesReadCommand)2 IColumn (org.apache.cassandra.db.IColumn)1 ReadCommand (org.apache.cassandra.db.ReadCommand)1 Row (org.apache.cassandra.db.Row)1 CellName (org.apache.cassandra.db.composites.CellName)1 NamesQueryFilter (org.apache.cassandra.db.filter.NamesQueryFilter)1 NotFoundException (org.apache.cassandra.thrift.NotFoundException)1