use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class RehashClusterPublisherManagerTest method testSegmentMovesToOriginatorJustBeforeSendingRemote.
private void testSegmentMovesToOriginatorJustBeforeSendingRemote(DeliveryGuarantee deliveryGuarantee, boolean parallel, boolean isEntry, boolean useKeys) throws Exception {
Cache cache0 = cache(0);
Address cache2Address = address(2);
CheckPoint checkPoint = new CheckPoint();
// Always let it finish once released
checkPoint.triggerForever(Mocks.AFTER_RELEASE);
// Block on about to send the remote command to node2
RpcManager original = Mocks.blockingMock(checkPoint, RpcManager.class, cache0, (stub, m) -> stub.when(m).invokeCommand(eq(cache2Address), isA(ReductionPublisherRequestCommand.class), any(), any()));
int expectedAmount = caches().size();
// If it is at most once, we don't retry the segment so the count will be off by 1
if (deliveryGuarantee == DeliveryGuarantee.AT_MOST_ONCE) {
expectedAmount -= 1;
}
// When we are using keys, we explicitly don't pass one of them
if (useKeys) {
expectedAmount--;
}
try {
runCommand(deliveryGuarantee, parallel, isEntry, expectedAmount, () -> {
checkPoint.awaitStrict(Mocks.BEFORE_INVOCATION, 10, TimeUnit.SECONDS);
triggerRebalanceSegment2MovesToNode0();
checkPoint.triggerForever(Mocks.BEFORE_RELEASE);
}, toKeys(useKeys));
} finally {
if (original != null) {
TestingUtil.replaceComponent(cache0, RpcManager.class, original, true);
}
}
}
use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class IracVersionUnitTest method mockRpcManager.
private static RpcManager mockRpcManager(String siteName) {
Transport transport = mockTransport(siteName);
RpcManager rpcManager = Mockito.mock(RpcManager.class);
Mockito.when(rpcManager.getTransport()).thenReturn(transport);
return rpcManager;
}
use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class GlobalTxTable method rollbackRemote.
private void rollbackRemote(ComponentRegistry cr, CacheXid cacheXid, TxState state) {
RollbackCommand rpcCommand = cr.getCommandsFactory().buildRollbackCommand(state.getGlobalTransaction());
RpcManager rpcManager = cr.getComponent(RpcManager.class);
rpcCommand.setTopologyId(rpcManager.getTopologyId());
rpcManager.invokeCommandOnAll(rpcCommand, VoidResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).thenRun(() -> {
// ignore exception so the rollback can be retried.
// if a node doesn't find the remote transaction, it returns null.
TxFunction function = new SetCompletedTransactionFunction(false);
rwMap.eval(cacheXid, function);
});
}
use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class GlobalTxTable method onTransactionDecision.
private void onTransactionDecision(CacheXid cacheXid, TxState state, boolean commit) {
ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheXid.getCacheName());
if (cr == null) {
// we don't have the cache locally
return;
}
RpcManager rpcManager = cr.getComponent(RpcManager.class);
if (rpcManager == null || state.getOriginator().equals(rpcManager.getAddress())) {
// local
PerCacheTxTable txTable = cr.getComponent(PerCacheTxTable.class);
EmbeddedTransaction tx = txTable.getLocalTx(cacheXid.getXid());
if (tx == null) {
// transaction completed
onTransactionCompleted(cacheXid);
} else {
blockingManager.runBlocking(() -> completeLocal(txTable, cacheXid, tx, commit), cacheXid);
}
} else {
if (commit) {
TransactionBoundaryCommand rpcCommand;
if (cr.getComponent(Configuration.class).transaction().lockingMode() == LockingMode.PESSIMISTIC) {
rpcCommand = cr.getCommandsFactory().buildPrepareCommand(state.getGlobalTransaction(), state.getModifications(), true);
} else {
rpcCommand = cr.getCommandsFactory().buildCommitCommand(state.getGlobalTransaction());
}
rpcCommand.setTopologyId(rpcManager.getTopologyId());
rpcManager.invokeCommandOnAll(rpcCommand, VoidResponseCollector.validOnly(), rpcManager.getSyncRpcOptions()).handle((aVoid, throwable) -> {
// TODO?
TxFunction function = new SetCompletedTransactionFunction(true);
rwMap.eval(cacheXid, function);
return null;
});
} else {
rollbackRemote(cr, cacheXid, state);
}
}
}
use of org.infinispan.remoting.rpc.RpcManager in project infinispan by infinispan.
the class GlobalTxTable method skipReaper.
private boolean skipReaper(Address originator, ByteString cacheName) {
ComponentRegistry cr = gcr.getNamedComponentRegistry(cacheName);
if (cr == null) {
// cache is stopped? doesn't exist? we need to handle it
return false;
}
RpcManager rpcManager = cr.getComponent(RpcManager.class);
return // we are not the originator. I
isRemote(rpcManager, originator) && // originator is still in the view.
rpcManager.getMembers().contains(originator);
}
Aggregations