Search in sources :

Example 11 with IIndexBulkLoader

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;
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) ILSMIndexOperationContext(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext) IIndexBulkLoader(org.apache.hyracks.storage.common.IIndexBulkLoader) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor) ISearchPredicate(org.apache.hyracks.storage.common.ISearchPredicate)

Aggregations

IIndexBulkLoader (org.apache.hyracks.storage.common.IIndexBulkLoader)11 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)7 ArrayTupleReference (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleReference)7 Test (org.junit.Test)5 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)4 IBinaryComparatorFactory (org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory)3 ITypeTraits (org.apache.hyracks.api.dataflow.value.ITypeTraits)3 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)3 BloomFilterSpecification (org.apache.hyracks.storage.am.bloomfilter.impls.BloomFilterSpecification)3 ITreeIndex (org.apache.hyracks.storage.am.common.api.ITreeIndex)3 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 BloomFilter (org.apache.hyracks.storage.am.bloomfilter.impls.BloomFilter)2 AbstractBloomFilterTest (org.apache.hyracks.storage.am.bloomfilter.util.AbstractBloomFilterTest)2 ILSMIndexOperationContext (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext)2 IIndexAccessor (org.apache.hyracks.storage.common.IIndexAccessor)2 IIndexCursor (org.apache.hyracks.storage.common.IIndexCursor)2 ISearchPredicate (org.apache.hyracks.storage.common.ISearchPredicate)2 IBufferCache (org.apache.hyracks.storage.common.buffercache.IBufferCache)2 Random (java.util.Random)1