Search in sources :

Example 61 with Record

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

the class BPTreeNode method internalInsert.

// ============ INSERT
/*
     * Traverse this page, ensuring the node below is not full before
     * decending. Therefore there is always space to do the actual insert.
     */
@Override
final Record internalInsert(AccessPath path, Record record) {
    if (logging(log))
        log(log, "internalInsert: %s [%s]", record, this);
    internalCheckNode();
    int idx = findSlot(record);
    if (logging(log))
        log(log, "internalInsert: idx=%d (=>%d)", idx, apply(idx));
    idx = apply(idx);
    BPTreePage page = get(idx);
    trackPath(path, this, idx, page);
    if (logging(log))
        log(log, "internalInsert: next: %s", page);
    if (page.isFull()) {
        // Need to split the page before descending.
        split(path, idx, page);
        // Examine the record we pulled up in the split.
        if (Record.keyGT(record, records.get(idx))) {
            page.release();
            // Yes. Get the new (upper) page
            idx = idx + 1;
            page = get(idx);
            path.reset(this, idx, page);
        }
        internalCheckNode();
    }
    Record r = page.internalInsert(path, record);
    page.release();
    return r;
}
Also used : Record(org.apache.jena.dboe.base.record.Record)

Example 62 with Record

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

the class BPTreeNode method merge.

/**
 * Merge left with right; fills left, frees right
 */
private BPTreePage merge(BPTreePage left, BPTreePage right, int dividingSlot) {
    if (logging(log)) {
        log(log, ">> merge(@%d): %s", dividingSlot, this);
        log(log, ">> left:  %s", left);
        log(log, ">> right: %s", right);
    }
    // /==\ + key + /==\ ==> /====\
    Record splitKey = records.get(dividingSlot);
    BPTreePage page = left.merge(right, splitKey);
    // Must release right (not done in merge)
    if (logging(log))
        log(log, "-- merge: %s", page);
    left.write();
    left.release();
    right.free();
    if (page == right)
        BPT.error("Returned page is not the left");
    if (BPT.CheckingNode) {
        if (isLeaf) {
            // possible.
            if (left.getCount() + 1 != left.getMaxSize() && left.getCount() != left.getMaxSize())
                BPT.error("Inconsistent data node size: %d/%d", left.getCount(), left.getMaxSize());
        } else if (!left.isFull()) {
            // If not two data blocks, the left side should now be full
            // (N+N+split)
            BPT.error("Inconsistent node size: %d/%d", left.getCount(), left.getMaxSize());
        }
    }
    // Remove from parent (which is "this")
    shuffleDown(dividingSlot);
    this.write();
    internalCheckNodeDeep();
    if (logging(log)) {
        log(log, "<< merge: %s", this);
        log(log, "<< left:  %s", left);
    }
    return left;
}
Also used : Record(org.apache.jena.dboe.base.record.Record)

Example 63 with Record

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

the class BPTreeNode method shiftRight.

private void shiftRight(BPTreePage left, BPTreePage right, int i) {
    if (logging(log)) {
        log(log, ">> shiftRight: this:  %s", this);
        log(log, ">> shiftRight: left:  %s", left);
        log(log, ">> shiftRight: right: %s", right);
    }
    Record r1 = records.get(i);
    Record r2 = left.shiftRight(right, r1);
    r2 = keyRecord(r2);
    this.records.set(i, r2);
    left.write();
    right.write();
    // Do later -- this.put();
    if (logging(log)) {
        log(log, "<< shiftRight: this:  %s", this);
        log(log, "<< shiftRight: left:  %s", left);
        log(log, "<< shiftRight: right: %s", right);
    }
}
Also used : Record(org.apache.jena.dboe.base.record.Record)

Example 64 with Record

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

the class BPTreeNode method split.

/*
     * Split a non-root node y, held at slot idx in its parent,
     * which is 'this'and is large enough for a new entry without
     * another split because we split full blocks on the way down.
     * Do this by splitting the node in two (call to BPTree.split)
     * and inserting the new key/pointer pair.
     * WRITE(y)
     * WRITE(z)
     * WRITE(this)
     */
