当前位置: 首页>>代码示例>>Java>>正文


Java SSTableReader.getScanner方法代码示例

本文整理汇总了Java中org.apache.cassandra.io.sstable.SSTableReader.getScanner方法的典型用法代码示例。如果您正苦于以下问题:Java SSTableReader.getScanner方法的具体用法?Java SSTableReader.getScanner怎么用?Java SSTableReader.getScanner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cassandra.io.sstable.SSTableReader的用法示例。


在下文中一共展示了SSTableReader.getScanner方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNoExpire

import org.apache.cassandra.io.sstable.SSTableReader; //导入方法依赖的package包/类
@Test
public void testNoExpire() throws InterruptedException
{
    ColumnFamilyStore cfs = Keyspace.open("Keyspace1").getColumnFamilyStore("Standard1");
    cfs.disableAutoCompaction();
    cfs.metadata.gcGraceSeconds(0);
    long timestamp = System.currentTimeMillis();
    Mutation rm = new Mutation("Keyspace1", Util.dk("ttl").getKey());
    rm.add("Standard1", Util.cellname("col"),
           ByteBufferUtil.EMPTY_BYTE_BUFFER,
           timestamp,
           1);
    rm.add("Standard1", Util.cellname("col7"),
           ByteBufferUtil.EMPTY_BYTE_BUFFER,
           timestamp,
           1);

    rm.apply();
    cfs.forceBlockingFlush();

    rm = new Mutation("Keyspace1", Util.dk("ttl").getKey());
            rm.add("Standard1", Util.cellname("col2"),
                   ByteBufferUtil.EMPTY_BYTE_BUFFER,
                   timestamp,
                   1);
            rm.apply();
    cfs.forceBlockingFlush();
    rm = new Mutation("Keyspace1", Util.dk("ttl").getKey());
    rm.add("Standard1", Util.cellname("col3"),
               ByteBufferUtil.EMPTY_BYTE_BUFFER,
               timestamp,
               1);
    rm.apply();
    cfs.forceBlockingFlush();
    DecoratedKey noTTLKey = Util.dk("nottl");
    rm = new Mutation("Keyspace1", noTTLKey.getKey());
    rm.add("Standard1", Util.cellname("col311"),
               ByteBufferUtil.EMPTY_BYTE_BUFFER,
               timestamp);
    rm.apply();
    cfs.forceBlockingFlush();
    Thread.sleep(2000); // wait for ttl to expire
    assertEquals(4, cfs.getSSTables().size());
    cfs.enableAutoCompaction(true);
    assertEquals(1, cfs.getSSTables().size());
    SSTableReader sstable = cfs.getSSTables().iterator().next();
    ISSTableScanner scanner = sstable.getScanner(DataRange.allData(sstable.partitioner));
    assertTrue(scanner.hasNext());
    while(scanner.hasNext())
    {
        OnDiskAtomIterator iter = scanner.next();
        assertEquals(noTTLKey, iter.getKey());
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:55,代码来源:TTLExpiryTest.java

示例2: getIterator

import org.apache.cassandra.io.sstable.SSTableReader; //导入方法依赖的package包/类
/**
 * Get a row iterator over the provided memtables and sstables, between the provided keys
 * and filtered by the queryfilter.
 * @param memtables Memtables pending flush.
 * @param sstables SStables to scan through.
 * @param range The data range to fetch
 * @param cfs
 * @return A row iterator following all the given restrictions
 */
public static CloseableIterator<Row> getIterator(final Iterable<Memtable> memtables,
                                                 final Collection<SSTableReader> sstables,
                                                 final DataRange range,
                                                 final ColumnFamilyStore cfs,
                                                 final long now)
{
    // fetch data from current memtable, historical memtables, and SSTables in the correct order.
    final List<CloseableIterator<OnDiskAtomIterator>> iterators = new ArrayList<CloseableIterator<OnDiskAtomIterator>>();

    // memtables
    for (Memtable memtable : memtables)
    {
        iterators.add(new ConvertToColumnIterator<AtomicSortedColumns>(range, memtable.getEntryIterator(range.startKey(), range.stopKey())));
    }

    for (SSTableReader sstable : sstables)
    {
        final SSTableScanner scanner = sstable.getScanner(range);
        iterators.add(scanner);
    }

    // reduce rows from all sources into a single row
    return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<OnDiskAtomIterator, Row>()
    {
        private final int gcBefore = cfs.gcBefore(now);
        private final List<OnDiskAtomIterator> colIters = new ArrayList<OnDiskAtomIterator>();
        private DecoratedKey key;
        private ColumnFamily returnCF;

        @Override
        protected void onKeyChange()
        {
            this.returnCF = TreeMapBackedSortedColumns.factory.create(cfs.metadata);
        }

        public void reduce(OnDiskAtomIterator current)
        {
            this.colIters.add(current);
            this.key = current.getKey();
            this.returnCF.delete(current.getColumnFamily());
        }

        protected Row getReduced()
        {
            // First check if this row is in the rowCache. If it is we can skip the rest
            ColumnFamily cached = cfs.getRawCachedRow(key);
            if (cached == null)
            {
                // not cached: collate
                QueryFilter.collateOnDiskAtom(returnCF, colIters, range.columnFilter(key.key), gcBefore, now);
            }
            else
            {
                QueryFilter keyFilter = new QueryFilter(key, cfs.name, range.columnFilter(key.key), now);
                returnCF = cfs.filterColumnFamily(cached, keyFilter);
            }

            Row rv = new Row(key, returnCF);
            colIters.clear();
            key = null;
            return rv;
        }
    });
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:74,代码来源:RowIteratorFactory.java


注:本文中的org.apache.cassandra.io.sstable.SSTableReader.getScanner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。