use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class BaseCompleteTransactionOperation method completeCache.
/**
* Completes the transaction for a specific cache.
*/
private CompletionStage<Void> completeCache(ByteString cacheName) throws Throwable {
TxState state = globalTxTable.getState(new CacheXid(cacheName, xid));
HotRodServer.ExtendedCacheInfo cacheInfo = server.getCacheInfo(cacheName.toString(), header.getVersion(), header.getMessageId(), true);
AdvancedCache<?, ?> cache = server.cache(cacheInfo, header, subject);
RpcManager rpcManager = cache.getRpcManager();
if (rpcManager == null || rpcManager.getAddress().equals(state.getOriginator())) {
if (log.isTraceEnabled()) {
log.tracef("[%s] Completing local executed transaction.", xid);
}
return asyncCompleteLocalTransaction(cache, state.getTimeout());
} else if (rpcManager.getMembers().contains(state.getOriginator())) {
if (log.isTraceEnabled()) {
log.tracef("[%s] Forward remotely executed transaction to %s.", xid, state.getOriginator());
}
return forwardCompleteCommand(cacheName, rpcManager, state);
} else {
if (log.isTraceEnabled()) {
log.tracef("[%s] Originator, %s, left the cluster.", xid, state.getOriginator());
}
return completeWithRemoteCommand(cache, rpcManager, state);
}
}
use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class GlobalTxTable method onOngoingTransaction.
private void onOngoingTransaction(CacheXid cacheXid, TxState state) {
if (state.getStatus() == Status.PREPARED && state.isRecoverable()) {
// recovery will handle prepared transactions
return;
}
ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheXid.getCacheName());
if (cr == null) {
// we don't have the cache locally
return;
}
RpcManager rpcManager = cr.getComponent(RpcManager.class);
if (isRemote(rpcManager, state.getOriginator())) {
// remotely originated transaction
// this is a weird state. the originator may crashed or it may be in another partition and communication with the client
// in any case, we can rollback the tx
// if we are in the minority partition, updating the global tx table will fail and we do nothing
// if we are in the majority partition, the originator can't commit/rollback since it would fail to update the global tx table
rollbackOldTransaction(cacheXid, state, () -> rollbackRemote(cr, cacheXid, state));
} else {
// local transaction prepared.
PerCacheTxTable txTable = cr.getComponent(PerCacheTxTable.class);
EmbeddedTransaction tx = txTable.getLocalTx(cacheXid.getXid());
if (tx == null) {
// local transaction doesn't exists.
onTransactionCompleted(cacheXid);
} else {
blockingManager.runBlocking(() -> rollbackOldTransaction(cacheXid, state, () -> completeLocal(txTable, cacheXid, tx, false)), cacheXid);
}
}
}
Aggregations