Search in sources :

Example 21 with ILSMComponent

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

the class ExternalBTree method deactivate.

@Override
public void deactivate(boolean flushOnExit) throws HyracksDataException {
    if (!isActive) {
        throw new HyracksDataException("Failed to deactivate the index since it is already deactivated.");
    }
    if (flushOnExit) {
        BlockingIOOperationCallbackWrapper cb = new BlockingIOOperationCallbackWrapper(ioOpCallback);
        cb.afterFinalize(LSMOperationType.FLUSH, null);
    }
    for (ILSMComponent c : diskComponents) {
        LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
        BTree btree = component.getBTree();
        BloomFilter bloomFilter = component.getBloomFilter();
        btree.deactivateCloseHandle();
        bloomFilter.deactivate();
    }
    for (ILSMComponent c : secondDiskComponents) {
        // Only deactivate non shared components (So components are not de-activated twice)
        if (!diskComponents.contains(c)) {
            LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
            BTree btree = component.getBTree();
            BloomFilter bloomFilter = component.getBloomFilter();
            btree.deactivateCloseHandle();
            bloomFilter.deactivate();
        }
    }
    isActive = false;
}
Also used : ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) BTree(org.apache.hyracks.storage.am.btree.impls.BTree) BlockingIOOperationCallbackWrapper(org.apache.hyracks.storage.am.lsm.common.impls.BlockingIOOperationCallbackWrapper) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) BloomFilter(org.apache.hyracks.storage.am.bloomfilter.impls.BloomFilter)

Example 22 with ILSMComponent

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

the class ExternalBTree method clear.

// The clear method is not used anywhere in AsterixDB! we override it anyway
// to exit components first and deal with 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) {
        LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
        component.getBloomFilter().deactivate();
        component.getBTree().deactivate();
        component.getBloomFilter().destroy();
        component.getBTree().destroy();
        // Remove from second list to avoid destroying twice
        secondDiskComponents.remove(c);
    }
    for (ILSMComponent c : secondDiskComponents) {
        LSMBTreeDiskComponent component = (LSMBTreeDiskComponent) c;
        component.getBloomFilter().deactivate();
        component.getBTree().deactivate();
        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 23 with ILSMComponent

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

the class ExternalBTree method scheduleMerge.

// The only reason to override the following method is that it uses a different context object
// in addition, determining whether or not to keep deleted tuples is different here
@Override
public void scheduleMerge(ILSMIndexOperationContext ctx, ILSMIOOperationCallback callback) throws HyracksDataException {
    ExternalBTreeOpContext opCtx = createOpContext(NoOpOperationCallback.INSTANCE, -1);
    opCtx.setOperation(IndexOperation.MERGE);
    List<ILSMComponent> mergingComponents = ctx.getComponentHolder();
    boolean returnDeletedTuples = false;
    if (version == 0) {
        if (ctx.getComponentHolder().get(ctx.getComponentHolder().size() - 1) != diskComponents.get(diskComponents.size() - 1)) {
            returnDeletedTuples = true;
        }
    } else {
        if (ctx.getComponentHolder().get(ctx.getComponentHolder().size() - 1) != secondDiskComponents.get(secondDiskComponents.size() - 1)) {
            returnDeletedTuples = true;
        }
    }
    ITreeIndexCursor cursor = new LSMBTreeRangeSearchCursor(opCtx, returnDeletedTuples);
    BTree firstBTree = ((LSMBTreeDiskComponent) mergingComponents.get(0)).getBTree();
    BTree lastBTree = ((LSMBTreeDiskComponent) mergingComponents.get(mergingComponents.size() - 1)).getBTree();
    FileReference firstFile = firstBTree.getFileReference();
    FileReference lastFile = lastBTree.getFileReference();
    LSMComponentFileReferences relMergeFileRefs = fileManager.getRelMergeFileReference(firstFile.getFile().getName(), lastFile.getFile().getName());
    ILSMIndexAccessor accessor = new LSMTreeIndexAccessor(getLsmHarness(), opCtx, cursorFactory);
    ioScheduler.scheduleOperation(new LSMBTreeMergeOperation(accessor, mergingComponents, cursor, relMergeFileRefs.getInsertIndexFileReference(), relMergeFileRefs.getBloomFilterFileReference(), callback, fileManager.getBaseDir()));
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) BTree(org.apache.hyracks.storage.am.btree.impls.BTree) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) LSMTreeIndexAccessor(org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor) FileReference(org.apache.hyracks.api.io.FileReference) LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences)

