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();
}
}
}
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);
}
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);
}
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);
}
}
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);
}
}
Aggregations