Search in sources :

Example 16 with ITransactionContext

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

the class LogBuffer method batchUnlock.

private void batchUnlock(int beginOffset, int endOffset) throws ACIDException {
    if (endOffset > beginOffset) {
        logBufferTailReader.initializeScan(beginOffset, endOffset);
        ITransactionContext txnCtx = null;
        LogRecord logRecord = logBufferTailReader.next();
        while (logRecord != null) {
            if (logRecord.getLogSource() == LogSource.LOCAL) {
                if (logRecord.getLogType() == LogType.ENTITY_COMMIT) {
                    reusableJobId.setId(logRecord.getJobId());
                    reusableDatasetId.setId(logRecord.getDatasetId());
                    txnCtx = txnSubsystem.getTransactionManager().getTransactionContext(reusableJobId, false);
                    txnSubsystem.getLockManager().unlock(reusableDatasetId, logRecord.getPKHashValue(), LockMode.ANY, txnCtx);
                    txnCtx.notifyOptracker(false);
                    if (txnSubsystem.getTransactionProperties().isCommitProfilerEnabled()) {
                        txnSubsystem.incrementEntityCommitCount();
                    }
                } else if (logRecord.getLogType() == LogType.JOB_COMMIT || logRecord.getLogType() == LogType.ABORT) {
                    reusableJobId.setId(logRecord.getJobId());
                    txnCtx = txnSubsystem.getTransactionManager().getTransactionContext(reusableJobId, false);
                    txnCtx.notifyOptracker(true);
                    notifyJobTermination();
                } else if (logRecord.getLogType() == LogType.FLUSH) {
                    notifyFlushTermination();
                } else if (logRecord.getLogType() == LogType.WAIT) {
                    notifyWaitTermination();
                }
            } else if (logRecord.getLogSource() == LogSource.REMOTE) {
                if (logRecord.getLogType() == LogType.JOB_COMMIT || logRecord.getLogType() == LogType.ABORT) {
                    notifyReplicationTermination();
                }
            }
            logRecord = logBufferTailReader.next();
        }
    }
}
Also used : ILogRecord(org.apache.asterix.common.transactions.ILogRecord) LogRecord(org.apache.asterix.common.transactions.LogRecord) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext)

Example 17 with ITransactionContext

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

the class LogManagerWithReplication method syncAppendToLogTail.

@Override
protected synchronized void syncAppendToLogTail(ILogRecord logRecord) throws ACIDException {
    if (logRecord.getLogSource() == LogSource.LOCAL && logRecord.getLogType() != LogType.FLUSH) {
        ITransactionContext txnCtx = logRecord.getTxnCtx();
        if (txnCtx.getTxnState() == ITransactionManager.ABORTED && logRecord.getLogType() != LogType.ABORT) {
            throw new ACIDException("Aborted job(" + txnCtx.getJobId() + ") tried to write non-abort type log record.");
        }
    }
    final int logRecordSize = logRecord.getLogSize();
    // Make sure the log will not exceed the log file size
    if (getLogFileOffset(appendLSN.get()) + logRecordSize >= logFileSize) {
        prepareNextLogFile();
        prepareNextPage(logRecordSize);
    } else if (!appendPage.hasSpace(logRecordSize)) {
        prepareNextPage(logRecordSize);
    }
    appendPage.append(logRecord, appendLSN.get());
    if (logRecord.getLogType() == LogType.FLUSH) {
        logRecord.setLSN(appendLSN.get());
    }
    appendLSN.addAndGet(logRecordSize);
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 18 with ITransactionContext

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

the class LockManagerUnitTest method j.

private ITransactionContext j(int jId) {
    if (!jobId2TxnCtxMap.containsKey(jId)) {
        ITransactionContext mockTxnContext = mock(ITransactionContext.class);
        when(mockTxnContext.getJobId()).thenReturn(new JobId(jId));
        jobId2TxnCtxMap.put(jId, mockTxnContext);
    }
    return jobId2TxnCtxMap.get(jId);
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) JobId(org.apache.asterix.common.transactions.JobId)

Example 19 with ITransactionContext

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

the class SecondaryIndexModificationOperationCallbackFactory method createModificationOperationCallback.

@Override
public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException {
    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);
        DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource();
        IModificationOperationCallback modCallback = new SecondaryIndexModificationOperationCallback(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) 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 20 with ITransactionContext

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

the class TempDatasetPrimaryIndexModificationOperationCallbackFactory method createModificationOperationCallback.

@Override
public IModificationOperationCallback createModificationOperationCallback(LocalResource resource, IHyracksTaskContext ctx, IOperatorNodePushable operatorNodePushable) throws HyracksDataException {
    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);
        DatasetLocalResource aResource = (DatasetLocalResource) resource.getResource();
        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, 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)

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