Search in sources :

Example 6 with SystemException

use of javax.transaction.SystemException in project graphdb by neo4j-attic.

the class TxManager method commit.

private void commit(Thread thread, TransactionImpl tx) throws SystemException, HeuristicMixedException, HeuristicRollbackException {
    // mark as commit in log done TxImpl.doCommit()
    Throwable commitFailureCause = null;
    int xaErrorCode = -1;
    if (tx.getResourceCount() == 0) {
        tx.setStatus(Status.STATUS_COMMITTED);
    } else {
        try {
            tx.doCommit();
        } catch (XAException e) {
            xaErrorCode = e.errorCode;
            e.printStackTrace();
            log.severe("Commit failed, status=" + getTxStatusAsString(tx.getStatus()) + ", errorCode=" + xaErrorCode);
            if (tx.getStatus() == Status.STATUS_COMMITTED) {
                // this should never be
                setTmNotOk();
                throw new TransactionFailureException("commit threw exception but status is committed?", e);
            }
        } catch (Throwable t) {
            t.printStackTrace();
            commitFailureCause = t;
        }
    }
    if (tx.getStatus() != Status.STATUS_COMMITTED) {
        try {
            tx.doRollback();
        } catch (XAException e) {
            e.printStackTrace();
            log.severe("Unable to rollback transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
            setTmNotOk();
            if (commitFailureCause != null) {
                commitFailureCause.printStackTrace();
            }
            throw new HeuristicMixedException("Unable to rollback ---> error code in commit: " + xaErrorCode + " ---> error code for rollback: " + e.errorCode);
        }
        tx.doAfterCompletion();
        txThreadMap.remove(thread);
        try {
            if (tx.isGlobalStartRecordWritten()) {
                getTxLog().txDone(tx.getGlobalId());
            }
        } catch (IOException e) {
            e.printStackTrace();
            log.severe("Error writing transaction log");
            setTmNotOk();
            throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
        }
        tx.setStatus(Status.STATUS_NO_TRANSACTION);
        if (commitFailureCause == null) {
            throw new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + "error code was: " + xaErrorCode);
        } else {
            throw new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + commitFailureCause);
        }
    }
    tx.doAfterCompletion();
    txThreadMap.remove(thread);
    try {
        if (tx.isGlobalStartRecordWritten()) {
            getTxLog().txDone(tx.getGlobalId());
        }
    } catch (IOException e) {
        e.printStackTrace();
        log.severe("Error writing transaction log");
        setTmNotOk();
        throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
    }
    tx.setStatus(Status.STATUS_NO_TRANSACTION);
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) IOException(java.io.IOException)

Example 7 with SystemException

use of javax.transaction.SystemException in project graphdb by neo4j-attic.

the class IndexConnectionBroker method delistResourcesForTransaction.

