use of org.infinispan.commands.remote.CacheRpcCommand in project infinispan by infinispan.
the class ScatteredStateConsumerImpl method handleSegments.
@Override
protected CompletionStage<Void> handleSegments(boolean isRebalance, IntSet addedSegments, IntSet removedSegments, IntSet transactionOnlySegments) {
if (!isRebalance) {
log.trace("This is not a rebalance, not doing anything...");
return CompletableFutures.completedNull();
}
if (addedSegments.isEmpty()) {
log.trace("No segments missing");
return CompletableFutures.completedNull();
}
synchronized (transferMapsLock) {
inboundSegments = IntSets.mutableFrom(addedSegments);
}
chunkCounter.set(0);
if (log.isTraceEnabled())
log.tracef("Revoking all segments, chunk counter reset to 0");
CacheRpcCommand command = commandsFactory.buildScatteredStateConfirmRevokeCommand(cacheTopology.getTopologyId(), addedSegments);
// we need to wait synchronously for the completion
return rpcManager.invokeCommandOnAll(command, MapResponseCollector.ignoreLeavers(), rpcManager.getSyncRpcOptions()).handle((responses, throwable) -> {
if (throwable == null) {
try {
svm.startKeyTransfer(addedSegments);
requestKeyTransfer(addedSegments);
} catch (SuspectException e) {
log.tracef("Key transfer source %s was suspected, another source will be selected", e.getSuspect());
} catch (Throwable t) {
log.failedToRequestSegments(cacheName, null, addedSegments, t);
}
} else {
if (cache.wired().getStatus() == ComponentStatus.RUNNING) {
log.failedConfirmingRevokedSegments(throwable);
} else {
// reduce verbosity for stopping cache
log.debug("Failed confirming revoked segments", throwable);
}
for (int segment : addedSegments) {
svm.notifyKeyTransferFinished(segment, false, false);
}
notifyEndOfStateTransferIfNeeded();
}
return null;
});
}
use of org.infinispan.commands.remote.CacheRpcCommand in project infinispan by infinispan.
the class ConditionalOperationPrimaryOwnerFailTest method testEntryNotWrapped.
public void testEntryNotWrapped() throws Throwable {
assertClusterSize("Wrong cluster size!", 3);
final Object key = new MagicKey(cache(0), cache(1));
final Cache<Object, Object> futureBackupOwnerCache = cache(2);
cache(0).put(key, INITIAL_VALUE);
final PerCacheInboundInvocationHandler spyHandler = spyInvocationHandler(futureBackupOwnerCache);
final EntryFactory spyEntryFactory = spyEntryFactory(futureBackupOwnerCache);
// it blocks the StateResponseCommand.class
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
doAnswer(invocation -> {
CacheRpcCommand command = (CacheRpcCommand) invocation.getArguments()[0];
if (command instanceof StateResponseCommand) {
log.debugf("Blocking command %s", command);
latch2.countDown();
latch1.await();
}
return invocation.callRealMethod();
}).when(spyHandler).handle(any(CacheRpcCommand.class), any(Reply.class), any(DeliverOrder.class));
doAnswer(invocation -> {
InvocationContext context = (InvocationContext) invocation.getArguments()[0];
log.debugf("wrapEntryForWriting invoked with %s", context);
CompletionStage<Void> stage = (CompletionStage<Void>) invocation.callRealMethod();
CompletionStages.join(stage);
assertNull(context.lookupEntry(key), "Entry should not be wrapped!");
return stage;
}).when(spyEntryFactory).wrapEntryForWriting(any(InvocationContext.class), any(), anyInt(), anyBoolean(), anyBoolean(), any());
Future<?> killMemberResult = fork(() -> killMember(1));
// await until the key is received from state transfer (the command is blocked now...)
latch2.await(30, TimeUnit.SECONDS);
futureBackupOwnerCache.put(key, FINAL_VALUE);
latch1.countDown();
killMemberResult.get(30, TimeUnit.SECONDS);
}
use of org.infinispan.commands.remote.CacheRpcCommand in project infinispan by infinispan.
the class PrepareProcessedAfterOriginatorCrashTest method testBelatedTransactionDoesntLeak.
public void testBelatedTransactionDoesntLeak() throws Throwable {
CountDownLatch prepareReceived = new CountDownLatch(1);
CountDownLatch prepareBlocked = new CountDownLatch(1);
CountDownLatch prepareExecuted = new CountDownLatch(1);
Cache receiver = cache(1);
PerCacheInboundInvocationHandler originalInvocationHandler = TestingUtil.extractComponent(receiver, PerCacheInboundInvocationHandler.class);
PerCacheInboundInvocationHandler blockingInvocationHandler = new AbstractDelegatingHandler(originalInvocationHandler) {
@Override
public void handle(CacheRpcCommand command, Reply reply, DeliverOrder order) {
if (!(command instanceof PrepareCommand)) {
delegate.handle(command, reply, order);
return;
}
try {
prepareReceived.countDown();
prepareBlocked.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new IllegalLifecycleStateException(e);
}
log.trace("Processing belated prepare");
delegate.handle(command, returnValue -> {
prepareExecuted.countDown();
reply.reply(returnValue);
}, order);
}
};
TestingUtil.replaceComponent(receiver, PerCacheInboundInvocationHandler.class, blockingInvocationHandler, true);
TestingUtil.extractComponentRegistry(receiver).cacheComponents();
final Object key = getKeyForCache(1);
fork(() -> {
try {
cache(0).put(key, "v");
} catch (Throwable e) {
// possible as the node is being killed
}
});
prepareReceived.await(10, TimeUnit.SECONDS);
killMember(0);
// give TransactionTable.cleanupStaleTransactions some time to run
Thread.sleep(5000);
prepareBlocked.countDown();
prepareExecuted.await(10, TimeUnit.SECONDS);
log.trace("Finished waiting for belated prepare to complete");
final TransactionTable transactionTable = TestingUtil.getTransactionTable(receiver);
assertEquals(0, transactionTable.getRemoteTxCount());
assertEquals(0, transactionTable.getLocalTxCount());
assertFalse(receiver.getAdvancedCache().getLockManager().isLocked(key));
}
use of org.infinispan.commands.remote.CacheRpcCommand in project infinispan by infinispan.
the class AsynchronousInvocationTest method mockCacheRpcCommand.
private static CacheRpcCommand mockCacheRpcCommand(boolean blocking) throws Throwable {
CacheRpcCommand mock = mock(CacheRpcCommand.class);
when(mock.canBlock()).thenReturn(blocking);
when(mock.getCacheName()).thenReturn(CACHE_NAME_BYTES);
when(mock.invokeAsync(any())).thenReturn(CompletableFutures.completedNull());
return mock;
}
use of org.infinispan.commands.remote.CacheRpcCommand in project infinispan by infinispan.
the class PushTransferTest method testNodeJoin.
public void testNodeJoin() throws Exception {
List<MagicKey> keys = init();
EmbeddedCacheManager cm4 = addClusterEnabledCacheManager(TestDataSCI.INSTANCE, null, TRANSPORT_FLAGS);
cm4.defineConfiguration(CACHE_NAME, defaultConfig.build());
int startTopologyId = c1.getAdvancedCache().getDistributionManager().getCacheTopology().getTopologyId();
BlockingLocalTopologyManager bltm = BlockingLocalTopologyManager.replaceTopologyManager(cm4, CACHE_NAME);
CountDownLatch statePushedLatch = new CountDownLatch(1);
CountDownLatch stateAppliedLatch = new CountDownLatch(1);
TestingUtil.addCacheStartingHook(cm4, (name, cr) -> {
PerCacheInboundInvocationHandler originalHandler = cr.getComponent(PerCacheInboundInvocationHandler.class);
AbstractDelegatingHandler newHandler = new AbstractDelegatingHandler(originalHandler) {
@Override
public void handle(CacheRpcCommand command, Reply reply, DeliverOrder order) {
// StateResponseCommand is topology-aware, so handle() just queues it on the remote executor
if (command instanceof StateResponseCommand) {
log.tracef("State received on %s", cm4.getAddress());
statePushedLatch.countDown();
}
originalHandler.handle(command, response -> {
log.tracef("State applied on %s", cm4.getAddress());
stateAppliedLatch.countDown();
reply.reply(response);
}, order);
}
};
BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
bcr.replaceComponent(PerCacheInboundInvocationHandler.class.getName(), newHandler, false);
cr.rewire();
cr.cacheComponents();
});
Future<Cache> c4Future = fork(() -> cm4.getCache(CACHE_NAME));
// Any StateResponseCommand should be delayed until node 4 has the TRANSITORY topology
assertTrue(statePushedLatch.await(10, TimeUnit.SECONDS));
assertFalse(stateAppliedLatch.await(100, TimeUnit.MILLISECONDS));
// Finish the rebalance, unblocking the StateResponseCommand(s)
bltm.confirmTopologyUpdate(CacheTopology.Phase.TRANSITORY);
assertEquals(0, stateAppliedLatch.getCount());
bltm.confirmTopologyUpdate(CacheTopology.Phase.NO_REBALANCE);
Cache c4 = c4Future.get(30, TimeUnit.SECONDS);
TestingUtil.blockUntilViewsReceived(30000, false, c1, c2, c3, c4);
TestingUtil.waitForNoRebalance(c1, c2, c3, c4);
for (MagicKey key : keys) {
int copies = Stream.of(c1, c2, c3, c4).mapToInt(c -> c.getAdvancedCache().getDataContainer().containsKey(key) ? 1 : 0).sum();
assertEquals("Key " + key + " has incorrect number of copies", 2, copies);
}
}
Aggregations