use of javax.transaction.xa.XAException 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.xa.XAException in project graphdb by neo4j-attic.
the class XaLogicalLog method done.
// [DONE][identifier]
public synchronized void done(int identifier) throws XAException {
if (backupSlave) {
return;
}
assert xidIdentMap.get(identifier) != null;
try {
LogIoUtils.writeDone(writeBuffer, identifier);
xidIdentMap.remove(identifier);
} catch (IOException e) {
throw new XAException("Logical log unable to mark as done [" + identifier + "] " + e);
}
}
use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.
the class XaLogicalLog method applyTwoPhaseCommitEntry.
private void applyTwoPhaseCommitEntry(LogEntry.TwoPhaseCommit commit) throws IOException {
int identifier = commit.getIdentifier();
long txId = commit.getTxId();
LogEntry.Start startEntry = xidIdentMap.get(identifier);
if (startEntry == null) {
throw new IOException("Unknown xid for identifier " + identifier);
}
Xid xid = startEntry.getXid();
if (xid == null) {
throw new IOException("Xid null for identifier " + identifier);
}
try {
XaTransaction xaTx = xaRm.getXaTransaction(xid);
xaTx.setCommitTxId(txId);
xaRm.injectTwoPhaseCommit(xid);
msgLog.logMessage("Injected two phase commit, txId=" + commit.getTxId(), true);
} catch (XAException e) {
e.printStackTrace();
throw new IOException(e.getMessage());
}
}
use of javax.transaction.xa.XAException in project neo4j-mobile-android by neo4j-contrib.
the class XaDataSourceManager method getBranchId.
synchronized byte[] getBranchId(XAResource xaResource) {
if (xaResource instanceof XaResource) {
byte[] branchId = ((XaResource) xaResource).getBranchId();
if (branchId != null) {
return branchId;
}
}
Iterator<Map.Entry<String, XaDataSource>> itr = dataSources.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry<String, XaDataSource> entry = itr.next();
XaDataSource dataSource = entry.getValue();
XAResource resource = dataSource.getXaConnection().getXaResource();
try {
if (resource.isSameRM(xaResource)) {
String name = entry.getKey();
return sourceIdMapping.get(name);
}
} catch (XAException e) {
throw new TransactionFailureException("Unable to check is same resource", e);
}
}
throw new TransactionFailureException("Unable to find mapping for XAResource[" + xaResource + "]");
}
use of javax.transaction.xa.XAException in project neo4j-mobile-android by neo4j-contrib.
the class XaLogicalLog method applyOnePhaseCommitEntry.
private void applyOnePhaseCommitEntry(LogEntry.OnePhaseCommit commit) throws IOException {
int identifier = commit.getIdentifier();
long txId = commit.getTxId();
LogEntry.Start startEntry = xidIdentMap.get(identifier);
if (startEntry == null) {
throw new IOException("Unknown xid for identifier " + identifier);
}
Xid xid = startEntry.getXid();
try {
XaTransaction xaTx = xaRm.getXaTransaction(xid);
xaTx.setCommitTxId(txId);
xaRm.injectOnePhaseCommit(xid);
registerRecoveredTransaction(txId);
} catch (XAException e) {
throw new IOException(e);
}
}
Aggregations