Search in sources :

Example 1 with NamesQueryFilter

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

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

the class HintedHandOffManager method scheduleAllDeliveries.

/**
 * Attempt delivery to any node for which we have hints.  Necessary since we can generate hints even for
 * nodes which are never officially down/failed.
 */
private void scheduleAllDeliveries() {
    if (logger_.isDebugEnabled())
        logger_.debug("Started scheduleAllDeliveries");
    ColumnFamilyStore hintStore = Table.open(Table.SYSTEM_TABLE).getColumnFamilyStore(HINTS_CF);
    IPartitioner p = StorageService.getPartitioner();
    RowPosition minPos = p.getMinimumToken().minKeyBound();
    Range<RowPosition> range = new Range<RowPosition>(minPos, minPos, p);
    IFilter filter = new NamesQueryFilter(ImmutableSortedSet.<ByteBuffer>of());
    List<Row> rows = hintStore.getRangeSlice(null, range, Integer.MAX_VALUE, filter, null);
    for (Row row : rows) {
        Token<?> token = StorageService.getPartitioner().getTokenFactory().fromByteArray(row.key.key);
        InetAddress target = StorageService.instance.getTokenMetadata().getEndpoint(token);
        scheduleHintDelivery(target);
    }
    if (logger_.isDebugEnabled())
        logger_.debug("Finished scheduleAllDeliveries");
}
Also used : IFilter(org.apache.cassandra.db.filter.IFilter) Range(org.apache.cassandra.dht.Range) NamesQueryFilter(org.apache.cassandra.db.filter.NamesQueryFilter) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 3 with NamesQueryFilter

use of org.apache.cassandra.db.filter.NamesQueryFilter in project janusgraph by JanusGraph.

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 {
            // This is a singleton set.  We need to define a comparator because SimpleDenseCellName is not
            // comparable, but the comparator that we pass into the TreeSet constructor does not have to be useful
            final SortedSet<CellName> names = new TreeSet<>((o1, o2) -> 0);
            names.add(CellNames.simpleDense(ByteBufferUtil.zeroByteBuffer(1)));
            NamesQueryFilter nqf = new NamesQueryFilter(names);
            final SliceByNamesReadCommand cmd = new SliceByNamesReadCommand(ks, ByteBufferUtil.zeroByteBuffer(1), cf, 1L, nqf);
            StorageProxy.read(ImmutableList.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 4 with NamesQueryFilter

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

the class CollationController method collectTimeOrderedData.

/**
 * Collects data in order of recency, using the sstable maxtimestamp data.
 * Once we have data for all requests columns that is newer than the newest remaining maxtimestamp,
 * we stop.
 */
private ColumnFamily collectTimeOrderedData() {
    logger.debug("collectTimeOrderedData");
    ISortedColumns.Factory factory = mutableColumns ? AtomicSortedColumns.factory() : TreeMapBackedSortedColumns.factory();
    ColumnFamily container = ColumnFamily.create(cfs.metadata, factory, filter.filter.isReversed());
    List<IColumnIterator> iterators = new ArrayList<IColumnIterator>();
    ColumnFamilyStore.ViewFragment view = cfs.markReferenced(filter.key);
    try {
        for (Memtable memtable : view.memtables) {
            IColumnIterator iter = filter.getMemtableColumnIterator(memtable);
            if (iter != null) {
                iterators.add(iter);
                container.delete(iter.getColumnFamily());
                while (iter.hasNext()) container.addColumn(iter.next());
            }
        }
        // avoid changing the filter columns of the original filter
        // (reduceNameFilter removes columns that are known to be irrelevant)
        TreeSet<ByteBuffer> filterColumns = new TreeSet<ByteBuffer>(((NamesQueryFilter) filter.filter).columns);
        QueryFilter reducedFilter = new QueryFilter(filter.key, filter.path, new NamesQueryFilter(filterColumns));
        /* add the SSTables on disk */
        Collections.sort(view.sstables, SSTable.maxTimestampComparator);
        // read sorted sstables
        for (SSTableReader sstable : view.sstables) {
            long currentMaxTs = sstable.getMaxTimestamp();
            reduceNameFilter(reducedFilter, container, currentMaxTs);
            if (((NamesQueryFilter) reducedFilter.filter).columns.isEmpty())
                break;
            IColumnIterator iter = reducedFilter.getSSTableColumnIterator(sstable);
            iterators.add(iter);
            if (iter.getColumnFamily() != null) {
                container.delete(iter.getColumnFamily());
                sstablesIterated++;
                while (iter.hasNext()) container.addColumn(iter.next());
            }
        }
        // and "there used to be data, but it's gone now" (we should cache the empty CF so we don't need to rebuild that slower)
        if (iterators.isEmpty())
            return null;
        // do a final collate.  toCollate is boilerplate required to provide a CloseableIterator
        final ColumnFamily c2 = container;
        CloseableIterator<IColumn> toCollate = new SimpleAbstractColumnIterator() {

            final Iterator<IColumn> iter = c2.iterator();

            protected IColumn computeNext() {
                return iter.hasNext() ? iter.next() : endOfData();
            }

            public ColumnFamily getColumnFamily() {
                return c2;
            }

            public DecoratedKey getKey() {
                return filter.key;
            }
        };
        ColumnFamily returnCF = container.cloneMeShallow();
        filter.collateColumns(returnCF, Collections.singletonList(toCollate), gcBefore);
        // "hoist up" the requested data into a more recent sstable
        if (sstablesIterated > cfs.getMinimumCompactionThreshold() && !cfs.isCompactionDisabled() && cfs.getCompactionStrategy() instanceof SizeTieredCompactionStrategy) {
            RowMutation rm = new RowMutation(cfs.table.name, new Row(filter.key, returnCF.cloneMe()));
            try {
                // skipping commitlog and index updates is fine since we're just de-fragmenting existing data
                Table.open(rm.getTable()).apply(rm, false, false);
            } catch (IOException e) {
                // log and allow the result to be returned
                logger.error("Error re-writing read results", e);
            }
        }
        // Caller is responsible for final removeDeletedCF.  This is important for cacheRow to work correctly:
        return returnCF;
    } finally {
        for (IColumnIterator iter : iterators) FileUtils.closeQuietly(iter);
        SSTableReader.releaseReferences(view.sstables);
    }
}
Also used : IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) SimpleAbstractColumnIterator(org.apache.cassandra.db.columniterator.SimpleAbstractColumnIterator) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) NamesQueryFilter(org.apache.cassandra.db.filter.NamesQueryFilter) NamesQueryFilter(org.apache.cassandra.db.filter.NamesQueryFilter) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) CloseableIterator(org.apache.cassandra.utils.CloseableIterator) SimpleAbstractColumnIterator(org.apache.cassandra.db.columniterator.SimpleAbstractColumnIterator) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) SizeTieredCompactionStrategy(org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy)

Aggregations

NamesQueryFilter (org.apache.cassandra.db.filter.NamesQueryFilter)4 SliceByNamesReadCommand (org.apache.cassandra.db.SliceByNamesReadCommand)2 CellName (org.apache.cassandra.db.composites.CellName)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 ByteBuffer (java.nio.ByteBuffer)1 IColumnIterator (org.apache.cassandra.db.columniterator.IColumnIterator)1 SimpleAbstractColumnIterator (org.apache.cassandra.db.columniterator.SimpleAbstractColumnIterator)1 SizeTieredCompactionStrategy (org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy)1 IFilter (org.apache.cassandra.db.filter.IFilter)1 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 Range (org.apache.cassandra.dht.Range)1 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)1 CloseableIterator (org.apache.cassandra.utils.CloseableIterator)1