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);
}
}
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;
}
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;
}
}
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);
}
}
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;
}
Aggregations