use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.
the class XaResourceManager method checkXids.
synchronized void checkXids() throws IOException {
msgLog.logMessage("XaResourceManager[" + name + "] sorting " + xidMap.size() + " xids");
Iterator<Xid> keyIterator = xidMap.keySet().iterator();
LinkedList<Xid> xids = new LinkedList<Xid>();
while (keyIterator.hasNext()) {
xids.add(keyIterator.next());
}
// comparator only used here
Collections.sort(xids, new Comparator<Xid>() {
public int compare(Xid o1, Xid o2) {
Integer id1 = txOrderMap.get(o1);
Integer id2 = txOrderMap.get(o2);
if (id1 == null && id2 == null) {
return 0;
}
if (id1 == null) {
return Integer.MAX_VALUE;
}
if (id2 == null) {
return Integer.MIN_VALUE;
}
return id1 - id2;
}
});
// = null;
txOrderMap.clear();
Logger logger = Logger.getLogger(tf.getClass().getName());
while (!xids.isEmpty()) {
Xid xid = xids.removeFirst();
XidStatus status = xidMap.get(xid);
TransactionStatus txStatus = status.getTransactionStatus();
XaTransaction xaTransaction = txStatus.getTransaction();
int identifier = xaTransaction.getIdentifier();
if (xaTransaction.isRecovered()) {
if (txStatus.commitStarted()) {
logger.fine("Marking 1PC [" + name + "] tx " + identifier + " as done");
log.doneInternal(identifier);
xidMap.remove(xid);
recoveredTxCount--;
} else if (!txStatus.prepared()) {
logger.fine("Rolling back non prepared tx [" + name + "]" + "txIdent[" + identifier + "]");
log.doneInternal(xaTransaction.getIdentifier());
xidMap.remove(xid);
recoveredTxCount--;
} else {
logger.fine("2PC tx [" + name + "] " + txStatus + " txIdent[" + identifier + "]");
}
}
}
checkIfRecoveryComplete();
}
use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.
the class LogIoUtils method readTxStartEntry.
private static LogEntry.Start readTxStartEntry(ByteBuffer buf, ReadableByteChannel channel) throws IOException, ReadPastEndException {
byte globalIdLength = readNextByte(buf, channel);
byte branchIdLength = readNextByte(buf, channel);
byte[] globalId = new byte[globalIdLength];
readIntoBufferAndFlip(ByteBuffer.wrap(globalId), channel, globalIdLength);
byte[] branchId = new byte[branchIdLength];
readIntoBufferAndFlip(ByteBuffer.wrap(branchId), channel, branchIdLength);
int identifier = readNextInt(buf, channel);
int formatId = readNextInt(buf, channel);
// re-create the transaction
Xid xid = new XidImpl(globalId, branchId, formatId);
return new LogEntry.Start(xid, identifier, -1);
}
use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.
the class XaLogicalLog method applyDoneEntry.
private void applyDoneEntry(LogEntry.Done done) throws IOException {
// get the tx identifier
int identifier = done.getIdentifier();
LogEntry.Start entry = xidIdentMap.get(identifier);
if (entry == null) {
throw new IOException("Unknown xid for identifier " + identifier);
}
Xid xid = entry.getXid();
xaRm.pruneXid(xid);
xidIdentMap.remove(identifier);
recoveredTxMap.remove(identifier);
}
use of javax.transaction.xa.Xid in project graphdb by neo4j-attic.
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 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());
}
}
Aggregations