use of org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep in project jena by apache.
the class BPT method promotePage.
/**
* Promote a B+Tree page
*/
static void promotePage(AccessPath path, BPTreePage page) {
Logger pageLog = page.getLogger();
boolean loggingCall = logging(pageLog);
if (loggingCall)
log(pageLog, "Promote :: Path=%s Page=%s", path, page);
// ---- Checking if the access path is consistent.
if (BPT.CheckingNode && path != null) {
if (path.getPath().size() > 2) {
// Check every one except the last is not a leaf node.
List<AccessStep> y = path.getPath().subList(0, path.getPath().size() - 2);
Optional<AccessStep> z = y.stream().filter(e -> e.node.isLeaf()).findFirst();
if (z.isPresent())
error("promote: Leaf %s found in path but not at the tail: %s", z.get(), path);
}
// Check the page/index pointers
Optional<AccessStep> z2 = path.getPath().stream().filter(e -> e.node.ptrs.get(e.idx) != e.page.getId()).findFirst();
if (z2.isPresent())
error("promote: path error: %s in %s", z2.get(), path);
}
// Work from the bottom to the top, the reverse order of AccessPath
if (loggingCall)
log(pageLog, " page>> %s", page.label());
boolean changed = page.promote();
if (loggingCall) {
if (changed)
log(pageLog, " page<< %s", page.label());
else
log(pageLog, " .. no change");
}
if (changed)
// Being careful.
page.write();
// if ( changed ) {
if (path != null) {
// Sequence of promote1 calls? + root.
List<AccessStep> steps = path.getPath();
int newPtr = page.getId();
BPTreePage newPage = null;
boolean previousChanged = changed;
BPTreeNode newRoot = null;
if (logging(pageLog))
log(pageLog, "Path: %s", path);
// Duplicate from bottom to top.
for (int i = steps.size() - 1; i >= 0; i--) {
AccessStep s = steps.get(i);
// duplicate
BPTreeNode n = s.node;
if (logging(pageLog))
log(pageLog, " >> %s", n);
changed = n.promote();
if (previousChanged) {
// Even if n did not change, if it's sub changed, need to update s.idx.
n.ptrs.set(s.idx, newPtr);
} else {
if (!changed) {
if (logging(pageLog))
log(pageLog, " .. no change");
continue;
}
}
previousChanged = changed;
if (logging(pageLog))
log(pageLog, " << %s", n);
if (n.isRoot()) {
if (newRoot != null)
throw new InternalErrorException("New root already found");
newRoot = n;
}
newPtr = n.getId();
n.write();
}
if (newRoot != null) {
if (loggingCall)
log(pageLog, " new root %s", newRoot);
page.bpTree.newRoot(newRoot);
}
}
// end of "if ( path != null )"
}
use of org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep in project jena by apache.
the class BPTreeRangeIteratorMapper method loadStack.
private BPTreeRecords loadStack(BPTreeNode node) {
AccessPath path = new AccessPath(null);
node.bpTree.startReadBlkMgr();
if (minRecord == null)
node.internalMinRecord(path);
else
node.internalSearch(path, minRecord);
List<AccessStep> steps = path.getPath();
for (AccessStep step : steps) {
BPTreeNode n = step.node;
Iterator<BPTreePage> it = n.iterator(minRecord, maxRecord);
if (it == null || !it.hasNext())
continue;
BPTreePage p = it.next();
stack.push(it);
}
BPTreePage p = steps.get(steps.size() - 1).page;
if (!(p instanceof BPTreeRecords))
throw new InternalErrorException("Last path step not to a records block");
node.bpTree.finishReadBlkMgr();
return (BPTreeRecords) p;
}
use of org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep in project jena by apache.
the class BPTreeRangeIterator method loadStack.
private BPTreeRecords loadStack(BPTreeNode node) {
AccessPath path = new AccessPath(null);
node.bpTree.startReadBlkMgr();
if (minRecord == null)
node.internalMinRecord(path);
else
node.internalSearch(path, minRecord);
List<AccessStep> steps = path.getPath();
for (AccessStep step : steps) {
BPTreeNode n = step.node;
Iterator<BPTreePage> it = n.iterator(minRecord, maxRecord);
if (it == null || !it.hasNext())
continue;
BPTreePage p = it.next();
stack.push(it);
}
BPTreePage p = steps.get(steps.size() - 1).page;
if (!(p instanceof BPTreeRecords))
throw new InternalErrorException("Last path step not to a records block");
node.bpTree.finishReadBlkMgr();
return (BPTreeRecords) p;
}
Aggregations