use of org.apache.hyracks.storage.common.IIndexBulkLoader in project asterixdb by apache.
the class ExternalBTreeWithBuddy method merge.
@Override
public ILSMDiskComponent merge(ILSMIOOperation operation) throws HyracksDataException {
LSMBTreeWithBuddyMergeOperation mergeOp = (LSMBTreeWithBuddyMergeOperation) operation;
IIndexCursor cursor = mergeOp.getCursor();
ISearchPredicate btreeSearchPred = new RangePredicate(null, null, true, true, null, null);
ILSMIndexOperationContext opCtx = ((LSMBTreeWithBuddySortedCursor) cursor).getOpCtx();
opCtx.getComponentHolder().addAll(mergeOp.getMergingComponents());
search(opCtx, cursor, btreeSearchPred);
LSMBTreeWithBuddyDiskComponent mergedComponent = createDiskComponent(componentFactory, mergeOp.getTarget(), mergeOp.getBuddyBTreeTarget(), mergeOp.getBloomFilterTarget(), true);
IIndexBulkLoader componentBulkLoader;
if (mergeOp.isKeepDeletedTuples()) {
// Keep the deleted tuples since the oldest disk component is not
// included in the merge operation
LSMBuddyBTreeMergeCursor buddyBtreeCursor = new LSMBuddyBTreeMergeCursor(opCtx);
search(opCtx, buddyBtreeCursor, btreeSearchPred);
long numElements = 0L;
for (int i = 0; i < mergeOp.getMergingComponents().size(); ++i) {
numElements += ((LSMBTreeWithBuddyDiskComponent) mergeOp.getMergingComponents().get(i)).getBloomFilter().getNumElements();
}
componentBulkLoader = createComponentBulkLoader(mergedComponent, 1.0f, false, numElements, false, false);
try {
while (buddyBtreeCursor.hasNext()) {
buddyBtreeCursor.next();
ITupleReference tuple = buddyBtreeCursor.getTuple();
((LSMBTreeWithBuddyDiskComponentBulkLoader) componentBulkLoader).delete(tuple);
}
} finally {
buddyBtreeCursor.close();
}
} else {
componentBulkLoader = createComponentBulkLoader(mergedComponent, 1.0f, false, 0L, false, false);
}
try {
while (cursor.hasNext()) {
cursor.next();
ITupleReference frameTuple = cursor.getTuple();
componentBulkLoader.add(frameTuple);
}
} finally {
cursor.close();
}
componentBulkLoader.end();
return mergedComponent;
}
Aggregations