Search in sources :

Example 1 with ACIDException

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;
}
Also used : ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 2 with ACIDException

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());
    }
}
Also used : LogRecord(org.apache.asterix.common.transactions.LogRecord) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 3 with ACIDException

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);
    }
}
Also used : LogRecord(org.apache.asterix.common.transactions.LogRecord) ITransactionContext(org.apache.asterix.common.transactions.ITransactionContext) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 4 with ACIDException

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();
    }
}
Also used : IFrame(org.apache.hyracks.api.comm.IFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 5 with ACIDException

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);
    }
}
Also used : HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

ACIDException (org.apache.asterix.common.exceptions.ACIDException)70 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)54 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)31 ITransactionContext (org.apache.asterix.common.transactions.ITransactionContext)14 IOException (java.io.IOException)9 ILSMIndex (org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex)9 DatasetLocalResource (org.apache.asterix.common.dataflow.DatasetLocalResource)6 DatasetId (org.apache.asterix.common.transactions.DatasetId)5 ITransactionSubsystem (org.apache.asterix.common.transactions.ITransactionSubsystem)5 LogRecord (org.apache.asterix.common.transactions.LogRecord)5 RemoteException (java.rmi.RemoteException)4 Checkpoint (org.apache.asterix.common.transactions.Checkpoint)4 ILogRecord (org.apache.asterix.common.transactions.ILogRecord)4 IModificationOperationCallback (org.apache.hyracks.storage.common.IModificationOperationCallback)4 HashMap (java.util.HashMap)3 IDatasetLifecycleManager (org.apache.asterix.common.api.IDatasetLifecycleManager)3 INcApplicationContext (org.apache.asterix.common.api.INcApplicationContext)3 ITransactionManager (org.apache.asterix.common.transactions.ITransactionManager)3 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)3 IIndex (org.apache.hyracks.storage.common.IIndex)3