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