Search in sources :

Example 6 with BTreeRangeSearchCursor

use of org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor in project asterixdb by apache.

the class BTreeUpdateSearchOperatorNodePushable method createCursor.

@Override
protected ITreeIndexCursor createCursor() {
    ITreeIndex treeIndex = (ITreeIndex) index;
    ITreeIndexFrame cursorFrame = treeIndex.getLeafFrameFactory().createFrame();
    return new BTreeRangeSearchCursor((IBTreeLeafFrame) cursorFrame, true);
}
Also used : BTreeRangeSearchCursor(org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor) ITreeIndexFrame(org.apache.hyracks.storage.am.common.api.ITreeIndexFrame) ITreeIndex(org.apache.hyracks.storage.am.common.api.ITreeIndex)

Example 7 with BTreeRangeSearchCursor

use of org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor 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;
}
Also used : BTreeRangeSearchCursor(org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor) IBTreeLeafFrame(org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) BTree(org.apache.hyracks.storage.am.btree.impls.BTree) BloomFilterAwareBTreePointSearchCursor(org.apache.hyracks.storage.am.lsm.common.impls.BloomFilterAwareBTreePointSearchCursor)

Example 8 with BTreeRangeSearchCursor

use of org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor in project asterixdb by apache.

the class LSMRTreeDeletedKeysBTreeMergeCursor method open.

@Override
public void open(ICursorInitialState initialState, ISearchPredicate searchPred) throws HyracksDataException {
    LSMRTreeCursorInitialState lsmInitialState = (LSMRTreeCursorInitialState) initialState;
    cmp = lsmInitialState.getBTreeCmp();
    operationalComponents = lsmInitialState.getOperationalComponents();
    // We intentionally set the lsmHarness to null so that we don't call lsmHarness.endSearch() because we already do that when we merge r-trees.
    lsmHarness = null;
    int numBTrees = operationalComponents.size();
    rangeCursors = new IIndexCursor[numBTrees];
    RangePredicate btreePredicate = new RangePredicate(null, null, true, true, cmp, cmp);
    IIndexAccessor[] btreeAccessors = new ITreeIndexAccessor[numBTrees];
    for (int i = 0; i < numBTrees; i++) {
        ILSMComponent component = operationalComponents.get(i);
        IBTreeLeafFrame leafFrame = (IBTreeLeafFrame) lsmInitialState.getBTreeLeafFrameFactory().createFrame();
        rangeCursors[i] = new BTreeRangeSearchCursor(leafFrame, false);
        BTree btree = ((LSMRTreeDiskComponent) component).getBTree();
        btreeAccessors[i] = btree.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        btreeAccessors[i].search(rangeCursors[i], btreePredicate);
    }
    setPriorityQueueComparator();
    initPriorityQueue();
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) BTreeRangeSearchCursor(org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor) IBTreeLeafFrame(org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) BTree(org.apache.hyracks.storage.am.btree.impls.BTree) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor)

Example 9 with BTreeRangeSearchCursor

use of org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor in project asterixdb by apache.

the class LSMRTreeWithAntiMatterTuples method flush.

