Search in sources :

Example 1 with BTreeNSMInteriorFrame

use of org.apache.hyracks.storage.am.btree.frames.BTreeNSMInteriorFrame in project asterixdb by apache.

the class BTree method validate.

private void validate(BTreeOpContext ctx, int pageId) throws HyracksDataException {
    ICachedPage page = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
    ctx.getInteriorFrame().setPage(page);
    PageValidationInfo currentPvi = ctx.getValidationInfos().peekFirst();
    boolean isLeaf = ctx.getInteriorFrame().isLeaf();
    if (isLeaf) {
        ctx.getLeafFrame().setPage(page);
        ctx.getLeafFrame().validate(currentPvi);
    } else {
        PageValidationInfo nextPvi = ctx.createPageValidationInfo(currentPvi);
        List<Integer> children = ((BTreeNSMInteriorFrame) ctx.getInteriorFrame()).getChildren(ctx.getCmp());
        ctx.getInteriorFrame().validate(currentPvi);
        for (int i = 0; i < children.size(); i++) {
            ctx.getInteriorFrame().setPage(page);
            if (children.size() == 1) {
                // There is a single child pointer with no keys, so propagate both low and high ranges
                nextPvi.propagateLowRangeKey(currentPvi);
                nextPvi.propagateHighRangeKey(currentPvi);
            } else if (i == 0) {
                // There is more than one child pointer and this is the left-most child pointer, so:
                //      1) propagate the low range key from the parent
                //      2) adjust the high range key
                nextPvi.propagateLowRangeKey(currentPvi);
                ctx.getInteriorFrameTuple().resetByTupleIndex(ctx.getInteriorFrame(), i);
                nextPvi.adjustHighRangeKey(ctx.getInteriorFrameTuple());
            } else if (i == children.size() - 1) {
                // There is more than one child pointer and this is the right-most child pointer, so:
                //      1) propagate the high range key from the parent
                //      2) adjust the low range key
                nextPvi.propagateHighRangeKey(currentPvi);
                ctx.getInteriorFrameTuple().resetByTupleIndex(ctx.getInteriorFrame(), i - 1);
                nextPvi.adjustLowRangeKey(ctx.getInteriorFrameTuple());
            } else {
                // There is more than one child pointer and this pointer is not the left/right-most pointer, so:
                //      1) adjust the low range key
                //      2) adjust the high range key
                ctx.getInteriorFrameTuple().resetByTupleIndex(ctx.getInteriorFrame(), i - 1);
                nextPvi.adjustLowRangeKey(ctx.getInteriorFrameTuple());
                ctx.getInteriorFrameTuple().resetByTupleIndex(ctx.getInteriorFrame(), i);
                nextPvi.adjustHighRangeKey(ctx.getInteriorFrameTuple());
            }
            ctx.getValidationInfos().addFirst(nextPvi);
            validate(ctx, children.get(i));
        }
    }
    bufferCache.unpin(page);
    ctx.getValidationInfos().removeFirst();
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BTreeNSMInteriorFrame(org.apache.hyracks.storage.am.btree.frames.BTreeNSMInteriorFrame) PageValidationInfo(org.apache.hyracks.storage.am.btree.impls.BTreeOpContext.PageValidationInfo)

Example 2 with BTreeNSMInteriorFrame

use of org.apache.hyracks.storage.am.btree.frames.BTreeNSMInteriorFrame in project asterixdb by apache.

the class BTree method printTree.

@SuppressWarnings("rawtypes")
public void printTree(int pageId, ICachedPage parent, boolean unpin, IBTreeLeafFrame leafFrame, IBTreeInteriorFrame interiorFrame, byte treeHeight, ISerializerDeserializer[] keySerdes, StringBuilder strBuilder, MultiComparator cmp) throws Exception {
    ICachedPage node = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
    node.acquireReadLatch();
    try {
        if (parent != null && unpin == true) {
            parent.releaseReadLatch();
            bufferCache.unpin(parent);
        }
        interiorFrame.setPage(node);
        int level = interiorFrame.getLevel();
        strBuilder.append(String.format("%1d ", level));
        strBuilder.append(String.format("%3d ", pageId) + ": ");
        for (int i = 0; i < treeHeight - level; i++) {
            strBuilder.append("    ");
        }
        String keyString;
        if (interiorFrame.isLeaf()) {
            leafFrame.setPage(node);
            keyString = printLeafFrameTuples(leafFrame, keySerdes);
        } else {
            keyString = printInteriorFrameTuples(interiorFrame, keySerdes);
        }
        strBuilder.append(keyString + "\n");
        if (!interiorFrame.isLeaf()) {
            ArrayList<Integer> children = ((BTreeNSMInteriorFrame) (interiorFrame)).getChildren(cmp);
            for (int i = 0; i < children.size(); i++) {
                printTree(children.get(i), node, i == children.size() - 1, leafFrame, interiorFrame, treeHeight, keySerdes, strBuilder, cmp);
            }
        } else {
            node.releaseReadLatch();
            bufferCache.unpin(node);
        }
    } catch (Exception e) {
        node.releaseReadLatch();
        bufferCache.unpin(node);
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BTreeNSMInteriorFrame(org.apache.hyracks.storage.am.btree.frames.BTreeNSMInteriorFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 BTreeNSMInteriorFrame (org.apache.hyracks.storage.am.btree.frames.BTreeNSMInteriorFrame)2 ICachedPage (org.apache.hyracks.storage.common.buffercache.ICachedPage)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 PageValidationInfo (org.apache.hyracks.storage.am.btree.impls.BTreeOpContext.PageValidationInfo)1