Search in sources :

Example 1 with ITransactionContext

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

the class JobEventListenerFactory method createListener.

@Override
public IJobletEventListener createListener(final IHyracksJobletContext jobletContext) {
    return new IJobletEventListener() {

        @Override
        public void jobletFinish(JobStatus jobStatus) {
            try {
                ITransactionManager txnManager = ((INcApplicationContext) jobletContext.getServiceContext().getApplicationContext()).getTransactionSubsystem().getTransactionManager();
                ITransactionContext txnContext = txnManager.getTransactionContext(jobId, false);
                txnContext.setWriteTxn(transactionalWrite);
                txnManager.completedTransaction(txnContext, DatasetId.NULL, -1, !(jobStatus == JobStatus.FAILURE));
            } catch (ACIDException e) {
                throw new Error(e);
            }
        }

        @Override
        public void jobletStart() {
            try {
                ((INcApplicationContext) jobletContext.getServiceContext().getApplicationContext()).getTransactionSubsystem().getTransactionManager().getTransactionContext(jobId, true);
            } catch (ACIDException e) {
                throw new Error(e);
            }
        }
    };
}
Also used : JobStatus(org.apache.hyracks.api.job.JobStatus) INcApplicationContext(org.apache.asterix.common.api.INcApplicationContext) ITransactionManager(org.apache.asterix.common.transactions.ITransactionManager) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) IJobletEventListener(org.apache.hyracks.api.job.IJobletEventListener) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 2 with ITransactionContext

use of org.apache.asterix.common.transactions.ITransactionContext 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 ITransactionContext

use of org.apache.asterix.common.transactions.ITransactionContext 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 ITransactionContext

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

the class MetadataNode method beginTransaction.

@Override
public void beginTransaction(JobId transactionId) throws ACIDException, RemoteException {
    ITransactionContext txnCtx = transactionSubsystem.getTransactionManager().beginTransaction(transactionId);
    txnCtx.setMetadataTransaction(true);
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext)

Example 5 with ITransactionContext

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

the class MetadataNode method commitTransaction.

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

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