use of org.infinispan.xsite.XSiteReplicateCommand in project infinispan by infinispan.
the class JGroupsTransportTest method blockRemoteGets.
private CompletableFuture<Void> blockRemoteGets() {
CompletableFuture<Void> blocker = new CompletableFuture<>();
InboundInvocationHandler oldInvocationHandler = TestingUtil.extractGlobalComponent(manager(1), InboundInvocationHandler.class);
InboundInvocationHandler blockingInvocationHandler = new InboundInvocationHandler() {
@Override
public void handleFromCluster(Address origin, ReplicableCommand command, Reply reply, DeliverOrder order) {
if (command instanceof ClusteredGetCommand) {
log.tracef("Blocking clustered get");
blocker.thenRun(() -> oldInvocationHandler.handleFromCluster(origin, command, reply, order));
} else {
oldInvocationHandler.handleFromCluster(origin, command, reply, order);
}
}
@Override
public void handleFromRemoteSite(String origin, XSiteReplicateCommand command, Reply reply, DeliverOrder order) {
oldInvocationHandler.handleFromRemoteSite(origin, command, reply, order);
}
};
TestingUtil.replaceComponent(manager(1), InboundInvocationHandler.class, blockingInvocationHandler, true);
return blocker;
}
use of org.infinispan.xsite.XSiteReplicateCommand in project infinispan by infinispan.
the class SiteProviderTopologyChangeTest method doTopologyChangeDuringXSiteStateTransfer.
/**
* the test node starts the x-site state transfer and sends a chunk of data. the next chunk is blocked and we trigger
* the cache topology change.
*/
private void doTopologyChangeDuringXSiteStateTransfer(TopologyEvent event) throws Exception {
log.debugf("Start topology change during x-site state transfer with %s", event);
initBeforeTest();
final TestCaches<Object, Object> testCaches = createTestCache(event, LON);
log.debugf("Controlled cache=%s, Coordinator cache=%s, Cache to remove=%s", addressOf(testCaches.controllerCache), addressOf(testCaches.coordinator), testCaches.removeIndex < 0 ? "NONE" : addressOf(cache(LON, testCaches.removeIndex)));
// the test node will start the x-site state transfer and it will block. next, it the topology will change.
// strategy: let the first push command to proceed a block the next one.
final CheckPoint checkPoint = new CheckPoint();
final AtomicBoolean firstChunk = new AtomicBoolean(false);
wrapGlobalComponent(testCaches.controllerCache.getCacheManager(), Transport.class, new WrapFactory<Transport, Transport, CacheContainer>() {
@Override
public Transport wrap(CacheContainer wrapOn, Transport current) {
return new AbstractDelegatingTransport(current) {
@Override
public void start() {
// no-op; avoid re-start the transport again...
}
@Override
public XSiteResponse backupRemotely(XSiteBackup backup, XSiteReplicateCommand rpcCommand) {
if (rpcCommand instanceof XSiteStatePushCommand) {
if (firstChunk.compareAndSet(false, true)) {
checkPoint.trigger("before-second-chunk");
try {
checkPoint.awaitStrict("second-chunk", 30, TimeUnit.SECONDS);
} catch (InterruptedException | TimeoutException e) {
XSiteResponseImpl rsp = new XSiteResponseImpl(TIME_SERVICE, backup);
rsp.completeExceptionally(e);
return rsp;
}
}
}
return super.backupRemotely(backup, rpcCommand);
}
};
}
}, true);
log.debug("Start x-site state transfer");
startStateTransfer(testCaches.coordinator, NYC);
assertOnline(LON, NYC);
checkPoint.awaitStrict("before-second-chunk", 30, TimeUnit.SECONDS);
final Future<Void> topologyEventFuture = triggerTopologyChange(LON, testCaches.removeIndex);
topologyEventFuture.get();
checkPoint.triggerForever("second-chunk");
awaitLocalStateTransfer(LON);
awaitXSiteStateSent(LON);
assertData();
}
use of org.infinispan.xsite.XSiteReplicateCommand in project infinispan by infinispan.
the class JGroupsTransport method processRequest.
private void processRequest(org.jgroups.Address src, short flags, byte[] buffer, int offset, int length, long requestId) {
try {
DeliverOrder deliverOrder = decodeDeliverMode(flags);
if (src.equals(((JGroupsAddress) getAddress()).getJGroupsAddress())) {
// DISCARD ignores the DONT_LOOPBACK flag, see https://issues.jboss.org/browse/JGRP-2205
if (log.isTraceEnabled())
log.tracef("Ignoring request %d from self without total order", requestId);
return;
}
ReplicableCommand command = (ReplicableCommand) marshaller.objectFromByteBuffer(buffer, offset, length);
Reply reply;
if (requestId != Request.NO_REQUEST_ID) {
if (log.isTraceEnabled())
log.tracef("%s received request %d from %s: %s", getAddress(), requestId, src, command);
reply = response -> sendResponse(src, response, requestId, command);
} else {
if (log.isTraceEnabled())
log.tracef("%s received command from %s: %s", getAddress(), src, command);
reply = Reply.NO_OP;
}
if (src instanceof SiteAddress) {
String originSite = ((SiteAddress) src).getSite();
XSiteReplicateCommand<?> xsiteCommand = (XSiteReplicateCommand<?>) command;
xsiteCommand.setOriginSite(originSite);
invocationHandler.handleFromRemoteSite(originSite, xsiteCommand, reply, deliverOrder);
} else {
invocationHandler.handleFromCluster(fromJGroupsAddress(src), command, reply, deliverOrder);
}
} catch (Throwable t) {
CLUSTER.errorProcessingRequest(requestId, src, t);
Exception e = t instanceof Exception ? ((Exception) t) : new CacheException(t);
sendResponse(src, new ExceptionResponse(e), requestId, null);
}
}
Aggregations