Search in sources :

Example 16 with ILSMIndexAccessor

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

the class ExternalRTree method scheduleMerge.

// The only change the the schedule merge is the method used to create the
// opCtx. first line <- in schedule merge, we->
@Override
public void scheduleMerge(ILSMIndexOperationContext ctx, ILSMIOOperationCallback callback) throws HyracksDataException {
    ILSMIndexOperationContext rctx = createOpContext(NoOpOperationCallback.INSTANCE, -1);
    rctx.setOperation(IndexOperation.MERGE);
    List<ILSMComponent> mergingComponents = ctx.getComponentHolder();
    ITreeIndexCursor cursor = new LSMRTreeSortedCursor(rctx, linearizer, buddyBTreeFields);
    LSMComponentFileReferences relMergeFileRefs = getMergeFileReferences((ILSMDiskComponent) mergingComponents.get(0), (ILSMDiskComponent) mergingComponents.get(mergingComponents.size() - 1));
    ILSMIndexAccessor accessor = new LSMRTreeAccessor(getLsmHarness(), rctx, buddyBTreeFields);
    // create the merge operation.
    LSMRTreeMergeOperation mergeOp = new LSMRTreeMergeOperation(accessor, mergingComponents, cursor, relMergeFileRefs.getInsertIndexFileReference(), relMergeFileRefs.getDeleteIndexFileReference(), relMergeFileRefs.getBloomFilterFileReference(), callback, fileManager.getBaseDir());
    ioScheduler.scheduleOperation(mergeOp);
}
Also used : ITreeIndexCursor(org.apache.hyracks.storage.am.common.api.ITreeIndexCursor) ILSMComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent) ILSMIndexOperationContext(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) LSMComponentFileReferences(org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences)

Example 17 with ILSMIndexAccessor

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

the class LSMInvertedIndexMergeTest method runTest.

@Override
protected void runTest(LSMInvertedIndexTestContext testCtx, TupleGenerator tupleGen) throws IOException {
    IIndex invIndex = testCtx.getIndex();
    invIndex.create();
    invIndex.activate();
    ILSMIndexAccessor invIndexAccessor = (ILSMIndexAccessor) invIndex.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    for (int i = 0; i < maxTreesToMerge; i++) {
        for (int j = 0; j < i; j++) {
            LSMInvertedIndexTestUtils.insertIntoInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT);
            // Deactivate and the re-activate the index to force it flush its in memory component
            invIndex.deactivate();
            invIndex.activate();
        }
        // Perform merge.
        invIndexAccessor.scheduleMerge(NoOpIOOperationCallbackFactory.INSTANCE.createIoOpCallback(), ((LSMInvertedIndex) invIndex).getImmutableComponents());
        validateAndCheckIndex(testCtx);
        runTinySearchWorkload(testCtx, tupleGen);
    }
    invIndex.deactivate();
    invIndex.destroy();
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)

Example 18 with ILSMIndexAccessor

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

the class PartitionedLSMInvertedIndexMergeTest method runTest.

@Override
protected void runTest(LSMInvertedIndexTestContext testCtx, TupleGenerator tupleGen) throws IOException, HyracksDataException {
    IIndex invIndex = testCtx.getIndex();
    invIndex.create();
    invIndex.activate();
    ILSMIndexAccessor invIndexAccessor = (ILSMIndexAccessor) invIndex.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    for (int i = 0; i < maxTreesToMerge; i++) {
        for (int j = 0; j < i; j++) {
            LSMInvertedIndexTestUtils.insertIntoInvIndex(testCtx, tupleGen, NUM_DOCS_TO_INSERT);
            // Deactivate and the re-activate the index to force it flush its in memory component
            invIndex.deactivate();
            invIndex.activate();
        }
        // Perform merge.
        invIndexAccessor.scheduleMerge(NoOpIOOperationCallbackFactory.INSTANCE.createIoOpCallback(), ((LSMInvertedIndex) invIndex).getImmutableComponents());
        validateAndCheckIndex(testCtx);
        runTinySearchWorkload(testCtx, tupleGen);
    }
    invIndex.deactivate();
    invIndex.destroy();
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)

Example 19 with ILSMIndexAccessor

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

the class RecoveryManager method undo.

private static void undo(ILogRecord logRecord, IDatasetLifecycleManager datasetLifecycleManager) {
    try {
        ILSMIndex index = (ILSMIndex) datasetLifecycleManager.getIndex(logRecord.getDatasetId(), logRecord.getResourceId());
        ILSMIndexAccessor indexAccessor = index.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        if (logRecord.getNewOp() == AbstractIndexModificationOperationCallback.INSERT_BYTE) {
            indexAccessor.forceDelete(logRecord.getNewValue());
        } else if (logRecord.getNewOp() == AbstractIndexModificationOperationCallback.DELETE_BYTE) {
            indexAccessor.forceInsert(logRecord.getOldValue());
        } else if (logRecord.getNewOp() == AbstractIndexModificationOperationCallback.UPSERT_BYTE) {
            // undo, upsert the old value if found, otherwise, physical delete
            if (logRecord.getOldValue() == null) {
                indexAccessor.forcePhysicalDelete(logRecord.getNewValue());
            } else {
                indexAccessor.forceUpsert(logRecord.getOldValue());
            }
        } else {
            throw new IllegalStateException("Unsupported OperationType: " + logRecord.getNewOp());
        }
    } catch (Exception e) {
        throw new IllegalStateException("Failed to undo", e);
    }
}
Also used : ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) ACIDException(org.apache.asterix.common.exceptions.ACIDException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IOException(java.io.IOException)

Example 20 with ILSMIndexAccessor

use of org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor 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)

Aggregations

ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)34 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)9 ILSMDiskComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent)8 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)8 ITreeIndexCursor (org.apache.hyracks.storage.am.common.api.ITreeIndexCursor)6 ArrayList (java.util.ArrayList)5 ILSMComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMComponent)4 ACIDException (org.apache.asterix.common.exceptions.ACIDException)3 IntegerSerializerDeserializer (org.apache.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer)3 LSMComponentFileReferences (org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentFileReferences)3 LSMTreeIndexAccessor (org.apache.hyracks.storage.am.lsm.common.impls.LSMTreeIndexAccessor)3 IModificationOperationCallback (org.apache.hyracks.storage.common.IModificationOperationCallback)3 IOException (java.io.IOException)2 AbstractLSMIOOperationCallback (org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback)2 ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)2 AMutableString (org.apache.asterix.om.base.AMutableString)2 AString (org.apache.asterix.om.base.AString)2 TransactionContext (org.apache.asterix.transaction.management.service.transaction.TransactionContext)2 UTF8StringSerializerDeserializer (org.apache.hyracks.dataflow.common.data.marshalling.UTF8StringSerializerDeserializer)2 OrderedIndexTestContext (org.apache.hyracks.storage.am.btree.OrderedIndexTestContext)2