Search in sources :

Example 1 with MappedBuffer

use of org.apache.cassandra.index.sasi.utils.MappedBuffer in project cassandra by apache.

the class TokenTreeTest method buildSerializeAndIterate.

public void buildSerializeAndIterate(TokenTreeBuilder builder, SortedMap<Long, LongSet> tokenMap) throws Exception {
    builder.finish();
    final File treeFile = FileUtils.createTempFile("token-tree-iterate-test1", "tt");
    treeFile.deleteOnExit();
    try (SequentialWriter writer = new SequentialWriter(treeFile, DEFAULT_OPT)) {
        builder.write(writer);
        writer.sync();
    }
    final RandomAccessReader reader = RandomAccessReader.open(treeFile);
    final TokenTree tokenTree = new TokenTree(new MappedBuffer(reader));
    final Iterator<Token> tokenIterator = tokenTree.iterator(KEY_CONVERTER);
    final Iterator<Map.Entry<Long, LongSet>> listIterator = tokenMap.entrySet().iterator();
    while (tokenIterator.hasNext() && listIterator.hasNext()) {
        Token treeNext = tokenIterator.next();
        Map.Entry<Long, LongSet> listNext = listIterator.next();
        Assert.assertEquals(listNext.getKey(), treeNext.get());
        Assert.assertEquals(convert(listNext.getValue()), convert(treeNext));
    }
    Assert.assertFalse("token iterator not finished", tokenIterator.hasNext());
    Assert.assertFalse("list iterator not finished", listIterator.hasNext());
    reader.close();
}
Also used : LongSet(com.carrotsearch.hppc.LongSet) SequentialWriter(org.apache.cassandra.io.util.SequentialWriter) RandomAccessReader(org.apache.cassandra.io.util.RandomAccessReader) File(org.apache.cassandra.io.util.File) MappedBuffer(org.apache.cassandra.index.sasi.utils.MappedBuffer)

Example 2 with MappedBuffer

use of org.apache.cassandra.index.sasi.utils.MappedBuffer in project cassandra by apache.

the class TokenTreeTest method skipPastEnd.

public void skipPastEnd(TokenTreeBuilder builder, SortedMap<Long, LongSet> tokens) throws Exception {
    builder.finish();
    final File treeFile = FileUtils.createTempFile("token-tree-skip-past-test", "tt");
    treeFile.deleteOnExit();
    try (SequentialWriter writer = new SequentialWriter(treeFile, DEFAULT_OPT)) {
        builder.write(writer);
        writer.sync();
    }
    final RandomAccessReader reader = RandomAccessReader.open(treeFile);
    final RangeIterator<Long, Token> tokenTree = new TokenTree(new MappedBuffer(reader)).iterator(KEY_CONVERTER);
    tokenTree.skipTo(tokens.lastKey() + 10);
}
Also used : RandomAccessReader(org.apache.cassandra.io.util.RandomAccessReader) SequentialWriter(org.apache.cassandra.io.util.SequentialWriter) File(org.apache.cassandra.io.util.File) MappedBuffer(org.apache.cassandra.index.sasi.utils.MappedBuffer)

Example 3 with MappedBuffer

use of org.apache.cassandra.index.sasi.utils.MappedBuffer in project cassandra by apache.

the class TokenTreeTest method buildSerializeIterateAndSkip.

