Search in sources :

Example 21 with ICachedPage

use of org.apache.hyracks.storage.common.buffercache.ICachedPage in project asterixdb by apache.

the class BTree method isConsistent.

private ICachedPage isConsistent(int pageId, BTreeOpContext ctx) throws Exception {
    ICachedPage node = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
    node.acquireReadLatch();
    ctx.getInteriorFrame().setPage(node);
    boolean isConsistent = ctx.getPageLsns().getLast() == ctx.getInteriorFrame().getPageLsn();
    if (!isConsistent) {
        node.releaseReadLatch();
        bufferCache.unpin(node);
        return null;
    }
    return node;
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage)

Example 22 with ICachedPage

use of org.apache.hyracks.storage.common.buffercache.ICachedPage in project asterixdb by apache.

the class BTree method unsetSmPages.

private void unsetSmPages(BTreeOpContext ctx) throws HyracksDataException {
    ICachedPage originalPage = ctx.getInteriorFrame().getPage();
    for (int i = 0; i < ctx.getSmPages().size(); i++) {
        int pageId = ctx.getSmPages().get(i);
        ICachedPage smPage = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
        smPage.acquireWriteLatch();
        try {
            ctx.getInteriorFrame().setPage(smPage);
            ctx.getInteriorFrame().setSmFlag(false);
        } finally {
            smPage.releaseWriteLatch(true);
            bufferCache.unpin(smPage);
        }
    }
    if (ctx.getSmPages().size() > 0) {
        if (ctx.getSmoCount() == Integer.MAX_VALUE) {
            smoCounter.set(0);
        } else {
            smoCounter.incrementAndGet();
        }
        treeLatch.writeLock().unlock();
        ctx.getSmPages().clear();
    }
    ctx.getInteriorFrame().setPage(originalPage);
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage)

Example 23 with ICachedPage

use of org.apache.hyracks.storage.common.buffercache.ICachedPage 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)

Example 24 with ICachedPage

use of org.apache.hyracks.storage.common.buffercache.ICachedPage in project asterixdb by apache.

the class BTreeRangeSearchCursor method fetchNextLeafPage.

private void fetchNextLeafPage(int nextLeafPage) throws HyracksDataException {
    do {
        ICachedPage nextLeaf = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, nextLeafPage), false);
        if (exclusiveLatchNodes) {
            nextLeaf.acquireWriteLatch();
            page.releaseWriteLatch(isPageDirty);
        } else {
            nextLeaf.acquireReadLatch();
            page.releaseReadLatch();
        }
        bufferCache.unpin(page);
        page = nextLeaf;
        isPageDirty = false;
        frame.setPage(page);
        pageId = nextLeafPage;
        nextLeafPage = frame.getNextLeaf();
    } while (frame.getTupleCount() == 0 && nextLeafPage > 0);
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage)

Example 25 with ICachedPage

use of org.apache.hyracks.storage.common.buffercache.ICachedPage in project asterixdb by apache.

the class BTree method performLeafSplit.

private boolean performLeafSplit(int pageId, ITupleReference tuple, BTreeOpContext ctx, int updateTupleIndex) throws Exception {
    // Lock is released in unsetSmPages(), after sm has fully completed.
    if (!treeLatch.writeLock().tryLock()) {
        return true;
    } else {
        int tempSmoCount = smoCounter.get();
        if (tempSmoCount != ctx.getSmoCount()) {
            treeLatch.writeLock().unlock();
            return true;
        }
    }
    int rightPageId = freePageManager.takePage(ctx.getMetaFrame());
    ICachedPage rightNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, rightPageId), true);
    rightNode.acquireWriteLatch();
    try {
        IBTreeLeafFrame rightFrame = ctx.createLeafFrame();
        rightFrame.setPage(rightNode);
        rightFrame.initBuffer((byte) 0);
        rightFrame.setMultiComparator(ctx.getCmp());
        // Perform an update (delete + insert) if the updateTupleIndex != -1
        if (updateTupleIndex != -1) {
            ITupleReference beforeTuple = ctx.getLeafFrame().getMatchingKeyTuple(tuple, updateTupleIndex);
            ctx.getModificationCallback().found(beforeTuple, tuple);
            ctx.getLeafFrame().delete(tuple, updateTupleIndex);
        } else {
            ctx.getModificationCallback().found(null, tuple);
        }
        ctx.getLeafFrame().split(rightFrame, tuple, ctx.getSplitKey(), ctx, bufferCache);
        ctx.getSmPages().add(pageId);
        ctx.getSmPages().add(rightPageId);
        ctx.getLeafFrame().setSmFlag(true);
        rightFrame.setSmFlag(true);
        rightFrame.setNextLeaf(ctx.getLeafFrame().getNextLeaf());
        ctx.getLeafFrame().setNextLeaf(rightPageId);
        rightFrame.setPageLsn(rightFrame.getPageLsn() + 1);
        ctx.getLeafFrame().setPageLsn(ctx.getLeafFrame().getPageLsn() + 1);
        ctx.getSplitKey().setPages(pageId, rightPageId);
    } catch (Exception e) {
        treeLatch.writeLock().unlock();
        throw e;
    } finally {
        rightNode.releaseWriteLatch(true);
        bufferCache.unpin(rightNode);
    }
    return false;
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) IBTreeLeafFrame(org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

ICachedPage (org.apache.hyracks.storage.common.buffercache.ICachedPage)51 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)13 ITreeIndexMetadataFrame (org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame)7 IBufferCache (org.apache.hyracks.storage.common.buffercache.IBufferCache)5 IFileMapProvider (org.apache.hyracks.storage.common.file.IFileMapProvider)4 FileReference (org.apache.hyracks.api.io.FileReference)3 Test (org.junit.Test)3 ByteBuffer (java.nio.ByteBuffer)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IIOManager (org.apache.hyracks.api.io.IIOManager)2 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)2 BTreeNSMInteriorFrame (org.apache.hyracks.storage.am.btree.frames.BTreeNSMInteriorFrame)2 ITreeIndexFrame (org.apache.hyracks.storage.am.common.api.ITreeIndexFrame)2 FrameOpSpaceStatus (org.apache.hyracks.storage.am.common.frames.FrameOpSpaceStatus)2 TreeIndexDiskOrderScanCursor (org.apache.hyracks.storage.am.common.impls.TreeIndexDiskOrderScanCursor)2 MultiComparator (org.apache.hyracks.storage.common.MultiComparator)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)1