use of org.apache.geode.internal.cache.FindRemoteTXMessage.FindRemoteTXMessageReplyProcessor in project geode by apache.
the class TXFailoverCommand method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
serverConnection.setAsTrue(REQUIRES_RESPONSE);
// Build the TXId for the transaction
InternalDistributedMember client = (InternalDistributedMember) serverConnection.getProxyID().getDistributedMember();
int uniqId = clientMessage.getTransactionId();
if (logger.isDebugEnabled()) {
logger.debug("TX: Transaction {} from {} is failing over to this server", uniqId, client);
}
TXId txId = new TXId(client, uniqId);
TXManagerImpl mgr = (TXManagerImpl) serverConnection.getCache().getCacheTransactionManager();
// in case it's already completing here in another
mgr.waitForCompletingTransaction(txId);
// thread
if (mgr.isHostedTxRecentlyCompleted(txId)) {
writeReply(clientMessage, serverConnection);
serverConnection.setAsTrue(RESPONDED);
mgr.removeHostedTXState(txId);
return;
}
// fixes bug 43350
boolean wasInProgress = mgr.setInProgress(true);
TXStateProxy tx = mgr.getTXState();
Assert.assertTrue(tx != null);
if (!tx.isRealDealLocal()) {
// send message to all peers to find out who hosts the transaction
FindRemoteTXMessageReplyProcessor processor = FindRemoteTXMessage.send(serverConnection.getCache(), txId);
try {
processor.waitForRepliesUninterruptibly();
} catch (ReplyException e) {
e.handleAsUnexpected();
}
// if hosting member is not null, bootstrap PeerTXStateStub to that member
// if hosting member is null, rebuild TXCommitMessage from partial TXCommitMessages
InternalDistributedMember hostingMember = processor.getHostingMember();
if (hostingMember != null) {
if (logger.isDebugEnabled()) {
logger.debug("TX: txState is not local, bootstrapping PeerTXState stub for targetNode: {}", hostingMember);
}
// inject the real deal
tx.setLocalTXState(new PeerTXStateStub(tx, hostingMember, client));
} else {
// bug #42228 and bug #43504 - this cannot return until the current view
// has been installed by all members, so that dlocks are released and
// the same keys can be used in a new transaction by the same client thread
InternalCache cache = serverConnection.getCache();
try {
WaitForViewInstallation.send((DistributionManager) cache.getDistributionManager());
} catch (InterruptedException e) {
cache.getDistributionManager().getCancelCriterion().checkCancelInProgress(e);
Thread.currentThread().interrupt();
}
// tx host has departed, rebuild the tx
if (processor.getTxCommitMessage() != null) {
if (logger.isDebugEnabled()) {
logger.debug("TX: for txId: {} rebuilt a recently completed tx", txId);
}
mgr.saveTXCommitMessageForClientFailover(txId, processor.getTxCommitMessage());
} else {
writeException(clientMessage, new TransactionDataNodeHasDepartedException("Could not find transaction host for " + txId), false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
mgr.removeHostedTXState(txId);
return;
}
}
}
if (!wasInProgress) {
mgr.setInProgress(false);
}
writeReply(clientMessage, serverConnection);
serverConnection.setAsTrue(RESPONDED);
}
Aggregations