Search in sources :

Example 11 with ILSMIndexAccessor

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

the class CorrelatedPrefixMergePolicy method diskComponentAdded.

@Override
public void diskComponentAdded(final ILSMIndex index, boolean fullMergeIsRequested) throws HyracksDataException {
    if (fullMergeIsRequested) {
        //full merge request is handled by each index separately, since it is possible that
        //when a primary index wants to send full merge requests for all secondaries,
        //one secondary index is being merged and the request cannot be scheduled
        List<ILSMDiskComponent> immutableComponents = new ArrayList<>(index.getImmutableComponents());
        if (!areComponentsReadableUnwritableState(immutableComponents)) {
            return;
        }
        ILSMIndexAccessor accessor = index.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        accessor.scheduleFullMerge(index.getIOOperationCallback());
        return;
    }
    if (!index.isPrimaryIndex()) {
        return;
    }
    List<ILSMDiskComponent> immutableComponents = new ArrayList<>(index.getImmutableComponents());
    if (!areComponentsReadableUnwritableState(immutableComponents)) {
        return;
    }
    scheduleMerge(index);
}
Also used : ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) ArrayList(java.util.ArrayList) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)

Example 12 with ILSMIndexAccessor

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

the class CorrelatedPrefixMergePolicy method triggerScheduledMerge.

/**
     * Submit merge requests for all disk components within [minID, maxID]
     * of all indexes of a given dataset in the given partition
     *
     * @param minID
     * @param maxID
     * @param partition
     * @param indexInfos
     * @throws HyracksDataException
     */
private void triggerScheduledMerge(long minID, long maxID, Set<IndexInfo> indexInfos) throws HyracksDataException {
    for (IndexInfo info : indexInfos) {
        ILSMIndex lsmIndex = info.getIndex();
        List<ILSMDiskComponent> immutableComponents = new ArrayList<>(lsmIndex.getImmutableComponents());
        if (isMergeOngoing(immutableComponents)) {
            continue;
        }
        List<ILSMDiskComponent> mergableComponents = new ArrayList<>();
        for (ILSMDiskComponent component : immutableComponents) {
            ILSMDiskComponentId id = component.getComponentId();
            if (!id.notFound()) {
                if (id.getMinId() >= minID && id.getMaxId() <= maxID) {
                    mergableComponents.add(component);
                }
                if (id.getMaxId() < minID) {
                    //if the component.maxID < minID, we can safely skip the rest disk components in the list
                    break;
                }
            }
        }
        ILSMIndexAccessor accessor = lsmIndex.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        accessor.scheduleMerge(lsmIndex.getIOOperationCallback(), mergableComponents);
    }
}
Also used : ILSMDiskComponent(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent) ILSMDiskComponentId(org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId) ArrayList(java.util.ArrayList) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)

Example 13 with ILSMIndexAccessor

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

the class LSMInsertDeleteOperatorNodePushable method nextFrame.