Example 24 with ILSMComponent

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

the class ExternalBTreeWithBuddy method activate.

@Override
public 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) {
            LSMBTreeWithBuddyDiskComponent component;
            component = createDiskComponent(componentFactory, lsmComonentFileReference.getInsertIndexFileReference(), lsmComonentFileReference.getDeleteIndexFileReference(), lsmComonentFileReference.getBloomFilterFileReference(), false);
            diskComponents.add(component);
            secondDiskComponents.add(component);
        }
        ((ExternalIndexHarness) getLsmHarness()).indexFirstTimeActivated();
    } else {
        // components. It should also maintain the version pointer
        for (ILSMComponent c : diskComponents) {
            LSMBTreeWithBuddyDiskComponent component = (LSMBTreeWithBuddyDiskComponent) c;
            BTree btree = component.getBTree();
            BTree buddyBtree = component.getBuddyBTree();
            BloomFilter bloomFilter = component.getBloomFilter();
            btree.activate();
            buddyBtree.activate();
            bloomFilter.activate();
        }
        for (ILSMComponent c : secondDiskComponents) {
            // Only activate non shared components
            if (!diskComponents.contains(c)) {
                LSMBTreeWithBuddyDiskComponent component = (LSMBTreeWithBuddyDiskComponent) c;
                BTree btree = component.getBTree();
                BTree buddyBtree = component.getBuddyBTree();
                BloomFilter bloomFilter = component.getBloomFilter();
                btree.activate();
                buddyBtree.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) ExternalIndexHarness(org.apache.hyracks.storage.am.lsm.common.impls.ExternalIndexHarness) 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 25 with ILSMComponent

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

the class LSMBTree method insert.

private boolean insert(ITupleReference tuple, LSMBTreeOpContext ctx) throws HyracksDataException {
    LSMBTreePointSearchCursor searchCursor = ctx.getInsertSearchCursor();
    IIndexCursor memCursor = ctx.getMemCursor();
    RangePredicate predicate = (RangePredicate) ctx.getSearchPredicate();
    predicate.setHighKey(tuple);
    predicate.setLowKey(tuple);
    if (needKeyDupCheck) {
        // first check the inmemory component
        ctx.getCurrentMutableBTreeAccessor().search(memCursor, predicate);
        try {
            if (memCursor.hasNext()) {
                memCursor.next();
                LSMBTreeTupleReference lsmbtreeTuple = (LSMBTreeTupleReference) memCursor.getTuple();
                if (!lsmbtreeTuple.isAntimatter()) {
                    throw HyracksDataException.create(ErrorCode.DUPLICATE_KEY);
                } else {
                    memCursor.close();
                    ctx.getCurrentMutableBTreeAccessor().upsertIfConditionElseInsert(tuple, AntimatterAwareTupleAcceptor.INSTANCE);
                    return true;
                }
            }
        } finally {
            memCursor.close();
        }
        // TODO: Can we just remove the above code that search the mutable
        // component and do it together with the search call below? i.e. instead
        // of passing false to the lsmHarness.search(), we pass true to include
        // the mutable component?
        // the key was not in the inmemory component, so check the disk
        // components
        // This is a hack to avoid searching the current active mutable component twice. It is critical to add it back once the search is over.
        ILSMComponent firstComponent = ctx.getComponentHolder().remove(0);
        search(ctx, searchCursor, predicate);
        try {
            if (searchCursor.hasNext()) {
                throw HyracksDataException.create(ErrorCode.DUPLICATE_KEY);
            }
        } finally {
            searchCursor.close();
            // Add the current active mutable component back
            ctx.getComponentHolder().add(0, firstComponent);
        }
    }
    ctx.getCurrentMutableBTreeAccessor().upsertIfConditionElseInsert(tuple, AntimatterAwareTupleAcceptor.INSTANCE);
    return true;
}
Also used : RangePredicate(org.apache.hyracks.storage.am.btree.impls.RangePredicate) LSMBTreeTupleReference(org.apache.hyracks.storage.am.lsm.btree.tuples.LSMBTreeTupleReference) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) IIndexCursor(org.apache.hyracks.storage.common.IIndexCursor)

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