Search in sources :

Example 1 with ILSMIndex

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

the class UpsertOperationCallbackFactory method createModificationOperationCallback.

@Override
public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException {
    DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource();
    ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx);
    IResourceLifecycleManager indexLifeCycleManager = txnSubsystem.getAsterixAppRuntimeContextProvider().getDatasetLifecycleManager();
    ILSMIndex index = (ILSMIndex) indexLifeCycleManager.get(resource.getPath());
    if (index == null) {
        throw new HyracksDataException("Index(id:" + resource.getId() + ") is not registered.");
    }
    try {
        ITransactionContext txnCtx = txnSubsystem.getTransactionManager().getTransactionContext(jobId, false);
        IModificationOperationCallback modCallback = new UpsertOperationCallback(new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp);
        txnCtx.registerIndexAndCallback(resource.getId(), index, (AbstractOperationCallback) modCallback, true);
        return modCallback;
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ITransactionSubsystem(org.apache.asterix.common.transactions.ITransactionSubsystem) IResourceLifecycleManager(org.apache.hyracks.storage.common.IResourceLifecycleManager) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback) DatasetId(org.apache.asterix.common.transactions.DatasetId) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 2 with ILSMIndex

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

the class MetadataNode method insertTupleIntoIndex.

private void insertTupleIntoIndex(JobId jobId, IMetadataIndex metadataIndex, ITupleReference tuple) throws ACIDException, HyracksDataException {
    long resourceID = metadataIndex.getResourceId();
    String resourceName = metadataIndex.getFile().getRelativePath();
    ILSMIndex lsmIndex = (ILSMIndex) datasetLifecycleManager.get(resourceName);
    try {
        datasetLifecycleManager.open(resourceName);
        // prepare a Callback for logging
        IModificationOperationCallback modCallback = createIndexModificationCallback(jobId, resourceID, metadataIndex, lsmIndex, Operation.INSERT);
        ILSMIndexAccessor indexAccessor = lsmIndex.createAccessor(modCallback, NoOpOperationCallback.INSTANCE);
        ITransactionContext txnCtx = transactionSubsystem.getTransactionManager().getTransactionContext(jobId, false);
        txnCtx.setWriteTxn(true);
        txnCtx.registerIndexAndCallback(resourceID, lsmIndex, (AbstractOperationCallback) modCallback, metadataIndex.isPrimaryIndex());
        LSMIndexUtil.checkAndSetFirstLSN((AbstractLSMIndex) lsmIndex, transactionSubsystem.getLogManager());
        // TODO: fix exceptions once new BTree exception model is in hyracks.
        indexAccessor.forceInsert(tuple);
        //by the job commit log event
        if (!((TransactionContext) txnCtx).getPrimaryIndexOpTracker().equals(lsmIndex.getOperationTracker())) {
            lsmIndex.getOperationTracker().completeOperation(lsmIndex, LSMOperationType.FORCE_MODIFICATION, null, modCallback);
        }
    } finally {
        datasetLifecycleManager.close(resourceName);
    }
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) TransactionContext(org.apache.asterix.transaction.management.service.transaction.TransactionContext) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback)

Example 3 with ILSMIndex

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

the class MetadataNode method deleteTupleFromIndex.

private void deleteTupleFromIndex(JobId jobId, IMetadataIndex metadataIndex, ITupleReference tuple) throws ACIDException, HyracksDataException {
    long resourceID = metadataIndex.getResourceId();
    String resourceName = metadataIndex.getFile().getRelativePath();
    ILSMIndex lsmIndex = (ILSMIndex) datasetLifecycleManager.get(resourceName);
    try {
        datasetLifecycleManager.open(resourceName);
        // prepare a Callback for logging
        IModificationOperationCallback modCallback = createIndexModificationCallback(jobId, resourceID, metadataIndex, lsmIndex, Operation.DELETE);
        ILSMIndexAccessor indexAccessor = lsmIndex.createAccessor(modCallback, NoOpOperationCallback.INSTANCE);
        ITransactionContext txnCtx = transactionSubsystem.getTransactionManager().getTransactionContext(jobId, false);
        txnCtx.setWriteTxn(true);
        txnCtx.registerIndexAndCallback(resourceID, lsmIndex, (AbstractOperationCallback) modCallback, metadataIndex.isPrimaryIndex());
        LSMIndexUtil.checkAndSetFirstLSN((AbstractLSMIndex) lsmIndex, transactionSubsystem.getLogManager());
        indexAccessor.forceDelete(tuple);
        //by the job commit log event
        if (!((TransactionContext) txnCtx).getPrimaryIndexOpTracker().equals(lsmIndex.getOperationTracker())) {
            lsmIndex.getOperationTracker().completeOperation(lsmIndex, LSMOperationType.FORCE_MODIFICATION, null, modCallback);
        }
    } finally {
        datasetLifecycleManager.close(resourceName);
    }
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) TransactionContext(org.apache.asterix.transaction.management.service.transaction.TransactionContext) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) ILSMIndexAccessor(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor) IModificationOperationCallback(org.apache.hyracks.storage.common.IModificationOperationCallback)

Example 4 with ILSMIndex

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

the class LSMIndexCompactOperatorNodePushable method initialize.

@Override
public void initialize() throws HyracksDataException {
    indexHelper.open();
    ILSMIndex index = (ILSMIndex) indexHelper.getIndexInstance();
    ILSMIndexAccessor accessor = index.createAccessor(NoOpOperationCallback.INSTANCE, NoOpOperationCallback.INSTANCE);
    try {
        accessor.scheduleFullMerge(NoOpIOOperationCallbackFactory.INSTANCE.createIoOpCallback());
    } catch (Exception e) {
        indexHelper.close();
        throw new HyracksDataException(e);
    }
}
Also used : ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) 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 5 with ILSMIndex

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

Aggregations

ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)15 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)11 ACIDException (org.apache.asterix.common.exceptions.ACIDException)9 ILSMIndexAccessor (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor)8 IModificationOperationCallback (org.apache.hyracks.storage.common.IModificationOperationCallback)8 ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)7 DatasetLocalResource (org.apache.asterix.common.dataflow.DatasetLocalResource)6 DatasetId (org.apache.asterix.common.transactions.DatasetId)5 ITransactionSubsystem (org.apache.asterix.common.transactions.ITransactionSubsystem)5 IResourceLifecycleManager (org.apache.hyracks.storage.common.IResourceLifecycleManager)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)2 Checkpoint (org.apache.asterix.common.transactions.Checkpoint)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 ILSMDiskComponent (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent)2 ILSMDiskComponentId (org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentId)2