use of org.apache.hyracks.storage.common.buffercache.ICachedPage in project asterixdb by apache.
the class BTree method isConsistent.
private ICachedPage isConsistent(int pageId, BTreeOpContext ctx) throws Exception {
ICachedPage node = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
node.acquireReadLatch();
ctx.getInteriorFrame().setPage(node);
boolean isConsistent = ctx.getPageLsns().getLast() == ctx.getInteriorFrame().getPageLsn();
if (!isConsistent) {
node.releaseReadLatch();
bufferCache.unpin(node);
return null;
}
return node;
}
use of org.apache.hyracks.storage.common.buffercache.ICachedPage in project asterixdb by apache.
the class BTree method unsetSmPages.
private void unsetSmPages(BTreeOpContext ctx) throws HyracksDataException {
ICachedPage originalPage = ctx.getInteriorFrame().getPage();
for (int i = 0; i < ctx.getSmPages().size(); i++) {
int pageId = ctx.getSmPages().get(i);
ICachedPage smPage = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
smPage.acquireWriteLatch();
try {
ctx.getInteriorFrame().setPage(smPage);
ctx.getInteriorFrame().setSmFlag(false);
} finally {
smPage.releaseWriteLatch(true);
bufferCache.unpin(smPage);
}
}
if (ctx.getSmPages().size() > 0) {
if (ctx.getSmoCount() == Integer.MAX_VALUE) {
smoCounter.set(0);
} else {
smoCounter.incrementAndGet();
}
treeLatch.writeLock().unlock();
ctx.getSmPages().clear();
}
ctx.getInteriorFrame().setPage(originalPage);
}
use of org.apache.hyracks.storage.common.buffercache.ICachedPage in project asterixdb by apache.
the class BTree method printTree.
@SuppressWarnings("rawtypes")
public void printTree(int pageId, ICachedPage parent, boolean unpin, IBTreeLeafFrame leafFrame, IBTreeInteriorFrame interiorFrame, byte treeHeight, ISerializerDeserializer[] keySerdes, StringBuilder strBuilder, MultiComparator cmp) throws Exception {
ICachedPage node = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
node.acquireReadLatch();
try {
if (parent != null && unpin == true) {
parent.releaseReadLatch();
bufferCache.unpin(parent);
}
interiorFrame.setPage(node);
int level = interiorFrame.getLevel();
strBuilder.append(String.format("%1d ", level));
strBuilder.append(String.format("%3d ", pageId) + ": ");
for (int i = 0; i < treeHeight - level; i++) {
strBuilder.append(" ");
}
String keyString;
if (interiorFrame.isLeaf()) {
leafFrame.setPage(node);
keyString = printLeafFrameTuples(leafFrame, keySerdes);
} else {
keyString = printInteriorFrameTuples(interiorFrame, keySerdes);
}
strBuilder.append(keyString + "\n");
if (!interiorFrame.isLeaf()) {
ArrayList<Integer> children = ((BTreeNSMInteriorFrame) (interiorFrame)).getChildren(cmp);
for (int i = 0; i < children.size(); i++) {
printTree(children.get(i), node, i == children.size() - 1, leafFrame, interiorFrame, treeHeight, keySerdes, strBuilder, cmp);
}
} else {
node.releaseReadLatch();
bufferCache.unpin(node);
}
} catch (Exception e) {
node.releaseReadLatch();
bufferCache.unpin(node);
}
}
use of org.apache.hyracks.storage.common.buffercache.ICachedPage in project asterixdb by apache.
the class BTreeRangeSearchCursor method fetchNextLeafPage.
private void fetchNextLeafPage(int nextLeafPage) throws HyracksDataException {
do {
ICachedPage nextLeaf = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, nextLeafPage), false);
if (exclusiveLatchNodes) {
nextLeaf.acquireWriteLatch();
page.releaseWriteLatch(isPageDirty);
} else {
nextLeaf.acquireReadLatch();
page.releaseReadLatch();
}
bufferCache.unpin(page);
page = nextLeaf;
isPageDirty = false;
frame.setPage(page);
pageId = nextLeafPage;
nextLeafPage = frame.getNextLeaf();
} while (frame.getTupleCount() == 0 && nextLeafPage > 0);
}
use of org.apache.hyracks.storage.common.buffercache.ICachedPage in project asterixdb by apache.
the class BTree method performLeafSplit.
private boolean performLeafSplit(int pageId, ITupleReference tuple, BTreeOpContext ctx, int updateTupleIndex) throws Exception {
// Lock is released in unsetSmPages(), after sm has fully completed.
if (!treeLatch.writeLock().tryLock()) {
return true;
} else {
int tempSmoCount = smoCounter.get();
if (tempSmoCount != ctx.getSmoCount()) {
treeLatch.writeLock().unlock();
return true;
}
}
int rightPageId = freePageManager.takePage(ctx.getMetaFrame());
ICachedPage rightNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, rightPageId), true);
rightNode.acquireWriteLatch();
try {
IBTreeLeafFrame rightFrame = ctx.createLeafFrame();
rightFrame.setPage(rightNode);
rightFrame.initBuffer((byte) 0);
rightFrame.setMultiComparator(ctx.getCmp());
// Perform an update (delete + insert) if the updateTupleIndex != -1
if (updateTupleIndex != -1) {
ITupleReference beforeTuple = ctx.getLeafFrame().getMatchingKeyTuple(tuple, updateTupleIndex);
ctx.getModificationCallback().found(beforeTuple, tuple);
ctx.getLeafFrame().delete(tuple, updateTupleIndex);
} else {
ctx.getModificationCallback().found(null, tuple);
}
ctx.getLeafFrame().split(rightFrame, tuple, ctx.getSplitKey(), ctx, bufferCache);
ctx.getSmPages().add(pageId);
ctx.getSmPages().add(rightPageId);
ctx.getLeafFrame().setSmFlag(true);
rightFrame.setSmFlag(true);
rightFrame.setNextLeaf(ctx.getLeafFrame().getNextLeaf());
ctx.getLeafFrame().setNextLeaf(rightPageId);
rightFrame.setPageLsn(rightFrame.getPageLsn() + 1);
ctx.getLeafFrame().setPageLsn(ctx.getLeafFrame().getPageLsn() + 1);
ctx.getSplitKey().setPages(pageId, rightPageId);
} catch (Exception e) {
treeLatch.writeLock().unlock();
throw e;
} finally {
rightNode.releaseWriteLatch(true);
bufferCache.unpin(rightNode);
}
return false;
}
Aggregations