Search in sources :

Example 51 with ICachedPage

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

the class AppendOnlyLinkedMetadataPageManager method releasePage.

@Override
public void releasePage(ITreeIndexMetadataFrame metaFrame, int freePageNum) throws HyracksDataException {
    ICachedPage metaPage = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, getMetadataPageId()), false);
    metaPage.acquireWriteLatch();
    try {
        metaFrame.setPage(metaPage);
        if (metaFrame.getSpace() > Integer.BYTES) {
            metaFrame.addFreePage(freePageNum);
        } else {
            int newPageNum = metaFrame.getFreePage();
            if (newPageNum < 0) {
                throw new HyracksDataException("Inconsistent Meta Page State. It has no space, but it also has no entries.");
            }
            ICachedPage newNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, newPageNum), false);
            newNode.acquireWriteLatch();
            try {
                int metaMaxPage = metaFrame.getMaxPage();
                System.arraycopy(metaPage.getBuffer().array(), 0, newNode.getBuffer().array(), 0, metaPage.getBuffer().capacity());
                metaFrame.init();
                metaFrame.setNextMetadataPage(newPageNum);
                metaFrame.setMaxPage(metaMaxPage);
                metaFrame.addFreePage(freePageNum);
            } finally {
                newNode.releaseWriteLatch(true);
                bufferCache.unpin(newNode);
            }
        }
    } finally {
        metaPage.releaseWriteLatch(true);
        bufferCache.unpin(metaPage);
    }
}
Also used : ICachedPage(org.apache.hyracks.storage.common.buffercache.ICachedPage) 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