Search in sources :

Example 1 with IndexedTerm

use of org.apache.cassandra.index.sasi.sa.IndexedTerm in project cassandra by apache.

the class OnDiskIndexBuilder method finish.

@SuppressWarnings("resource")
protected void finish(Descriptor descriptor, Pair<ByteBuffer, ByteBuffer> range, File file, TermIterator terms) {
    SequentialWriter out = null;
    try {
        out = new SequentialWriter(file, WRITER_OPTION);
        out.writeUTF(descriptor.version.toString());
        out.writeShort(termSize.size);
        // min, max term (useful to find initial scan range from search expressions)
        ByteBufferUtil.writeWithShortLength(terms.minTerm(), out);
        ByteBufferUtil.writeWithShortLength(terms.maxTerm(), out);
        // min, max keys covered by index (useful when searching across multiple indexes)
        ByteBufferUtil.writeWithShortLength(range.left, out);
        ByteBufferUtil.writeWithShortLength(range.right, out);
        out.writeUTF(mode.toString());
        out.writeBoolean(marksPartials);
        out.skipBytes((int) (BLOCK_SIZE - out.position()));
        dataLevel = mode == Mode.SPARSE ? new DataBuilderLevel(out, new MutableDataBlock(termComparator, mode)) : new MutableLevel<>(out, new MutableDataBlock(termComparator, mode));
        while (terms.hasNext()) {
            Pair<IndexedTerm, TokenTreeBuilder> term = terms.next();
            addTerm(new InMemoryDataTerm(term.left, term.right), out);
        }
        dataLevel.finalFlush();
        for (MutableLevel l : levels) // flush all of the buffers
        l.flush();
        // and finally write levels index
        final long levelIndexPosition = out.position();
        out.writeInt(levels.size());
        for (int i = levels.size() - 1; i >= 0; i--) levels.get(i).flushMetadata();
        dataLevel.flushMetadata();
        out.writeLong(levelIndexPosition);
        // sync contents of the output and disk,
        // since it's not done implicitly on close
        out.sync();
    } catch (IOException e) {
        throw new FSWriteError(e, file);
    } finally {
        FileUtils.closeQuietly(out);
    }
}
Also used : FSWriteError(org.apache.cassandra.io.FSWriteError) IndexedTerm(org.apache.cassandra.index.sasi.sa.IndexedTerm) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 IndexedTerm (org.apache.cassandra.index.sasi.sa.IndexedTerm)1 FSWriteError (org.apache.cassandra.io.FSWriteError)1