use of org.apache.hyracks.storage.am.btree.api.IBTreeFrame in project asterixdb by apache.
the class BTree method insertInterior.
private void insertInterior(ICachedPage node, int pageId, ITupleReference tuple, BTreeOpContext ctx) throws Exception {
ctx.getInteriorFrame().setPage(node);
int targetTupleIndex = ctx.getInteriorFrame().findInsertTupleIndex(tuple);
FrameOpSpaceStatus spaceStatus = ctx.getInteriorFrame().hasSpaceInsert(tuple);
switch(spaceStatus) {
case INSUFFICIENT_SPACE:
{
int rightPageId = freePageManager.takePage(ctx.getMetaFrame());
ICachedPage rightNode = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, rightPageId), true);
rightNode.acquireWriteLatch();
try {
IBTreeFrame rightFrame = ctx.createInteriorFrame();
rightFrame.setPage(rightNode);
rightFrame.initBuffer(ctx.getInteriorFrame().getLevel());
rightFrame.setMultiComparator(ctx.getCmp());
// instead of creating a new split key, use the existing
// splitKey
ctx.getInteriorFrame().split(rightFrame, ctx.getSplitKey().getTuple(), ctx.getSplitKey(), ctx, bufferCache);
ctx.getSmPages().add(pageId);
ctx.getSmPages().add(rightPageId);
ctx.getInteriorFrame().setSmFlag(true);
rightFrame.setSmFlag(true);
rightFrame.setPageLsn(rightFrame.getPageLsn() + 1);
ctx.getInteriorFrame().setPageLsn(ctx.getInteriorFrame().getPageLsn() + 1);
ctx.getSplitKey().setPages(pageId, rightPageId);
} finally {
rightNode.releaseWriteLatch(true);
bufferCache.unpin(rightNode);
}
break;
}
case SUFFICIENT_CONTIGUOUS_SPACE:
{
ctx.getInteriorFrame().insert(tuple, targetTupleIndex);
ctx.getSplitKey().reset();
break;
}
case SUFFICIENT_SPACE:
{
boolean slotsChanged = ctx.getInteriorFrame().compact();
if (slotsChanged) {
targetTupleIndex = ctx.getInteriorFrame().findInsertTupleIndex(tuple);
}
ctx.getInteriorFrame().insert(tuple, targetTupleIndex);
ctx.getSplitKey().reset();
break;
}
case TOO_LARGE:
{
int tupleSize = ctx.getInteriorFrame().getBytesRequiredToWriteTuple(tuple);
throw HyracksDataException.create(ErrorCode.RECORD_IS_TOO_LARGE, tupleSize, maxTupleSize);
}
default:
{
throw new IllegalStateException("NYI: " + spaceStatus);
}
}
}
Aggregations