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;
}
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;
}
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);
}
}
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();
}
}
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;
}
Aggregations