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