@Override
public ILSMDiskComponent flush(ILSMIOOperation operation) throws HyracksDataException {
    LSMRTreeFlushOperation flushOp = (LSMRTreeFlushOperation) operation;
    // Renaming order is critical because we use assume ordering when we
    // read the file names when we open the tree.
    // The RTree should be renamed before the BTree.
    LSMRTreeMemoryComponent flushingComponent = (LSMRTreeMemoryComponent) flushOp.getFlushingComponent();
    ITreeIndexAccessor memRTreeAccessor = flushingComponent.getRTree().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    RTreeSearchCursor rtreeScanCursor = (RTreeSearchCursor) memRTreeAccessor.createSearchCursor(false);
    SearchPredicate rtreeNullPredicate = new SearchPredicate(null, null);
    memRTreeAccessor.search(rtreeScanCursor, rtreeNullPredicate);
    LSMRTreeDiskComponent component = createDiskComponent(componentFactory, flushOp.getTarget(), null, null, true);
    ILSMDiskComponentBulkLoader componentBulkLoader = createComponentBulkLoader(component, 1.0f, false, 0L, false, false);
    // Since the LSM-RTree is used as a secondary assumption, the
    // primary key will be the last comparator in the BTree comparators
    TreeTupleSorter rTreeTupleSorter = new TreeTupleSorter(flushingComponent.getRTree().getFileId(), linearizerArray, rtreeLeafFrameFactory.createFrame(), rtreeLeafFrameFactory.createFrame(), flushingComponent.getRTree().getBufferCache(), comparatorFields);
    boolean isEmpty = true;
    try {
        while (rtreeScanCursor.hasNext()) {
            isEmpty = false;
            rtreeScanCursor.next();
            rTreeTupleSorter.insertTupleEntry(rtreeScanCursor.getPageId(), rtreeScanCursor.getTupleOffset());
        }
    } finally {
        rtreeScanCursor.close();
    }
    if (!isEmpty) {
        rTreeTupleSorter.sort();
    }
    // scan the memory BTree
    ITreeIndexAccessor memBTreeAccessor = flushingComponent.getBTree().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    BTreeRangeSearchCursor btreeScanCursor = (BTreeRangeSearchCursor) memBTreeAccessor.createSearchCursor(false);
    RangePredicate btreeNullPredicate = new RangePredicate(null, null, true, true, null, null);
    memBTreeAccessor.search(btreeScanCursor, btreeNullPredicate);
    TreeTupleSorter bTreeTupleSorter = new TreeTupleSorter(flushingComponent.getBTree().getFileId(), linearizerArray, btreeLeafFrameFactory.createFrame(), btreeLeafFrameFactory.createFrame(), flushingComponent.getBTree().getBufferCache(), comparatorFields);
    isEmpty = true;
    try {
        while (btreeScanCursor.hasNext()) {
            isEmpty = false;
            btreeScanCursor.next();
            bTreeTupleSorter.insertTupleEntry(btreeScanCursor.getPageId(), btreeScanCursor.getTupleOffset());
        }
    } finally {
        btreeScanCursor.close();
    }
    if (!isEmpty) {
        bTreeTupleSorter.sort();
    }
    LSMRTreeWithAntiMatterTuplesFlushCursor cursor = new LSMRTreeWithAntiMatterTuplesFlushCursor(rTreeTupleSorter, bTreeTupleSorter, comparatorFields, linearizerArray);
    cursor.open(null, null);
    try {
        while (cursor.hasNext()) {
            cursor.next();
            ITupleReference frameTuple = cursor.getTuple();
            componentBulkLoader.add(frameTuple);
        }
    } finally {
        cursor.close();
    }
    if (component.getLSMComponentFilter() != null) {
        List<ITupleReference> filterTuples = new ArrayList<>();
        filterTuples.add(flushingComponent.getLSMComponentFilter().getMinTuple());
        filterTuples.add(flushingComponent.getLSMComponentFilter().getMaxTuple());
        getFilterManager().updateFilter(component.getLSMComponentFilter(), filterTuples);
        getFilterManager().writeFilter(component.getLSMComponentFilter(), component.getRTree());
    }
    flushingComponent.getMetadata().copy(component.getMetadata());
    componentBulkLoader.end();
    return component;
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) BTreeRangeSearchCursor(org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor) ArrayList(java.util.ArrayList) ILSMDiskComponentBulkLoader(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentBulkLoader) RTreeSearchCursor(org.apache.hyracks.storage.am.rtree.impls.RTreeSearchCursor) SearchPredicate(org.apache.hyracks.storage.am.rtree.impls.SearchPredicate) ISearchPredicate(org.apache.hyracks.storage.common.ISearchPredicate) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)

Example 10 with BTreeRangeSearchCursor

use of org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor in project asterixdb by apache.

the class BTreeSearchCursorTest method performSearches.

