Search in sources :

Example 46 with ICachedPage

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

the class LinkedMetaDataPageManager method init.

@Override
public void init(ITreeIndexFrameFactory interiorFrameFactory, ITreeIndexFrameFactory leafFrameFactory) throws HyracksDataException {
    // initialize meta data page
    ITreeIndexMetadataFrame metaFrame = createMetadataFrame();
    int metaPage = getMetadataPageId();
    if (metaPage == IBufferCache.INVALID_PAGEID) {
        throw new HyracksDataException("No valid metadata found in this file.");
    }
    ICachedPage metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getMetadataPageId()), true);
    metaNode.acquireWriteLatch();
    try {
        metaFrame.setPage(metaNode);
        metaFrame.init();
        metaFrame.setRootPageId(1);
        metaFrame.setMaxPage(1);
    } finally {
        metaNode.releaseWriteLatch(true);
        bufferCache.flushDirtyPage(metaNode);
        bufferCache.unpin(metaNode);
    }
    int rootPage = getRootPageId();
    ICachedPage rootNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, rootPage), true);
    rootNode.acquireWriteLatch();
    try {
        ITreeIndexFrame leafFrame = leafFrameFactory.createFrame();
        leafFrame.setPage(rootNode);
        leafFrame.initBuffer((byte) 0);
    } finally {
        rootNode.releaseWriteLatch(true);
        bufferCache.flushDirtyPage(rootNode);
        bufferCache.unpin(rootNode);
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) ITreeIndexFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexFrame) ITreeIndexMetadataFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 47 with ICachedPage

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

the class LinkedMetaDataPageManager method getMaxPageId.

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

Example 48 with ICachedPage

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

the class LinkedMetaDataPageManager method setRootPageId.

@Override
public void setRootPageId(int rootPage) throws HyracksDataException {
    ICachedPage metaNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getMetadataPageId()), false);
    ITreeIndexMetadataFrame metaFrame = frameFactory.createFrame();
    metaNode.acquireWriteLatch();
    try {
        metaFrame.setPage(metaNode);
        metaFrame.setRootPageId(rootPage);
    } finally {
        metaNode.releaseWriteLatch(true);
        bufferCache.unpin(metaNode);
        ready = true;
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) ITreeIndexMetadataFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexMetadataFrame)

Example 49 with ICachedPage

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

the class AppendOnlyLinkedMetadataPageManager method get.

@Override
public void get(ITreeIndexMetadataFrame frame, IValueReference key, IPointable value) throws HyracksDataException {
    ICachedPage page = pinPage();
    page.acquireReadLatch();
    try {
        frame.setPage(page);
        frame.get(key, value);
    } finally {
        page.releaseReadLatch();
        unpinPage(page);
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage)

Example 50 with ICachedPage

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

the class AppendOnlyLinkedMetadataPageManager method getFileOffset.

@Override
public long getFileOffset(ITreeIndexMetadataFrame frame, IValueReference key) throws HyracksDataException {
    int pageId = getMetadataPageId();
    if (pageId != IBufferCache.INVALID_PAGEID) {
        ICachedPage page = pinPage();
        page.acquireReadLatch();
        try {
            frame.setPage(page);
            int inPageOffset = frame.getOffset(key);
            return inPageOffset >= 0 ? ((long) pageId * bufferCache.getPageSizeWithHeader()) + frame.getOffset(key) + IBufferCache.RESERVED_HEADER_BYTES : -1L;
        } finally {
            page.releaseReadLatch();
            unpinPage(page);
        }
    }
    return -1L;
}
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