Search in sources :

Example 1 with AccessStep

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 )"
}
Also used : BlockMgr(org.apache.jena.dboe.base.block.BlockMgr) List(java.util.List) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) AccessStep(org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep) Logger(org.slf4j.Logger) Alg.decodeIndex(org.apache.jena.atlas.lib.Alg.decodeIndex) Optional(java.util.Optional) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) SystemIndex(org.apache.jena.dboe.sys.SystemIndex) FmtLog(org.apache.jena.atlas.logging.FmtLog) String.format(java.lang.String.format) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) Logger(org.slf4j.Logger) AccessStep(org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep)

Example 2 with AccessStep

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;
}
Also used : InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) AccessStep(org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep)

Example 3 with AccessStep

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;
}
Also used : InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) AccessStep(org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep)

Aggregations

InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)3 AccessStep (org.apache.jena.dboe.trans.bplustree.AccessPath.AccessStep)3 String.format (java.lang.String.format)1 List (java.util.List)1 Optional (java.util.Optional)1 Alg.decodeIndex (org.apache.jena.atlas.lib.Alg.decodeIndex)1 FmtLog (org.apache.jena.atlas.logging.FmtLog)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)1 SystemIndex (org.apache.jena.dboe.sys.SystemIndex)1 Logger (org.slf4j.Logger)1