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