Search in sources :

Example 61 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class BPlusTree method addAndReturnOld.

/**
 * Add a record into the B+Tree
 */
public Record addAndReturnOld(Record record) {
    startUpdateBlkMgr();
    BPTreeNode root = getRoot();
    Record r = BPTreeNode.insert(root, record);
    if (CheckingTree)
        root.checkNodeDeep();
    releaseRoot(root);
    finishUpdateBlkMgr();
    return r;
}
Also used : Record(org.apache.jena.tdb.base.record.Record)

Example 62 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class BPlusTree method clear.

@Override
public void clear() {
    Record[] records = new Record[SLICE];
    while (true) {
        Iterator<Record> iter = iterator();
        int i = 0;
        for (i = 0; i < SLICE; i++) {
            if (!iter.hasNext())
                break;
            Record r = iter.next();
            records[i] = r;
        }
        if (i == 0)
            break;
        for (int j = 0; j < i; j++) {
            delete(records[j]);
            records[j] = null;
        }
    }
}
Also used : Record(org.apache.jena.tdb.base.record.Record)

Example 63 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class BPlusTree method find.

@Override
public Record find(Record record) {
    startReadBlkMgr();
    BPTreeNode root = getRoot();
    Record v = BPTreeNode.search(root, record);
    releaseRoot(root);
    finishReadBlkMgr();
    return v;
}
Also used : Record(org.apache.jena.tdb.base.record.Record)

Example 64 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class BPlusTreeRewriter method writePackedDataBlocks.

// **** data block phase
/**
 * Pack record blocks into linked RecordBufferPages
 */
private static Iterator<Pair<Integer, Record>> writePackedDataBlocks(Iterator<Record> records, final BPlusTree bpt) {
    if (debug) {
        divider();
        System.out.println("---- Data level");
    }
    final RecordBufferPageMgr mgr = bpt.getRecordsMgr().getRecordBufferPageMgr();
    Iterator<RecordBufferPage> iter = new RecordBufferPageLinker(new RecordBufferPagePacker(records, mgr));
    Function<RecordBufferPage, Pair<Integer, Record>> transform = rbp -> {
        mgr.put(rbp);
        Record r = rbp.getRecordBuffer().getHigh();
        r = bpt.getRecordFactory().createKeyOnly(r);
        return new Pair<>(rbp.getId(), r);
    };
    // Write and convert to split pairs.
    Iterator<Pair<Integer, Record>> iter2 = Iter.map(iter, transform);
    if (debug) {
        if (rebalance)
            System.out.println("Before rebalance (data)");
        iter2 = summarizeDataBlocks(iter2, bpt.getRecordsMgr().getRecordBufferPageMgr());
    // iter2 = printDataBlocks(iter2, bpt.getRecordsMgr().getRecordBufferPageMgr()) ;
    }
    if (rebalance)
        iter2 = new RebalenceDataEnd(iter2, bpt);
    // Testing - materialize - debug wil have done this
    if (materialize && !debug)
        iter2 = Iter.toList(iter2).iterator();
    if (debug && rebalance) {
        System.out.println("After rebalance (data)");
        iter2 = summarizeDataBlocks(iter2, bpt.getRecordsMgr().getRecordBufferPageMgr());
    // iter2 = printDataBlocks(iter2, bpt.getRecordsMgr().getRecordBufferPageMgr()) ;
    }
    return iter2;
}
Also used : IteratorWithBuffer(org.apache.jena.atlas.iterator.IteratorWithBuffer) Record(org.apache.jena.tdb.base.record.Record) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) LoggerFactory(org.slf4j.LoggerFactory) BPlusTreeRewriterUtils.summarizeDataBlocks(org.apache.jena.tdb.index.bplustree.BPlusTreeRewriterUtils.summarizeDataBlocks) RecordFactory(org.apache.jena.tdb.base.record.RecordFactory) Function(java.util.function.Function) BlockMgr(org.apache.jena.tdb.base.block.BlockMgr) BPlusTreeRewriterUtils.printIndexBlocks(org.apache.jena.tdb.index.bplustree.BPlusTreeRewriterUtils.printIndexBlocks) BPlusTreeRewriterUtils.divider(org.apache.jena.tdb.index.bplustree.BPlusTreeRewriterUtils.divider) RecordBufferPageMgr(org.apache.jena.tdb.base.recordbuffer.RecordBufferPageMgr) Pair(org.apache.jena.atlas.lib.Pair) RecordBuffer(org.apache.jena.tdb.base.buffer.RecordBuffer) Iter(org.apache.jena.atlas.iterator.Iter) PtrBuffer(org.apache.jena.tdb.base.buffer.PtrBuffer) RecordBufferPage(org.apache.jena.tdb.base.recordbuffer.RecordBufferPage) RecordBufferPageMgr(org.apache.jena.tdb.base.recordbuffer.RecordBufferPageMgr) Record(org.apache.jena.tdb.base.record.Record) RecordBufferPage(org.apache.jena.tdb.base.recordbuffer.RecordBufferPage) Pair(org.apache.jena.atlas.lib.Pair)

Example 65 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class BPlusTreeRewriterUtils method summarizeDataBlocks.

static Iterator<Pair<Integer, Record>> summarizeDataBlocks(Iterator<Pair<Integer, Record>> iter, RecordBufferPageMgr recordPageMgr) {
    divider();
    List<Pair<Integer, Record>> x = Iter.toList(iter);
    for (Pair<Integer, Record> pair : x) {
        RecordBufferPage rbp = recordPageMgr.getRead(pair.car());
        System.out.printf("%s -- RecordBufferPage[id=%d,link=%d] (%d) -> [%s]\n", pair, rbp.getId(), rbp.getLink(), rbp.getCount(), rbp.getRecordBuffer().getHigh());
        recordPageMgr.release(rbp);
    }
    return x.iterator();
}
Also used : Record(org.apache.jena.tdb.base.record.Record) Pair(org.apache.jena.atlas.lib.Pair) RecordBufferPage(org.apache.jena.tdb.base.recordbuffer.RecordBufferPage)

Aggregations

Record (org.apache.jena.tdb.base.record.Record)95 Test (org.junit.Test)20 RecordLib.intToRecord (org.apache.jena.tdb.base.record.RecordLib.intToRecord)15 RecordBuffer (org.apache.jena.tdb.base.buffer.RecordBuffer)14 BaseTest (org.apache.jena.atlas.junit.BaseTest)10 RangeIndex (org.apache.jena.tdb.index.RangeIndex)8 BlockMgr (org.apache.jena.tdb.base.block.BlockMgr)6 RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)6 NoSuchElementException (java.util.NoSuchElementException)5 FileSet (org.apache.jena.tdb.base.file.FileSet)5 BPlusTree (org.apache.jena.tdb.index.bplustree.BPlusTree)5 NodeId (org.apache.jena.tdb.store.NodeId)5 Pair (org.apache.jena.atlas.lib.Pair)4 Location (org.apache.jena.tdb.base.file.Location)4 BPlusTreeParams (org.apache.jena.tdb.index.bplustree.BPlusTreeParams)4 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)3 StorageException (org.apache.jena.tdb.base.StorageException)3 RecordBufferPage (org.apache.jena.tdb.base.recordbuffer.RecordBufferPage)3 ColumnMap (org.apache.jena.tdb.lib.ColumnMap)3 TupleIndexRecord (org.apache.jena.tdb.store.tupletable.TupleIndexRecord)3