void delistResourcesForTransaction() throws NotInTransactionException {
    Transaction tx = this.getCurrentTransaction();
    if (tx == null) {
        throw new NotInTransactionException();
    }
    T con = txConnectionMap.get(tx);
    if (con != null) {
        try {
            tx.delistResource(con.getXaResource(), XAResource.TMSUCCESS);
        } catch (IllegalStateException e) {
            throw new RuntimeException("Unable to delist lucene resource from tx", e);
        } catch (SystemException e) {
            throw new RuntimeException("Unable to delist lucene resource from tx", e);
        }
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Example 8 with SystemException

use of javax.transaction.SystemException in project graphdb by neo4j-attic.

the class ReadOnlyTxManager method rollback.

public void rollback() throws IllegalStateException, SystemException {
    Thread thread = Thread.currentThread();
    ReadOnlyTransactionImpl tx = txThreadMap.get(thread);
    if (tx == null) {
        throw new IllegalStateException("Not in transaction");
    }
    if (tx.getStatus() == Status.STATUS_ACTIVE || tx.getStatus() == Status.STATUS_MARKED_ROLLBACK || tx.getStatus() == Status.STATUS_PREPARING) {
        tx.doBeforeCompletion();
        try {
            tx.doRollback();
        } catch (XAException e) {
            e.printStackTrace();
            log.severe("Unable to rollback marked or active transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
            throw new SystemException("Unable to rollback " + " ---> error code for rollback: " + e.errorCode);
        }
        tx.doAfterCompletion();
        txThreadMap.remove(thread);
        tx.setStatus(Status.STATUS_NO_TRANSACTION);
    } else {
        throw new IllegalStateException("Tx status is: " + getTxStatusAsString(tx.getStatus()));
    }
}
Also used : XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException)

Example 9 with SystemException

use of javax.transaction.SystemException in project graphdb by neo4j-attic.

the class TxManager method rollback.

public void rollback() throws IllegalStateException, SystemException {
    if (!tmOk) {
        throw new SystemException("TM has encountered some problem, " + "please perform neccesary action (tx recovery/restart)");
    }
    Thread thread = Thread.currentThread();
    TransactionImpl tx = txThreadMap.get(thread);
    if (tx == null) {
        throw new IllegalStateException("Not in transaction");
    }
    boolean hasAnyLocks = false;
    try {
        hasAnyLocks = finishHook.hasAnyLocks(tx);
        if (tx.getStatus() == Status.STATUS_ACTIVE || tx.getStatus() == Status.STATUS_MARKED_ROLLBACK || tx.getStatus() == Status.STATUS_PREPARING) {
            tx.setStatus(Status.STATUS_MARKED_ROLLBACK);
            tx.doBeforeCompletion();
            // delist resources?
            try {
                rolledBackTxCount.incrementAndGet();
                tx.doRollback();
            } catch (XAException e) {
                e.printStackTrace();
                log.severe("Unable to rollback marked or active transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
                setTmNotOk();
                throw new SystemException("Unable to rollback " + " ---> error code for rollback: " + e.errorCode);
            }
            tx.doAfterCompletion();
            txThreadMap.remove(thread);
            try {
                if (tx.isGlobalStartRecordWritten()) {
                    getTxLog().txDone(tx.getGlobalId());
                }
            } catch (IOException e) {
                e.printStackTrace();
                log.severe("Error writing transaction log");
                setTmNotOk();
                throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
            }
            tx.setStatus(Status.STATUS_NO_TRANSACTION);
        } else {
            throw new IllegalStateException("Tx status is: " + getTxStatusAsString(tx.getStatus()));
        }
    } finally {
        if (hasAnyLocks) {
            finishHook.finishTransaction(tx.getEventIdentifier());
        }
    }
}
Also used : XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) IOException(java.io.IOException)

Example 10 with SystemException

use of javax.transaction.SystemException in project graphdb by neo4j-attic.

the class PersistenceManager method delistResourcesForTransaction.

void delistResourcesForTransaction() throws NotInTransactionException {
    Transaction tx = this.getCurrentTransaction();
    if (tx == null) {
        throw new NotInTransactionException();
    }
    ResourceConnection con = txConnectionMap.get(tx);
    if (con != null) {
        try {
            tx.delistResource(con.getXAResource(), XAResource.TMSUCCESS);
        } catch (SystemException e) {
            throw new TransactionFailureException("Failed to delist resource '" + con + "' from current transaction.", e);
        }
    }
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException)

Aggregations

SystemException (javax.transaction.SystemException)102 Transaction (javax.transaction.Transaction)34 RollbackException (javax.transaction.RollbackException)29 NotSupportedException (javax.transaction.NotSupportedException)22 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)18 IOException (java.io.IOException)16 HeuristicMixedException (javax.transaction.HeuristicMixedException)16 UserTransaction (javax.transaction.UserTransaction)14 XAException (javax.transaction.xa.XAException)13 Test (org.junit.Test)12 TransactionManager (javax.transaction.TransactionManager)11 SQLException (java.sql.SQLException)10 LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)10 InvalidTransactionException (javax.transaction.InvalidTransactionException)9 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)8 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)8 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)8 XAResource (javax.transaction.xa.XAResource)7 Synchronization (javax.transaction.Synchronization)6 File (java.io.File)5