use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.
the class TransactionManager method getTransactionContext.
@Override
public ITransactionContext getTransactionContext(JobId jobId, boolean createIfNotExist) throws ACIDException {
setMaxJobId(jobId.getId());
ITransactionContext txnCtx = transactionContextRepository.get(jobId);
if (txnCtx == null) {
if (createIfNotExist) {
synchronized (this) {
txnCtx = transactionContextRepository.get(jobId);
if (txnCtx == null) {
txnCtx = new TransactionContext(jobId);
transactionContextRepository.put(jobId, txnCtx);
}
}
} else {
throw new ACIDException("TransactionContext of " + jobId + " doesn't exist.");
}
}
return txnCtx;
}
use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.
the class TransactionManager method abortTransaction.
@Override
public void abortTransaction(ITransactionContext txnCtx, DatasetId datasetId, int PKHashVal) throws ACIDException {
if (txnCtx.getTxnState() != ITransactionManager.ABORTED) {
txnCtx.setTxnState(ITransactionManager.ABORTED);
}
try {
if (txnCtx.isWriteTxn()) {
LogRecord logRecord = ((TransactionContext) txnCtx).getLogRecord();
TransactionUtil.formJobTerminateLogRecord(txnCtx, logRecord, false);
txnSubsystem.getLogManager().log(logRecord);
txnSubsystem.getRecoveryManager().rollbackTransaction(txnCtx);
}
} catch (Exception ae) {
String msg = "Could not complete rollback! System is in an inconsistent state";
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.severe(msg);
}
ae.printStackTrace();
throw new ACIDException(msg, ae);
} finally {
((TransactionContext) txnCtx).cleanupForAbort();
txnSubsystem.getLockManager().releaseLocks(txnCtx);
transactionContextRepository.remove(txnCtx.getJobId());
}
}
use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.
the class TransactionManager method commitTransaction.
@Override
public void commitTransaction(ITransactionContext txnCtx, DatasetId datasetId, int PKHashVal) throws ACIDException {
//Only job-level commits call this method.
try {
if (txnCtx.isWriteTxn()) {
LogRecord logRecord = ((TransactionContext) txnCtx).getLogRecord();
TransactionUtil.formJobTerminateLogRecord(txnCtx, logRecord, true);
txnSubsystem.getLogManager().log(logRecord);
}
} catch (Exception ae) {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.severe(" caused exception in commit !" + txnCtx.getJobId());
}
throw ae;
} finally {
txnSubsystem.getLockManager().releaseLocks(txnCtx);
transactionContextRepository.remove(txnCtx.getJobId());
txnCtx.setTxnState(ITransactionManager.COMMITTED);
}
}
use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.
the class CommitRuntime method nextFrame.
@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
tAccess.reset(buffer);
int nTuple = tAccess.getTupleCount();
for (int t = 0; t < nTuple; t++) {
if (isTemporaryDatasetWriteJob) {
/**
* This "if branch" is for writes over temporary datasets. A temporary dataset does not require any lock
* and does not generate any write-ahead update and commit log but generates flush log and job commit
* log. However, a temporary dataset still MUST guarantee no-steal policy so that this notification call
* should be delivered to PrimaryIndexOptracker and used correctly in order to decrement number of
* active operation count of PrimaryIndexOptracker. By maintaining the count correctly and only allowing
* flushing when the count is 0, it can guarantee the no-steal policy for temporary datasets, too.
*/
// TODO: Fix this for upserts. an upsert tuple right now expect to notify the opTracker twice (one for
// delete and one for insert)
transactionContext.notifyOptracker(false);
} else {
tRef.reset(tAccess, t);
try {
formLogRecord(buffer, t);
logMgr.log(logRecord);
if (!isSink) {
appendTupleToFrame(t);
}
} catch (ACIDException e) {
throw new HyracksDataException(e);
}
}
}
IFrame message = TaskUtil.get(HyracksConstants.KEY_MESSAGE, ctx);
if (message != null && MessagingFrameTupleAppender.getMessageType(message) == MessagingFrameTupleAppender.MARKER_MESSAGE) {
try {
formMarkerLogRecords(message.getBuffer());
logMgr.log(logRecord);
} catch (ACIDException e) {
throw new HyracksDataException(e);
}
message.reset();
message.getBuffer().put(MessagingFrameTupleAppender.NULL_FEED_MESSAGE);
message.getBuffer().flip();
}
}
use of org.apache.asterix.common.exceptions.ACIDException in project asterixdb by apache.
the class UpsertOperationCallback method found.
@Override
public void found(ITupleReference before, ITupleReference after) throws HyracksDataException {
try {
int pkHash = computePrimaryKeyHashValue(after, primaryKeyFields);
log(pkHash, after, before);
} catch (ACIDException e) {
throw new HyracksDataException(e);
}
}
Aggregations