use of org.apache.hyracks.storage.am.btree.impls.BTreeOpContext.PageValidationInfo in project asterixdb by apache.
the class BTree method validate.
private void validate(BTreeOpContext ctx, int pageId) throws HyracksDataException {
ICachedPage page = bufferCache.pin(BufferedFileHandle.getDiskPageId(fileId, pageId), false);
ctx.getInteriorFrame().setPage(page);
PageValidationInfo currentPvi = ctx.getValidationInfos().peekFirst();
boolean isLeaf = ctx.getInteriorFrame().isLeaf();
if (isLeaf) {
ctx.getLeafFrame().setPage(page);
ctx.getLeafFrame().validate(currentPvi);
} else {
PageValidationInfo nextPvi = ctx.createPageValidationInfo(currentPvi);
List<Integer> children = ((BTreeNSMInteriorFrame) ctx.getInteriorFrame()).getChildren(ctx.getCmp());
ctx.getInteriorFrame().validate(currentPvi);
for (int i = 0; i < children.size(); i++) {
ctx.getInteriorFrame().setPage(page);
if (children.size() == 1) {
// There is a single child pointer with no keys, so propagate both low and high ranges
nextPvi.propagateLowRangeKey(currentPvi);
nextPvi.propagateHighRangeKey(currentPvi);
} else if (i == 0) {
// There is more than one child pointer and this is the left-most child pointer, so:
// 1) propagate the low range key from the parent
// 2) adjust the high range key
nextPvi.propagateLowRangeKey(currentPvi);
ctx.getInteriorFrameTuple().resetByTupleIndex(ctx.getInteriorFrame(), i);
nextPvi.adjustHighRangeKey(ctx.getInteriorFrameTuple());
} else if (i == children.size() - 1) {
// There is more than one child pointer and this is the right-most child pointer, so:
// 1) propagate the high range key from the parent
// 2) adjust the low range key
nextPvi.propagateHighRangeKey(currentPvi);
ctx.getInteriorFrameTuple().resetByTupleIndex(ctx.getInteriorFrame(), i - 1);
nextPvi.adjustLowRangeKey(ctx.getInteriorFrameTuple());
} else {
// There is more than one child pointer and this pointer is not the left/right-most pointer, so:
// 1) adjust the low range key
// 2) adjust the high range key
ctx.getInteriorFrameTuple().resetByTupleIndex(ctx.getInteriorFrame(), i - 1);
nextPvi.adjustLowRangeKey(ctx.getInteriorFrameTuple());
ctx.getInteriorFrameTuple().resetByTupleIndex(ctx.getInteriorFrame(), i);
nextPvi.adjustHighRangeKey(ctx.getInteriorFrameTuple());
}
ctx.getValidationInfos().addFirst(nextPvi);
validate(ctx, children.get(i));
}
}
bufferCache.unpin(page);
ctx.getValidationInfos().removeFirst();
}
use of org.apache.hyracks.storage.am.btree.impls.BTreeOpContext.PageValidationInfo in project asterixdb by apache.
the class BTree method validate.
@Override
public void validate() throws HyracksDataException {
// Stack validation protocol:
// * parent pushes the validation information onto the stack before validation
// * child pops the validation information off of the stack after validating
BTreeAccessor accessor = (BTreeAccessor) createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
PageValidationInfo pvi = accessor.ctx.createPageValidationInfo(null);
accessor.ctx.getValidationInfos().addFirst(pvi);
if (isActive) {
validate(accessor.ctx, rootPage);
}
}
Aggregations