Search in sources :

Example 11 with ICachedPage

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

the class AppendOnlyLinkedMetadataPageManager method open.

@Override
public void open(int fileId) throws HyracksDataException {
    this.fileId = fileId;
    // get the number of pages of the file
    int pages = bufferCache.getNumPagesOfFile(fileId);
    //if there are no pages in the file yet, we're just initializing
    if (pages == 0) {
        if (confiscatedPage != null) {
            throw new HyracksDataException("Metadata Page Manager is already initialized");
        }
        ITreeIndexMetadataFrame metaFrame = createMetadataFrame();
        ICachedPage metaNode = bufferCache.confiscatePage(BufferCache.INVALID_DPID);
        try {
            metaFrame.setPage(metaNode);
            metaFrame.init();
            metaFrame.setMaxPage(-1);
        } finally {
            confiscatedPage = metaNode;
        }
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) ITreeIndexMetadataFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 12 with ICachedPage

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

the class AppendOnlyLinkedMetadataPageManager method getMaxPageId.

@Override
public int getMaxPageId(ITreeIndexMetadataFrame metaFrame) throws HyracksDataException {
    ICachedPage metaNode;
    if (confiscatedPage == null) {
        int mdPage = getMetadataPageId();
        if (mdPage < 0) {
            return IBufferCache.INVALID_PAGEID;
        }
        metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, mdPage), false);
    } else {
        metaNode = confiscatedPage;
    }
    metaNode.acquireReadLatch();
    int maxPage = -1;
    try {
        metaFrame.setPage(metaNode);
        maxPage = metaFrame.getMaxPage();
    } finally {
        metaNode.releaseReadLatch();
        if (confiscatedPage == null) {
            bufferCache.unpin(metaNode);
        }
    }
    return maxPage;
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage)

Example 13 with ICachedPage

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

the class AppendOnlyLinkedMetadataPageManager method takePage.

@Override
public int takePage(ITreeIndexMetadataFrame metaFrame) throws HyracksDataException {
    confiscatedPage.acquireWriteLatch();
    int freePage = IBufferCache.INVALID_PAGEID;
    try {
        metaFrame.setPage(confiscatedPage);
        freePage = metaFrame.getFreePage();
        if (freePage < 0) {
            // no free page entry on this page
            int nextPage = metaFrame.getNextMetadataPage();
            if (nextPage > 0) {
                // sibling may have free pages
                ICachedPage nextNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, nextPage), false);
                nextNode.acquireWriteLatch();
                // of nextpage
                try {
                    // remember entries that remain unchanged
                    int maxPage = metaFrame.getMaxPage();
                    // copy entire page (including sibling pointer, free
                    // page entries, and all other info)
                    // after this copy nextPage is considered a free page
                    System.arraycopy(nextNode.getBuffer().array(), 0, confiscatedPage.getBuffer().array(), 0, nextNode.getBuffer().capacity());
                    // reset unchanged entry
                    metaFrame.setMaxPage(maxPage);
                    freePage = metaFrame.getFreePage();
                    // happen, but we deal with it anyway just to be safe
                    if (freePage < 0) {
                        freePage = nextPage;
                    } else {
                        metaFrame.addFreePage(nextPage);
                    }
                } finally {
                    nextNode.releaseWriteLatch(true);
                    bufferCache.unpin(nextNode);
                }
            } else {
                freePage = metaFrame.getMaxPage();
                freePage++;
                metaFrame.setMaxPage(freePage);
            }
        }
    } finally {
        confiscatedPage.releaseWriteLatch(false);
    }
    return freePage;
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage)

Example 14 with ICachedPage

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

the class LinkedMetaDataPageManager method isEmpty.

@Override
public boolean isEmpty(ITreeIndexFrame frame, int rootPage) throws HyracksDataException {
    ICachedPage rootNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, rootPage), false);
    rootNode.acquireReadLatch();
    try {
        frame.setPage(rootNode);
        return frame.getLevel() == 0 && frame.getTupleCount() == 0;
    } finally {
        rootNode.releaseReadLatch();
        bufferCache.unpin(rootNode);
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage)

Example 15 with ICachedPage

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

the class AbstractTreeIndex method getTreeHeight.

public byte getTreeHeight(ITreeIndexFrame frame) throws HyracksDataException {
    ICachedPage rootNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, rootPage), false);
    rootNode.acquireReadLatch();
    try {
        frame.setPage(rootNode);
        return frame.getLevel();
    } finally {
        rootNode.releaseReadLatch();
        bufferCache.unpin(rootNode);
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage)

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