Search in sources :

Example 1 with ILSMComponent

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

Example 2 with ILSMComponent

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.

the class ExternalRTree method clear.

// The clear method is not used anywhere in AsterixDB! we override it anyway
// to exit components first and clear the two lists
@Override
public void clear() throws HyracksDataException {
    if (!isActive) {
        throw new HyracksDataException("Failed to clear the index since it is not activated.");
    }
    getLsmHarness().indexClear();
    for (ILSMComponent c : diskComponents) {
        LSMRTreeDiskComponent component = (LSMRTreeDiskComponent) c;
        component.getRTree().deactivate();
        component.getBloomFilter().deactivate();
        component.getBTree().deactivate();
        component.getRTree().destroy();
        component.getBloomFilter().destroy();
        component.getBTree().destroy();
        // Remove from second list to avoid destroying twice
        secondDiskComponents.remove(c);
    }
    for (ILSMComponent c : secondDiskComponents) {
        LSMRTreeDiskComponent component = (LSMRTreeDiskComponent) c;
        component.getRTree().deactivate();
        component.getBloomFilter().deactivate();
        component.getBTree().deactivate();
        component.getRTree().destroy();
        component.getBloomFilter().destroy();
        component.getBTree().destroy();
    }
    diskComponents.clear();
    secondDiskComponents.clear();
    version = 0;
}
Also used : ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 3 with ILSMComponent

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.

the class ExternalRTree method activate.

@Override
public synchronized void activate() throws HyracksDataException {
    if (isActive) {
        throw new HyracksDataException("Failed to activate the index since it is already activated.");
    }
    if (diskComponents.size() == 0 && secondDiskComponents.size() == 0) {
        //First time activation
        List<LSMComponentFileReferences> validFileReferences;
        validFileReferences = fileManager.cleanupAndGetValidFiles();
        for (LSMComponentFileReferences lsmComonentFileReference : validFileReferences) {
            LSMRTreeDiskComponent component;
            component = createDiskComponent(componentFactory, lsmComonentFileReference.getInsertIndexFileReference(), lsmComonentFileReference.getDeleteIndexFileReference(), lsmComonentFileReference.getBloomFilterFileReference(), false);
            diskComponents.add(component);
            secondDiskComponents.add(component);
        }
        getLsmHarness().indexFirstTimeActivated();
    } else {
        // components. It should also maintain the version pointer
        for (ILSMComponent c : diskComponents) {
            LSMRTreeDiskComponent component = (LSMRTreeDiskComponent) c;
            RTree rtree = component.getRTree();
            BTree btree = component.getBTree();
            BloomFilter bloomFilter = component.getBloomFilter();
            rtree.activate();
            btree.activate();
            bloomFilter.activate();
        }
        for (ILSMComponent c : secondDiskComponents) {
            // Only activate non shared components
            if (!diskComponents.contains(c)) {
                LSMRTreeDiskComponent component = (LSMRTreeDiskComponent) c;
                RTree rtree = component.getRTree();
                BTree btree = component.getBTree();
                BloomFilter bloomFilter = component.getBloomFilter();
                rtree.activate();
                btree.activate();
                bloomFilter.activate();
            }
        }
    }
    isActive = true;
}
Also used : ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) BTree(org.apache.hyracks.storage.am.btree.impls.BTree) RTree(org.apache.hyracks.storage.am.rtree.impls.RTree) LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) BloomFilter(org.apache.hyracks.storage.am.bloomfilter.impls.BloomFilter)

Example 4 with ILSMComponent

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

Example 5 with ILSMComponent

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent in project asterixdb by apache.

the class LSMInvertedIndex method search.

@Override
public void search(ILSMIndexOperationContext ictx, IIndexCursor cursor, ISearchPredicate pred) throws HyracksDataException {
    List<ILSMComponent> operationalComponents = ictx.getComponentHolder();
    int numComponents = operationalComponents.size();
    boolean includeMutableComponent = false;
    ArrayList<IIndexAccessor> indexAccessors = new ArrayList<>(numComponents);
    ArrayList<IIndexAccessor> deletedKeysBTreeAccessors = new ArrayList<>(numComponents);
    for (int i = 0; i < operationalComponents.size(); i++) {
        ILSMComponent component = operationalComponents.get(i);
        if (component.getType() == LSMComponentType.MEMORY) {
            includeMutableComponent = true;
            IIndexAccessor invIndexAccessor = ((LSMInvertedIndexMemoryComponent) component).getInvIndex().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
            indexAccessors.add(invIndexAccessor);
            IIndexAccessor deletedKeysAccessor = ((LSMInvertedIndexMemoryComponent) component).getDeletedKeysBTree().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
            deletedKeysBTreeAccessors.add(deletedKeysAccessor);
        } else {
            IIndexAccessor invIndexAccessor = ((LSMInvertedIndexDiskComponent) component).getInvIndex().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
            indexAccessors.add(invIndexAccessor);
            IIndexAccessor deletedKeysAccessor = ((LSMInvertedIndexDiskComponent) component).getDeletedKeysBTree().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
            deletedKeysBTreeAccessors.add(deletedKeysAccessor);
        }
    }
    ICursorInitialState initState = createCursorInitialState(pred, ictx, includeMutableComponent, indexAccessors, deletedKeysBTreeAccessors, operationalComponents);
    cursor.open(initState, pred);
}
Also used : ICursorInitialState(org.apache.hyracks.storage.common.ICursorInitialState) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) ArrayList(java.util.ArrayList) IIndexAccessor(org.apache.hyracks.storage.common.IIndexAccessor)

Aggregations

ILSMComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)38 BTree (org.apache.hyracks.storage.am.btree.impls.BTree)13 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)10 ILSMDiskComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent)10 IBTreeLeafFrame (org.apache.hyracks.storage.am.btree.api.IBTreeLeafFrame)9 BTreeRangeSearchCursor (org.apache.hyracks.storage.am.btree.impls.BTreeRangeSearchCursor)7 RangePredicate (org.apache.hyracks.storage.am.btree.impls.RangePredicate)7 LSMComponentFileReferences (org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences)6 BloomFilter (org.apache.hyracks.storage.am.bloomfilter.impls.BloomFilter)5 BloomFilterAwareBTreePointSearchCursor (org.apache.hyracks.storage.am.lsm.common.impls.BloomFilterAwareBTreePointSearchCursor)5 ArrayList (java.util.ArrayList)4 ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)4 RTree (org.apache.hyracks.storage.am.rtree.impls.RTree)4 ITreeIndexAccessor (org.apache.hyracks.storage.am.common.api.ITreeIndexAccessor)3 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)3 ILSMIndexOperationContext (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext)3 IIndexAccessor (org.apache.hyracks.storage.common.IIndexAccessor)3 ILSMDiskComponentId (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId)2 BlockingIOOperationCallbackWrapper (org.apache.hyracks.storage.am.lsm.common.impls.BlockingIOOperationCallbackWrapper)2 LSMTreeIndexAccessor (org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor)2