public boolean performSearches(ArrayList<Integer> keys, BTree btree, IBTreeLeafFrame leafFrame, IBTreeInteriorFrame interiorFrame, int minKey, int maxKey, boolean lowKeyInclusive, boolean highKeyInclusive, boolean printExpectedResults) throws Exception {
    ArrayList<Integer> results = new ArrayList<>();
    ArrayList<Integer> expectedResults = new ArrayList<>();
    for (int i = minKey; i < maxKey; i++) {
        for (int j = minKey; j < maxKey; j++) {
            results.clear();
            expectedResults.clear();
            int lowKey = i;
            int highKey = j;
            ITreeIndexCursor rangeCursor = new BTreeRangeSearchCursor(leafFrame, false);
            RangePredicate rangePred = createRangePredicate(lowKey, highKey, lowKeyInclusive, highKeyInclusive);
            ITreeIndexAccessor indexAccessor = btree.createAccessor(TestOperationCallback.INSTANCE, TestOperationCallback.INSTANCE);
            indexAccessor.search(rangeCursor, rangePred);
            try {
                while (rangeCursor.hasNext()) {
                    rangeCursor.next();
                    ITupleReference frameTuple = rangeCursor.getTuple();
                    ByteArrayInputStream inStream = new ByteArrayInputStream(frameTuple.getFieldData(0), frameTuple.getFieldStart(0), frameTuple.getFieldLength(0));
                    DataInput dataIn = new DataInputStream(inStream);
                    Integer res = IntegerSerializerDeserializer.INSTANCE.deserialize(dataIn);
                    results.add(res);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                rangeCursor.close();
            }
            getExpectedResults(expectedResults, keys, lowKey, highKey, lowKeyInclusive, highKeyInclusive);
            if (printExpectedResults) {
                if (expectedResults.size() > 0) {
                    char l, u;
                    if (lowKeyInclusive) {
                        l = '[';
                    } else {
                        l = '(';
                    }
                    if (highKeyInclusive) {
                        u = ']';
                    } else {
                        u = ')';
                    }
                    if (LOGGER.isLoggable(Level.INFO)) {
                        LOGGER.info("RANGE: " + l + " " + lowKey + " , " + highKey + " " + u);
                    }
                    StringBuilder strBuilder = new StringBuilder();
                    for (Integer r : expectedResults) {
                        strBuilder.append(r + " ");
                    }
                    if (LOGGER.isLoggable(Level.INFO)) {
                        LOGGER.info(strBuilder.toString());
                    }
                }
            }
            if (results.size() == expectedResults.size()) {
                for (int k = 0; k < results.size(); k++) {
                    if (!results.get(k).equals(expectedResults.get(k))) {
                        if (LOGGER.isLoggable(Level.INFO)) {
                            LOGGER.info("DIFFERENT RESULTS AT: i=" + i + " j=" + j + " k=" + k);
                            LOGGER.info(results.get(k) + " " + expectedResults.get(k));
                        }
                        return false;
                    }
                }
            } else {
                if (LOGGER.isLoggable(Level.INFO)) {
                    LOGGER.info("UNEQUAL NUMBER OF RESULTS AT: i=" + i + " j=" + j);
                    LOGGER.info("RESULTS: " + results.size());
                    LOGGER.info("EXPECTED RESULTS: " + expectedResults.size());
                }
                return false;
            }
        }
    }
    return true;
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) BTreeRangeSearchCursor(org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor) ArrayList(java.util.ArrayList) DataInputStream(java.io.DataInputStream) ITreeIndexAccessor(org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) DataInput(java.io.DataInput) ByteArrayInputStream(java.io.ByteArrayInputStream) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)

Aggregations

BTreeRangeSearchCursor (org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor)11 IBTreeLeafFrame (org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame)8 BTree (org.apache.hyracks.storage.am.btree.impls.BTree)8 ILSMComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)7 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)6 ITreeIndexAccessor (org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)6 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)3 BloomFilterAwareBTreePointSearchCursor (org.apache.hyracks.storage.am.lsm.common.impls.BloomFilterAwareBTreePointSearchCursor)3 RTreeSearchCursor (org.apache.hyracks.storage.am.rtree.impls.RTreeSearchCursor)3 ArrayList (java.util.ArrayList)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)2 IRTreeInteriorFrame (org.apache.hyracks.storage.am.rtree.api.IRTreeInteriorFrame)2 IRTreeLeafFrame (org.apache.hyracks.storage.am.rtree.api.IRTreeLeafFrame)2 RTree (org.apache.hyracks.storage.am.rtree.impls.RTree)2 IIndexAccessor (org.apache.hyracks.storage.common.IIndexAccessor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInput (java.io.DataInput)1 DataInputStream (java.io.DataInputStream)1 Random (java.util.Random)1