use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.
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 graphdb by neo4j-attic.
the class XaLogicalLog method commitTwoPhase.
// [TX_2P_COMMIT][identifier]
public synchronized void commitTwoPhase(int identifier, long txId, int masterId) throws XAException {
LogEntry.Start startEntry = xidIdentMap.get(identifier);
assert startEntry != null;
assert txId != -1;
try {
LogIoUtils.writeCommit(true, writeBuffer, identifier, txId, masterId);
writeBuffer.force();
cacheTxStartPosition(txId, masterId, startEntry);
} catch (IOException e) {
throw new XAException("Logical log unable to mark 2PC [" + identifier + "] " + e);
}
}
use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.
the class XaLogicalLog method start.
// returns identifier for transaction
// [TX_START][xid[gid.length,bid.lengh,gid,bid]][identifier][format id]
public synchronized int start(Xid xid) throws XAException {
if (backupSlave) {
throw new XAException("Resource is configured as backup slave, " + "no new transactions can be started for " + fileName + "." + currentLog);
}
int xidIdent = getNextIdentifier();
try {
long position = writeBuffer.getFileChannelPosition();
LogEntry.Start start = new LogEntry.Start(xid, xidIdent, position);
LogIoUtils.writeStart(writeBuffer, xidIdent, xid);
xidIdentMap.put(xidIdent, start);
} catch (IOException e) {
throw new XAException("Logical log couldn't start transaction: " + e);
}
return xidIdent;
}
use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.
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);
msgLog.logMessage("Injected one phase commit, txId=" + commit.getTxId(), true);
} catch (XAException e) {
e.printStackTrace();
throw new IOException(e.getMessage());
}
}
use of javax.transaction.xa.XAException in project graphdb by neo4j-attic.
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));
}
msgLog.logMessage("applyTxWithoutTxId log version: " + logVersion + ", committing tx=" + nextTxId + ") @ pos " + writeBuffer.getFileChannelPosition(), true);
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);
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) {
e.printStackTrace();
throw new IOException(e.getMessage());
}
// 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." );
msgLog.logMessage("Applied external tx and generated tx id=" + nextTxId, true);
// System.out.println( "applyTxWithoutTxId#end @ pos: " + writeBuffer.getFileChannelPosition() );
}
Aggregations