@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
    currentTupleIdx = 0;
    lastFlushedTupleIdx = 0;
    flushedPartialTuples = false;
    accessor.reset(buffer);
    ILSMIndexAccessor lsmAccessor = (ILSMIndexAccessor) indexAccessor;
    int tupleCount = accessor.getTupleCount();
    try {
        for (; i < tupleCount; i++, currentTupleIdx++) {
            if (tupleFilter != null) {
                frameTuple.reset(accessor, i);
                if (!tupleFilter.accept(frameTuple)) {
                    continue;
                }
            }
            tuple.reset(accessor, i);
            switch(op) {
                case INSERT:
                    if (i == 0 && isPrimary) {
                        lsmAccessor.insert(tuple);
                    } else {
                        lsmAccessor.forceInsert(tuple);
                    }
                    break;
                case DELETE:
                    if (i == 0 && isPrimary) {
                        lsmAccessor.delete(tuple);
                    } else {
                        lsmAccessor.forceDelete(tuple);
                    }
                    break;
                default:
                    {
                        throw HyracksDataException.create(ErrorCode.INVALID_OPERATOR_OPERATION, op.toString(), LSMInsertDeleteOperatorNodePushable.class.getSimpleName());
                    }
            }
        }
    } catch (HyracksDataException e) {
        if (e.getErrorCode() == ErrorCode.INVALID_OPERATOR_OPERATION) {
            throw e;
        } else {
            throw HyracksDataException.create(ErrorCode.ERROR_PROCESSING_TUPLE, e, i);
        }
    } catch (Exception e) {
        throw HyracksDataException.create(ErrorCode.ERROR_PROCESSING_TUPLE, e, i);
    }
    writeBuffer.ensureFrameSize(buffer.capacity());
    if (flushedPartialTuples) {
        flushPartialFrame();
    } else {
        FrameUtils.copyAndFlip(buffer, writeBuffer.getBuffer());
        FrameUtils.flushFrame(writeBuffer.getBuffer(), writer);
    }
    i = 0;
}
Also used : ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 14 with ILSMIndexAccessor

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

the class DatasetLifecycleManager method flushDatasetOpenIndexes.

/*
     * This method can only be called asynchronously safely if we're sure no modify operation will take place until the flush is scheduled
     */
private void flushDatasetOpenIndexes(DatasetInfo dsInfo, boolean asyncFlush) throws HyracksDataException {
    if (!dsInfo.isExternal() && dsInfo.isDurable()) {
        synchronized (logRecord) {
            TransactionUtil.formFlushLogRecord(logRecord, dsInfo.getDatasetID(), null, logManager.getNodeId(), dsInfo.getIndexes().size());
            try {
                logManager.log(logRecord);
            } catch (ACIDException e) {
                throw new HyracksDataException("could not write flush log while closing dataset", e);
            }
            try {
                //notification will come from LogPage class (notifyFlushTerminator)
                logRecord.wait();
            } catch (InterruptedException e) {
                throw new HyracksDataException(e);
            }
        }
        for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
            //update resource lsn
            AbstractLSMIOOperationCallback ioOpCallback = (AbstractLSMIOOperationCallback) iInfo.getIndex().getIOOperationCallback();
            ioOpCallback.updateLastLSN(logRecord.getLSN());
        }
    }
    if (asyncFlush) {
        for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
            ILSMIndexAccessor accessor = iInfo.getIndex().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
            accessor.scheduleFlush(iInfo.getIndex().getIOOperationCallback());
        }
    } else {
        for (IndexInfo iInfo : dsInfo.getIndexes().values()) {
            // TODO: This is not efficient since we flush the indexes sequentially.
            // Think of a way to allow submitting the flush requests concurrently. We don't do them concurrently because this
            // may lead to a deadlock scenario between the DatasetLifeCycleManager and the PrimaryIndexOperationTracker.
            flushAndWaitForIO(dsInfo, iInfo);
        }
    }
}
Also used : AbstractLSMIOOperationCallback(org.apache.asterix.common.ioopcallbacks.AbstractLSMIOOperationCallback) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 15 with ILSMIndexAccessor

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

the class DatasetLifecycleManager method flushAndWaitForIO.

private static void flushAndWaitForIO(DatasetInfo dsInfo, IndexInfo iInfo) throws HyracksDataException {
    if (iInfo.isOpen()) {
        ILSMIndexAccessor accessor = iInfo.getIndex().createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
        accessor.scheduleFlush(iInfo.getIndex().getIOOperationCallback());
    }
    // Wait for the above flush op.
    synchronized (dsInfo) {
        while (dsInfo.getNumActiveIOOps() > 0) {
            try {
                //notification will come from DatasetInfo class (undeclareActiveIOOperation)
                dsInfo.wait();
            } catch (InterruptedException e) {
                throw new HyracksDataException(e);
            }
        }
    }
}
Also used : ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

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