use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.
the class XaLogicalLog method applyStartEntry.
private void applyStartEntry(LogEntry.Start entry) throws IOException {
int identifier = entry.getIdentifier();
if (identifier >= nextIdentifier) {
nextIdentifier = (identifier + 1);
}
// re-create the transaction
Xid xid = entry.getXid();
xidIdentMap.put(identifier, entry);
XaTransaction xaTx = xaTf.create(identifier);
xaTx.setRecovered();
recoveredTxMap.put(identifier, xaTx);
xaRm.injectStart(xid, xaTx);
// force to make sure done record is there if 2PC tx and global log
// marks tx as committed
fileChannel.force(false);
}
use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.
the class XaResourceManager method fail.
synchronized void fail(XAResource xaResource, Xid xid) throws XAException {
if (xidMap.get(xid) == null) {
throw new XAException("Unknown xid[" + xid + "]");
}
Xid xidEntry = xaResourceMap.remove(xaResource);
if (xidEntry == null) {
throw new XAException("Resource[" + xaResource + "] not enlisted");
}
XidStatus status = xidMap.get(xid);
status.getTransactionStatus().markAsRollback();
}
use of javax.transaction.xa.Xid in project neo4j-mobile-android by neo4j-contrib.
the class XaLogicalLog method applyPrepareEntry.
private void applyPrepareEntry(LogEntry.Prepare prepareEntry) throws IOException {
// get the tx identifier
int identifier = prepareEntry.getIdentifier();
LogEntry.Start entry = xidIdentMap.get(identifier);
if (entry == null) {
throw new IOException("Unknown xid for identifier " + identifier);
}
Xid xid = entry.getXid();
if (xaRm.injectPrepare(xid)) {
// read only we can remove
xidIdentMap.remove(identifier);
recoveredTxMap.remove(identifier);
}
}
use of javax.transaction.xa.Xid in project neo4j-mobile-android by neo4j-contrib.
the class XaLogicalLog method applyTransactionWithoutTxId.
public synchronized void applyTransactionWithoutTxId(ReadableByteChannel byteChannel, long nextTxId, int masterId) throws IOException {
if (nextTxId != (xaTf.getLastCommittedTx() + 1)) {
throw new IllegalStateException("Tried to apply tx " + nextTxId + " but expected transaction " + (xaTf.getCurrentVersion() + 1));
}
logRecoveryMessage("applyTxWithoutTxId log version: " + logVersion + ", committing tx=" + nextTxId + ") @ pos " + writeBuffer.getFileChannelPosition());
long logEntriesFound = 0;
scanIsComplete = false;
LogApplier logApplier = new LogApplier(byteChannel);
int xidIdent = getNextIdentifier();
long startEntryPosition = writeBuffer.getFileChannelPosition();
while (logApplier.readAndWriteAndApplyEntry(xidIdent)) {
logEntriesFound++;
}
byteChannel.close();
LogEntry.Start startEntry = logApplier.startEntry;
if (startEntry == null) {
throw new IOException("Unable to find start entry");
}
startEntry.setStartPosition(startEntryPosition);
// System.out.println( "applyTxWithoutTxId#before 1PC @ pos: " + writeBuffer.getFileChannelPosition() );
LogEntry.OnePhaseCommit commit = new LogEntry.OnePhaseCommit(xidIdent, nextTxId, masterId);
LogIoUtils.writeLogEntry(commit, writeBuffer);
// need to manually force since xaRm.commit will not do it (transaction marked as recovered)
writeBuffer.force();
Xid xid = startEntry.getXid();
try {
XaTransaction xaTx = xaRm.getXaTransaction(xid);
xaTx.setCommitTxId(nextTxId);
xaRm.commit(xid, true);
LogEntry doneEntry = new LogEntry.Done(startEntry.getIdentifier());
LogIoUtils.writeLogEntry(doneEntry, writeBuffer);
xidIdentMap.remove(startEntry.getIdentifier());
recoveredTxMap.remove(startEntry.getIdentifier());
cacheTxStartPosition(nextTxId, masterId, startEntry);
} catch (XAException e) {
throw new IOException(e);
}
// LogEntry.Done done = new LogEntry.Done( entry.getIdentifier() );
// LogIoUtils.writeLogEntry( done, writeBuffer );
// xaTf.setLastCommittedTx( nextTxId ); // done in doCommit
scanIsComplete = true;
// log.info( "Tx[" + nextTxId + "] " + " applied successfully." );
logRecoveryMessage("Applied external tx and generated tx id=" + nextTxId);
checkLogRotation();
// System.out.println( "applyTxWithoutTxId#end @ pos: " + writeBuffer.getFileChannelPosition() );
}
use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.
the class ReadOnlyTransactionImpl method enlistResource.
public synchronized boolean enlistResource(XAResource xaRes) throws RollbackException, IllegalStateException {
if (xaRes == null) {
throw new IllegalArgumentException("Null xa resource");
}
if (status == Status.STATUS_ACTIVE || status == Status.STATUS_PREPARING) {
try {
if (resourceList.size() == 0) {
//
byte[] branchId = txManager.getBranchId(xaRes);
Xid xid = new XidImpl(globalId, branchId);
resourceList.add(new ResourceElement(xid, xaRes));
xaRes.start(xid, XAResource.TMNOFLAGS);
return true;
}
Xid sameRmXid = null;
Iterator<ResourceElement> itr = resourceList.iterator();
while (itr.hasNext()) {
ResourceElement re = itr.next();
if (sameRmXid == null && re.getResource().isSameRM(xaRes)) {
sameRmXid = re.getXid();
}
if (xaRes == re.getResource()) {
if (re.getStatus() == RS_SUSPENDED) {
xaRes.start(re.getXid(), XAResource.TMRESUME);
} else {
// either enlisted or delisted
// is TMJOIN correct then?
xaRes.start(re.getXid(), XAResource.TMJOIN);
}
re.setStatus(RS_ENLISTED);
return true;
}
}
if (// should we join?
sameRmXid != null) {
resourceList.add(new ResourceElement(sameRmXid, xaRes));
xaRes.start(sameRmXid, XAResource.TMJOIN);
} else // new branch
{
// ResourceElement re = resourceList.getFirst();
byte[] branchId = txManager.getBranchId(xaRes);
Xid xid = new XidImpl(globalId, branchId);
resourceList.add(new ResourceElement(xid, xaRes));
xaRes.start(xid, XAResource.TMNOFLAGS);
}
return true;
} catch (XAException e) {
e.printStackTrace();
log.severe("Unable to enlist resource[" + xaRes + "]");
status = Status.STATUS_MARKED_ROLLBACK;
return false;
}
} else if (status == Status.STATUS_ROLLING_BACK || status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_MARKED_ROLLBACK) {
throw new RollbackException("Tx status is: " + txManager.getTxStatusAsString(status));
}
throw new IllegalStateException("Tx status is: " + txManager.getTxStatusAsString(status));
}
Aggregations