Search in sources :

Example 21 with ITransactionContext

use of org.apache.asterix.common.transactions.ITransactionContext in project asterixdb by apache.

the class TempDatasetSecondaryIndexModificationOperationCallbackFactory 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<IIndex> 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 TempDatasetIndexModificationOperationCallback(new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp);
        txnCtx.registerIndexAndCallback(resource.getId(), index, (AbstractOperationCallback) modCallback, false);
        return modCallback;
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : DatasetLocalResource(org.apache.asterix.common.dataflow.DatasetLocalResource) IIndex(org.apache.hyracks.storage.common.IIndex) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ILSMIndex(org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex) ITransactionSubsystem(org.apache.asterix.common.transactions.ITransactionSubsystem) 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 22 with ITransactionContext

use of org.apache.asterix.common.transactions.ITransactionContext in project asterixdb by apache.

the class PrimaryIndexModificationOperationCallbackFactory method createModificationOperationCallback.

@Override
public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException {
    ITransactionSubsystem txnSubsystem = txnSubsystemProvider.getTransactionSubsystem(ctx);
    IResourceLifecycleManager<IIndex> 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);
        DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource();
        IModificationOperationCallback modCallback = new PrimaryIndexModificationOperationCallback(new DatasetId(datasetId), primaryKeyFields, txnCtx, txnSubsystem.getLockManager(), txnSubsystem, resource.getId(), aResource.getPartition(), resourceType, indexOp, operatorNodePushable);
        txnCtx.registerIndexAndCallback(resource.getId(), index, (AbstractOperationCallback) modCallback, true);
        return modCallback;
    } catch (ACIDException e) {
        throw new HyracksDataException(e);
    }
}
Also used : IIndex(org.apache.hyracks.storage.common.IIndex) 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) 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 23 with ITransactionContext

use of org.apache.asterix.common.transactions.ITransactionContext in project asterixdb by apache.

the class MetadataNode method lock.

@Override
public void lock(JobId jobId, byte lockMode) throws ACIDException, RemoteException {
    ITransactionContext txnCtx = transactionSubsystem.getTransactionManager().getTransactionContext(jobId, false);
    transactionSubsystem.getLockManager().lock(METADATA_DATASET_ID, -1, lockMode, txnCtx);
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext)

Example 24 with ITransactionContext

use of org.apache.asterix.common.transactions.ITransactionContext in project asterixdb by apache.

the class MetadataNode method abortTransaction.

@Override
public void abortTransaction(JobId jobId) throws RemoteException, ACIDException {
    try {
        ITransactionContext txnCtx = transactionSubsystem.getTransactionManager().getTransactionContext(jobId, false);
        transactionSubsystem.getTransactionManager().abortTransaction(txnCtx, DatasetId.NULL, -1);
    } catch (ACIDException e) {
        LOGGER.log(Level.WARNING, "Exception aborting transaction", e);
        throw e;
    }
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 25 with ITransactionContext

use of org.apache.asterix.common.transactions.ITransactionContext in project asterixdb by apache.

the class FlushDatasetOperatorDescriptor method createPushRuntime.

@Override
public IOperatorNodePushable createPushRuntime(final IHyracksTaskContext ctx, IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
    return new AbstractUnaryInputSinkOperatorNodePushable() {

        @Override
        public void open() throws HyracksDataException {
        }

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
        }

        @Override
        public void fail() throws HyracksDataException {
            this.close();
        }

        @Override
        public void close() throws HyracksDataException {
            try {
                INcApplicationContext appCtx = (INcApplicationContext) ctx.getJobletContext().getServiceContext().getApplicationContext();
                IDatasetLifecycleManager datasetLifeCycleManager = appCtx.getDatasetLifecycleManager();
                ILockManager lockManager = appCtx.getTransactionSubsystem().getLockManager();
                ITransactionManager txnManager = appCtx.getTransactionSubsystem().getTransactionManager();
                // get the local transaction
                ITransactionContext txnCtx = txnManager.getTransactionContext(jobId, false);
                // lock the dataset granule
                lockManager.lock(datasetId, -1, LockMode.S, txnCtx);
                // flush the dataset synchronously
                datasetLifeCycleManager.flushDataset(datasetId.getId(), false);
            } catch (ACIDException e) {
                throw new HyracksDataException(e);
            }
        }
    };
}
Also used : IDatasetLifecycleManager(org.apache.asterix.common.api.IDatasetLifecycleManager) AbstractUnaryInputSinkOperatorNodePushable(org.apache.hyracks.dataflow.std.base.AbstractUnaryInputSinkOperatorNodePushable) INcApplicationContext(org.apache.asterix.common.api.INcApplicationContext) ILockManager(org.apache.asterix.common.transactions.ILockManager) ITransactionManager(org.apache.asterix.common.transactions.ITransactionManager) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ByteBuffer(java.nio.ByteBuffer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)26 ACIDException (org.apache.asterix.common.exceptions.ACIDException)15 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)7 IModificationOperationCallback (org.apache.hyracks.storage.common.IModificationOperationCallback)7 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)6 DatasetLocalResource (org.apache.asterix.common.dataflow.DatasetLocalResource)5 DatasetId (org.apache.asterix.common.transactions.DatasetId)5 ITransactionSubsystem (org.apache.asterix.common.transactions.ITransactionSubsystem)5 INcApplicationContext (org.apache.asterix.common.api.INcApplicationContext)3 ITransactionManager (org.apache.asterix.common.transactions.ITransactionManager)3 JobId (org.apache.asterix.common.transactions.JobId)3 LogRecord (org.apache.asterix.common.transactions.LogRecord)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TestNodeController (org.apache.asterix.app.bootstrap.TestNodeController)2 TupleGenerator (org.apache.asterix.app.data.gen.TupleGenerator)2 LSMInsertDeleteOperatorNodePushable (org.apache.asterix.common.dataflow.LSMInsertDeleteOperatorNodePushable)2 ILogRecord (org.apache.asterix.common.transactions.ILogRecord)2 StorageComponentProvider (org.apache.asterix.file.StorageComponentProvider)2 Dataset (org.apache.asterix.metadata.entities.Dataset)2