Search in sources :

Example 36 with QueryPath

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

the class SSTableReaderTest method testSpannedIndexPositions.

@Test
public void testSpannedIndexPositions() throws IOException, ExecutionException, InterruptedException {
    // each index entry is ~11 bytes, so this will generate lots of segments
    MmappedSegmentedFile.MAX_SEGMENT_SIZE = 40;
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
    // insert a bunch of data and compact to a single sstable
    CompactionManager.instance.disableAutoCompaction();
    for (int j = 0; j < 100; j += 2) {
        ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j));
        RowMutation rm = new RowMutation("Keyspace1", key);
        rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j);
        rm.apply();
    }
    store.forceBlockingFlush();
    CompactionManager.instance.performMaximal(store);
    // check that all our keys are found correctly
    SSTableReader sstable = store.getSSTables().iterator().next();
    for (int j = 0; j < 100; j += 2) {
        DecoratedKey dk = Util.dk(String.valueOf(j));
        FileDataInput file = sstable.getFileDataInput(dk, DatabaseDescriptor.getIndexedReadBufferSizeInKB() * 1024);
        DecoratedKey keyInDisk = SSTableReader.decodeKey(sstable.partitioner, sstable.descriptor, ByteBufferUtil.readWithShortLength(file));
        assert keyInDisk.equals(dk) : String.format("%s != %s in %s", keyInDisk, dk, file.getPath());
    }
    // check no false positives
    for (int j = 1; j < 110; j += 2) {
        DecoratedKey dk = Util.dk(String.valueOf(j));
        assert sstable.getPosition(dk, SSTableReader.Operator.EQ) == -1;
    }
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) FileDataInput(org.apache.cassandra.io.util.FileDataInput) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 37 with QueryPath

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

the class SSTableReaderTest method testGetPositionsForRangesWithKeyCache.

@Test
public void testGetPositionsForRangesWithKeyCache() throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore store = table.getColumnFamilyStore("Standard2");
    CacheService.instance.keyCache.setCapacity(100);
    // insert data and compact to a single sstable
    CompactionManager.instance.disableAutoCompaction();
    for (int j = 0; j < 10; j++) {
        ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j));
        RowMutation rm = new RowMutation("Keyspace1", key);
        rm.add(new QueryPath("Standard2", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j);
        rm.apply();
    }
    store.forceBlockingFlush();
    CompactionManager.instance.performMaximal(store);
    SSTableReader sstable = store.getSSTables().iterator().next();
    long p2 = sstable.getPosition(k(2), SSTableReader.Operator.EQ);
    long p3 = sstable.getPosition(k(3), SSTableReader.Operator.EQ);
    long p6 = sstable.getPosition(k(6), SSTableReader.Operator.EQ);
    long p7 = sstable.getPosition(k(7), SSTableReader.Operator.EQ);
    Pair<Long, Long> p = sstable.getPositionsForRanges(makeRanges(t(2), t(6))).iterator().next();
    // range are start exclusive so we should start at 3
    assert p.left == p3;
    // to capture 6 we have to stop at the start of 7
    assert p.right == p7;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 38 with QueryPath

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

the class SSTableReaderTest method testPersistentStatistics.

@Test
public void testPersistentStatistics() throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
    for (int j = 0; j < 100; j += 2) {
        ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j));
        RowMutation rm = new RowMutation("Keyspace1", key);
        rm.add(new QueryPath("Standard1", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j);
        rm.apply();
    }
    store.forceBlockingFlush();
    store.clearUnsafe();
    store.loadNewSSTables();
    assert store.getMaxRowSize() != 0;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 39 with QueryPath

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

the class SSTableReaderTest method testGetPositionsForRanges.

@Test
public void testGetPositionsForRanges() throws IOException, ExecutionException, InterruptedException {
    Table table = Table.open("Keyspace1");
    ColumnFamilyStore store = table.getColumnFamilyStore("Standard2");
    // insert data and compact to a single sstable
    CompactionManager.instance.disableAutoCompaction();
    for (int j = 0; j < 10; j++) {
        ByteBuffer key = ByteBufferUtil.bytes(String.valueOf(j));
        RowMutation rm = new RowMutation("Keyspace1", key);
        rm.add(new QueryPath("Standard2", null, ByteBufferUtil.bytes("0")), ByteBufferUtil.EMPTY_BYTE_BUFFER, j);
        rm.apply();
    }
    store.forceBlockingFlush();
    CompactionManager.instance.performMaximal(store);
    List<Range<Token>> ranges = new ArrayList<Range<Token>>();
    // 1 key
    ranges.add(new Range<Token>(t(0), t(1)));
    // 2 keys
    ranges.add(new Range<Token>(t(2), t(4)));
    // wrapping range from key to end
    ranges.add(new Range<Token>(t(6), StorageService.getPartitioner().getMinimumToken()));
    // empty range (should be ignored)
    ranges.add(new Range<Token>(t(9), t(91)));
    // confirm that positions increase continuously
    SSTableReader sstable = store.getSSTables().iterator().next();
    long previous = -1;
    for (Pair<Long, Long> section : sstable.getPositionsForRanges(ranges)) {
        assert previous <= section.left : previous + " ! < " + section.left;
        assert section.left < section.right : section.left + " ! < " + section.right;
        previous = section.right;
    }
}
Also used : ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) ByteBuffer(java.nio.ByteBuffer) QueryPath(org.apache.cassandra.db.filter.QueryPath) Test(org.junit.Test)

Example 40 with QueryPath

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

the class TimeSortTest method validateTimeSort.

private void validateTimeSort(Table table) throws IOException {
    for (int i = 900; i < 1000; ++i) {
        DecoratedKey key = Util.dk(Integer.toString(i));
        for (int j = 0; j < 8; j += 3) {
            ColumnFamily cf = table.getColumnFamilyStore("StandardLong1").getColumnFamily(key, new QueryPath("StandardLong1"), getBytes(j * 2), ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 1000);
            Collection<IColumn> columns = cf.getSortedColumns();
            assert columns.size() == 8 - j;
            int k = j;
            for (IColumn c : columns) {
                assertEquals((k++) * 2, c.timestamp());
            }
        }
    }
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath)

Aggregations

QueryPath (org.apache.cassandra.db.filter.QueryPath)123 Test (org.junit.Test)67 ByteBuffer (java.nio.ByteBuffer)40 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)22 ColumnFamily (org.apache.cassandra.db.ColumnFamily)14 RowMutation (org.apache.cassandra.db.RowMutation)11 File (java.io.File)10 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)10 IOException (java.io.IOException)8 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)8 DecoratedKey (org.apache.cassandra.db.DecoratedKey)8 Table (org.apache.cassandra.db.Table)8 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)8 WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)8 IColumn (org.apache.cassandra.db.IColumn)6 ArrayList (java.util.ArrayList)5 PrintStream (java.io.PrintStream)4 UnknownHostException (java.net.UnknownHostException)4 HashSet (java.util.HashSet)4 DropColumnFamily (org.apache.cassandra.db.migration.DropColumnFamily)4