private void split(AccessPath path, int idx, BPTreePage y) {
    // logging = true;
    if (logging(log)) {
        log(log, "split >> y=%s  this=%s idx=%d", y.getRefStr(), this.getRefStr(), idx);
        log(log, "split --   %s", y);
    }
    internalCheckNode();
    if (BPT.CheckingNode) {
        if (!y.isFull())
            BPT.error("Node is not full");
        if (this.ptrs.get(idx) != y.getId()) {
            int a = this.ptrs.get(idx);
            int b = y.getId();
            BPT.error("Node to be split isn't in right place [%d/%d]", a, b);
        }
    }
    internalCheckNodeDeep();
    // Either-Or
    // promotePage(path, this);
    // promote1(y, this, idx);
    // Includes promote "this" because "this" is in the path.
    promotePage(path, y);
    Record splitKey = y.getSplitKey();
    splitKey = keyRecord(splitKey);
    if (logging(log))
        log(log, "Split key: %s", splitKey);
    BPTreePage z = y.split();
    if (logging(log)) {
        log(log, "Split: %s", y);
        log(log, "Split: %s", z);
    }
    // Key only.
    if (splitKey.hasSeparateValue())
        splitKey = keyRecord(splitKey);
    // Insert new node. "add" shuffle's up as well.
    records.add(idx, splitKey);
    ptrs.add(idx + 1, z.getId());
    count++;
    if (logging(log)) {
        log(log, "split <<   %s", this);
        log(log, "split <<   %s", y);
        log(log, "split <<   %s", z);
    }
    y.write();
    z.write();
    z.release();
    // y.release(); y release management done by caller.
    this.write();
    if (BPT.CheckingNode) {
        if (Record.keyNE(splitKey, y.maxRecord()))
            BPT.error("Split key %d but max subtree %s", splitKey, y.maxRecord());
        internalCheckNodeDeep();
    }
}
Also used : Record(org.apache.jena.dboe.base.record.Record)

Example 65 with Record

use of org.apache.jena.dboe.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));
    // Write and convert to split pairs.
    Iterator<Pair<Integer, Record>> iter2 = Iter.map(iter, rbp -> {
        mgr.put(rbp);
        Record r = rbp.getRecordBuffer().getHigh();
        r = bpt.getRecordFactory().createKeyOnly(r);
        return new Pair<>(rbp.getId(), r);
    });
    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 will 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 : RecordBufferPageMgr(org.apache.jena.dboe.base.recordbuffer.RecordBufferPageMgr) Record(org.apache.jena.dboe.base.record.Record) RecordBufferPage(org.apache.jena.dboe.base.recordbuffer.RecordBufferPage) Pair(org.apache.jena.atlas.lib.Pair)

Aggregations

Record (org.apache.jena.dboe.base.record.Record)71 RecordLib.intToRecord (org.apache.jena.dboe.test.RecordLib.intToRecord)6 Pair (org.apache.jena.atlas.lib.Pair)5 NoSuchElementException (java.util.NoSuchElementException)3 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)3 FileSet (org.apache.jena.dboe.base.file.FileSet)3 RecordBufferPage (org.apache.jena.dboe.base.recordbuffer.RecordBufferPage)3 BPTreeNode (org.apache.jena.dboe.trans.bplustree.BPTreeNode)3 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)3 BPlusTreeParams (org.apache.jena.dboe.trans.bplustree.BPlusTreeParams)3 NodeId (org.apache.jena.tdb2.store.NodeId)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 StorageException (org.apache.jena.dboe.base.StorageException)2 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)2 RecordBuffer (org.apache.jena.dboe.base.buffer.RecordBuffer)2 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)2 Index (org.apache.jena.dboe.index.Index)2 RangeIndex (org.apache.jena.dboe.index.RangeIndex)2 TDBException (org.apache.jena.tdb2.TDBException)2