use of org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame in project asterixdb by apache.
the class LSMRTreeWithAntiMatterTuplesSearchCursor method open.
@Override
public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
LSMRTreeCursorInitialState lsmInitialState = (LSMRTreeCursorInitialState) initialState;
cmp = lsmInitialState.getHilbertCmp();
btreeCmp = lsmInitialState.getBTreeCmp();
lsmHarness = lsmInitialState.getLSMHarness();
comparatorFields = lsmInitialState.getComparatorFields();
operationalComponents = lsmInitialState.getOperationalComponents();
rtreeSearchPredicate = (SearchPredicate) searchPred;
searchCallback = lsmInitialState.getSearchOperationCallback();
includeMutableComponent = false;
numMutableComponents = 0;
int numImmutableComponents = 0;
for (ILSMComponent component : operationalComponents) {
if (component.getType() == LSMComponentType.MEMORY) {
includeMutableComponent = true;
numMutableComponents++;
} else {
numImmutableComponents++;
}
}
if (includeMutableComponent) {
btreeRangePredicate = new RangePredicate(null, null, true, true, btreeCmp, btreeCmp);
}
mutableRTreeCursors = new RTreeSearchCursor[numMutableComponents];
mutableRTreeAccessors = new ITreeIndexAccessor[numMutableComponents];
btreeCursors = new BTreeRangeSearchCursor[numMutableComponents];
btreeAccessors = new ITreeIndexAccessor[numMutableComponents];
for (int i = 0; i < numMutableComponents; i++) {
ILSMComponent component = operationalComponents.get(i);
RTree rtree = ((LSMRTreeMemoryComponent) component).getRTree();
BTree btree = ((LSMRTreeMemoryComponent) component).getBTree();
mutableRTreeCursors[i] = new RTreeSearchCursor((IRTreeInteriorFrame) lsmInitialState.getRTreeInteriorFrameFactory().createFrame(), (IRTreeLeafFrame) lsmInitialState.getRTreeLeafFrameFactory().createFrame());
btreeCursors[i] = new BTreeRangeSearchCursor((IBTreeLeafFrame) lsmInitialState.getBTreeLeafFrameFactory().createFrame(), false);
btreeAccessors[i] = btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
mutableRTreeAccessors[i] = rtree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
}
rangeCursors = new RTreeSearchCursor[numImmutableComponents];
ITreeIndexAccessor[] immutableRTreeAccessors = new ITreeIndexAccessor[numImmutableComponents];
int j = 0;
for (int i = numMutableComponents; i < operationalComponents.size(); i++) {
ILSMComponent component = operationalComponents.get(i);
rangeCursors[j] = new RTreeSearchCursor((IRTreeInteriorFrame) lsmInitialState.getRTreeInteriorFrameFactory().createFrame(), (IRTreeLeafFrame) lsmInitialState.getRTreeLeafFrameFactory().createFrame());
RTree rtree = ((LSMRTreeDiskComponent) component).getRTree();
immutableRTreeAccessors[j] = rtree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
immutableRTreeAccessors[j].search(rangeCursors[j], searchPred);
j++;
}
searchNextCursor();
setPriorityQueueComparator();
initPriorityQueue();
open = true;
}
use of org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame in project asterixdb by apache.
the class LSMRTreeAbstractCursor method open.
@Override
public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
LSMRTreeCursorInitialState lsmInitialState = (LSMRTreeCursorInitialState) initialState;
if (btreeCmp == null) {
btreeCmp = lsmInitialState.getBTreeCmp();
btreeRangePredicate.setLowKeyCmp(btreeCmp);
btreeRangePredicate.setHighKeyCmp(btreeCmp);
}
operationalComponents = lsmInitialState.getOperationalComponents();
lsmHarness = lsmInitialState.getLSMHarness();
numberOfTrees = operationalComponents.size();
int numComponenets = operationalComponents.size();
if (rtreeCursors == null || rtreeCursors.length != numComponenets) {
// object creation: should be relatively low
rtreeCursors = new RTreeSearchCursor[numberOfTrees];
btreeCursors = new BTreeRangeSearchCursor[numberOfTrees];
rtreeAccessors = new RTreeAccessor[numberOfTrees];
btreeAccessors = new BTreeAccessor[numberOfTrees];
}
includeMutableComponent = false;
for (int i = 0; i < numberOfTrees; i++) {
ILSMComponent component = operationalComponents.get(i);
RTree rtree;
BTree btree;
if (component.getType() == LSMComponentType.MEMORY) {
includeMutableComponent = true;
// No need for a bloom filter for the in-memory BTree.
if (btreeCursors[i] == null || btreeCursors[i].isBloomFilterAware()) {
//create
btreeCursors[i] = new BTreeRangeSearchCursor((IBTreeLeafFrame) lsmInitialState.getBTreeLeafFrameFactory().createFrame(), false);
} else {
//re-use
btreeCursors[i].reset();
}
rtree = ((LSMRTreeMemoryComponent) component).getRTree();
btree = ((LSMRTreeMemoryComponent) component).getBTree();
} else {
if (btreeCursors[i] == null || !btreeCursors[i].isBloomFilterAware()) {
// need to create a new one
btreeCursors[i] = new BloomFilterAwareBTreePointSearchCursor((IBTreeLeafFrame) lsmInitialState.getBTreeLeafFrameFactory().createFrame(), false, ((LSMRTreeDiskComponent) operationalComponents.get(i)).getBloomFilter());
} else {
// reset
((BloomFilterAwareBTreePointSearchCursor) btreeCursors[i]).resetBloomFilter(((LSMRTreeDiskComponent) operationalComponents.get(i)).getBloomFilter());
btreeCursors[i].reset();
}
rtree = ((LSMRTreeDiskComponent) component).getRTree();
btree = ((LSMRTreeDiskComponent) component).getBTree();
}
if (rtreeCursors[i] == null) {
rtreeCursors[i] = new RTreeSearchCursor((IRTreeInteriorFrame) lsmInitialState.getRTreeInteriorFrameFactory().createFrame(), (IRTreeLeafFrame) lsmInitialState.getRTreeLeafFrameFactory().createFrame());
} else {
rtreeCursors[i].reset();
}
if (rtreeAccessors[i] == null) {
rtreeAccessors[i] = (RTreeAccessor) rtree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
btreeAccessors[i] = (BTreeAccessor) btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
} else {
rtreeAccessors[i].reset(rtree, NoOpOperationCallback.INSTANCE);
btreeAccessors[i].reset(btree, NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
}
}
rtreeSearchPredicate = (SearchPredicate) searchPred;
btreeRangePredicate.setHighKey(null);
btreeRangePredicate.setLowKey(null);
open = true;
}
use of org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame in project asterixdb by apache.
the class LSMInvertedIndexRangeSearchCursor method open.
@Override
public void open(ICursorInitialState initState, ISearchPredicate searchPred) throws HyracksDataException {
LSMInvertedIndexRangeSearchCursorInitialState lsmInitState = (LSMInvertedIndexRangeSearchCursorInitialState) initState;
cmp = lsmInitState.getOriginalKeyComparator();
int numComponents = lsmInitState.getNumComponents();
rangeCursors = new IIndexCursor[numComponents];
for (int i = 0; i < numComponents; i++) {
IInvertedIndexAccessor invIndexAccessor = (IInvertedIndexAccessor) lsmInitState.getIndexAccessors().get(i);
rangeCursors[i] = invIndexAccessor.createRangeSearchCursor();
invIndexAccessor.rangeSearch(rangeCursors[i], lsmInitState.getSearchPredicate());
}
lsmHarness = lsmInitState.getLSMHarness();
operationalComponents = lsmInitState.getOperationalComponents();
includeMutableComponent = lsmInitState.getIncludeMemComponent();
// For searching the deleted-keys BTrees.
this.keysOnlyTuple = lsmInitState.getKeysOnlyTuple();
deletedKeysBTreeAccessors = lsmInitState.getDeletedKeysBTreeAccessors();
if (!deletedKeysBTreeAccessors.isEmpty()) {
deletedKeysBTreeCursors = new IIndexCursor[deletedKeysBTreeAccessors.size()];
for (int i = 0; i < operationalComponents.size(); i++) {
ILSMComponent component = operationalComponents.get(i);
if (component.getType() == LSMComponentType.MEMORY) {
// No need for a bloom filter for the in-memory BTree.
deletedKeysBTreeCursors[i] = deletedKeysBTreeAccessors.get(i).createSearchCursor(false);
} else {
deletedKeysBTreeCursors[i] = new BloomFilterAwareBTreePointSearchCursor((IBTreeLeafFrame) lsmInitState.getgetDeletedKeysBTreeLeafFrameFactory().createFrame(), false, ((LSMInvertedIndexDiskComponent) operationalComponents.get(i)).getBloomFilter());
}
}
}
MultiComparator keyCmp = lsmInitState.getKeyComparator();
keySearchPred = new RangePredicate(keysOnlyTuple, keysOnlyTuple, true, true, keyCmp, keyCmp);
setPriorityQueueComparator();
initPriorityQueue();
}
use of org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame in project asterixdb by apache.
the class LSMBTreePointSearchCursor method open.
@Override
public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
LSMBTreeCursorInitialState lsmInitialState = (LSMBTreeCursorInitialState) initialState;
operationalComponents = lsmInitialState.getOperationalComponents();
lsmHarness = lsmInitialState.getLSMHarness();
searchCallback = lsmInitialState.getSearchOperationCallback();
predicate = (RangePredicate) lsmInitialState.getSearchPredicate();
numBTrees = operationalComponents.size();
if (rangeCursors == null || rangeCursors.length != numBTrees) {
// object creation: should be relatively low
rangeCursors = new BTreeRangeSearchCursor[numBTrees];
btreeAccessors = new BTreeAccessor[numBTrees];
}
includeMutableComponent = false;
for (int i = 0; i < numBTrees; i++) {
ILSMComponent component = operationalComponents.get(i);
BTree btree;
if (component.getType() == LSMComponentType.MEMORY) {
includeMutableComponent = true;
// No need for a bloom filter for the in-memory BTree.
if (rangeCursors[i] == null || rangeCursors[i].isBloomFilterAware()) {
// create a new one
IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getLeafFrameFactory().createFrame();
rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false);
} else {
// reset
rangeCursors[i].reset();
}
btree = ((LSMBTreeMemoryComponent) component).getBTree();
} else {
if (rangeCursors[i] != null && rangeCursors[i].isBloomFilterAware()) {
// can re-use cursor
((BloomFilterAwareBTreePointSearchCursor) rangeCursors[i]).resetBloomFilter(((LSMBTreeDiskComponent) component).getBloomFilter());
rangeCursors[i].reset();
} else {
// create new cursor <should be relatively rare>
IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getLeafFrameFactory().createFrame();
rangeCursors[i] = new BloomFilterAwareBTreePointSearchCursor(leafFrame, false, ((LSMBTreeDiskComponent) component).getBloomFilter());
}
btree = ((LSMBTreeDiskComponent) component).getBTree();
}
if (btreeAccessors[i] == null) {
btreeAccessors[i] = (BTreeAccessor) btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
} else {
// re-use
btreeAccessors[i].reset(btree, NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
}
}
nextHasBeenCalled = false;
foundTuple = false;
}
use of org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame 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