// works with maps other than bigTokensMap but skips to a rather large token
// so likely for maps other than bigTokensMap skipping is not tested by this.
public void buildSerializeIterateAndSkip(TokenTreeBuilder builder, SortedMap<Long, LongSet> tokens) throws Exception {
    builder.finish();
    final File treeFile = FileUtils.createTempFile("token-tree-iterate-test2", "tt");
    treeFile.deleteOnExit();
    try (SequentialWriter writer = new SequentialWriter(treeFile, DEFAULT_OPT)) {
        builder.write(writer);
        writer.sync();
    }
    final RandomAccessReader reader = RandomAccessReader.open(treeFile);
    final TokenTree tokenTree = new TokenTree(new MappedBuffer(reader));
    final RangeIterator<Long, Token> treeIterator = tokenTree.iterator(KEY_CONVERTER);
    final RangeIterator<Long, TokenWithOffsets> listIterator = new EntrySetSkippableIterator(tokens);
    long lastToken = 0L;
    while (treeIterator.hasNext() && lastToken < 12) {
        Token treeNext = treeIterator.next();
        TokenWithOffsets listNext = listIterator.next();
        Assert.assertEquals(listNext.token, (lastToken = treeNext.get()));
        Assert.assertEquals(convert(listNext.offsets), convert(treeNext));
    }
    treeIterator.skipTo(100548L);
    listIterator.skipTo(100548L);
    while (treeIterator.hasNext() && listIterator.hasNext()) {
        Token treeNext = treeIterator.next();
        TokenWithOffsets listNext = listIterator.next();
        Assert.assertEquals(listNext.token, (long) treeNext.get());
        Assert.assertEquals(convert(listNext.offsets), convert(treeNext));
    }
    Assert.assertFalse("Tree iterator not completed", treeIterator.hasNext());
    Assert.assertFalse("List iterator not completed", listIterator.hasNext());
    reader.close();
}
Also used : RandomAccessReader(org.apache.cassandra.io.util.RandomAccessReader) SequentialWriter(org.apache.cassandra.io.util.SequentialWriter) File(org.apache.cassandra.io.util.File) MappedBuffer(org.apache.cassandra.index.sasi.utils.MappedBuffer)

Example 4 with MappedBuffer

use of org.apache.cassandra.index.sasi.utils.MappedBuffer in project cassandra by apache.

the class OnDiskBlock method getTerm.

@SuppressWarnings("resource")
protected T getTerm(int index) {
    MappedBuffer dup = blockIndex.duplicate();
    long startsAt = getTermPosition(index);
    if (// last element
    termCount() - 1 == index)
        dup.position(startsAt);
    else
        dup.position(startsAt).limit(getTermPosition(index + 1));
    return cast(dup);
}
Also used : MappedBuffer(org.apache.cassandra.index.sasi.utils.MappedBuffer)

Example 5 with MappedBuffer

use of org.apache.cassandra.index.sasi.utils.MappedBuffer in project cassandra by apache.

the class TokenTreeTest method generateTree.

private static TokenTree generateTree(final long minToken, final long maxToken, boolean isStatic) throws IOException {
    final SortedMap<Long, LongSet> toks = new TreeMap<Long, LongSet>() {

        {
            for (long i = minToken; i <= maxToken; i++) {
                LongSet offsetSet = new LongHashSet();
                offsetSet.add(i);
                put(i, offsetSet);
            }
        }
    };
    final TokenTreeBuilder builder = isStatic ? new StaticTokenTreeBuilder(new FakeCombinedTerm(toks)) : new DynamicTokenTreeBuilder(toks);
    builder.finish();
    final File treeFile = FileUtils.createTempFile("token-tree-get-test", "tt");
    treeFile.deleteOnExit();
    try (SequentialWriter writer = new SequentialWriter(treeFile, DEFAULT_OPT)) {
        builder.write(writer);
        writer.sync();
    }
    RandomAccessReader reader = null;
    try {
        reader = RandomAccessReader.open(treeFile);
        return new TokenTree(new MappedBuffer(reader));
    } finally {
        FileUtils.closeQuietly(reader);
    }
}
Also used : LongSet(com.carrotsearch.hppc.LongSet) SequentialWriter(org.apache.cassandra.io.util.SequentialWriter) LongHashSet(com.carrotsearch.hppc.LongHashSet) RandomAccessReader(org.apache.cassandra.io.util.RandomAccessReader) File(org.apache.cassandra.io.util.File) MappedBuffer(org.apache.cassandra.index.sasi.utils.MappedBuffer)

Aggregations

MappedBuffer (org.apache.cassandra.index.sasi.utils.MappedBuffer)6 File (org.apache.cassandra.io.util.File)5 RandomAccessReader (org.apache.cassandra.io.util.RandomAccessReader)5 SequentialWriter (org.apache.cassandra.io.util.SequentialWriter)5 LongSet (com.carrotsearch.hppc.LongSet)2 LongHashSet (com.carrotsearch.hppc.LongHashSet)1