Search in sources :

Example 1 with XSiteResponseImpl

use of org.infinispan.remoting.transport.impl.XSiteResponseImpl 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();
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) XSiteReplicateCommand(org.infinispan.xsite.XSiteReplicateCommand) AbstractDelegatingTransport(org.infinispan.remoting.transport.AbstractDelegatingTransport) CacheContainer(org.infinispan.manager.CacheContainer) XSiteResponse(org.infinispan.remoting.transport.XSiteResponse) XSiteResponseImpl(org.infinispan.remoting.transport.impl.XSiteResponseImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AbstractDelegatingTransport(org.infinispan.remoting.transport.AbstractDelegatingTransport) Transport(org.infinispan.remoting.transport.Transport) XSiteStatePushCommand(org.infinispan.xsite.statetransfer.XSiteStatePushCommand) CheckPoint(org.infinispan.test.fwk.CheckPoint)

Example 2 with XSiteResponseImpl

use of org.infinispan.remoting.transport.impl.XSiteResponseImpl in project infinispan by infinispan.

the class JGroupsTransport method backupRemotely.

@Override
public <O> XSiteResponse<O> backupRemotely(XSiteBackup backup, XSiteReplicateCommand<O> rpcCommand) {
    assert !localSite.equals(backup.getSiteName()) : "sending to local site";
    if (unreachableSites.containsKey(backup.getSiteName())) {
        // fail fast if we have thread handling a SITE_UNREACHABLE event.
        return new SiteUnreachableXSiteResponse<>(backup, timeService);
    }
    Address recipient = JGroupsAddressCache.fromJGroupsAddress(new SiteMaster(backup.getSiteName()));
    long requestId = requests.newRequestId();
    logRequest(requestId, rpcCommand, recipient, "backup");
    SingleSiteRequest<ValidResponse> request = new SingleSiteRequest<>(SingleResponseCollector.validOnly(), requestId, requests, backup.getSiteName());
    addRequest(request);
    DeliverOrder order = backup.isSync() ? DeliverOrder.NONE : DeliverOrder.PER_SENDER;
    long timeout = backup.getTimeout();
    XSiteResponseImpl<O> xSiteResponse = new XSiteResponseImpl<>(timeService, backup);
    try {
        sendCommand(recipient, rpcCommand, request.getRequestId(), order, false, false);
        if (timeout > 0) {
            request.setTimeout(timeoutExecutor, timeout, TimeUnit.MILLISECONDS);
        }
        request.whenComplete(xSiteResponse);
    } catch (Throwable t) {
        request.cancel(true);
        xSiteResponse.completeExceptionally(t);
    }
    return xSiteResponse;
}
Also used : PhysicalAddress(org.jgroups.PhysicalAddress) SiteAddress(org.jgroups.protocols.relay.SiteAddress) JGroupsAddressCache.fromJGroupsAddress(org.infinispan.remoting.transport.jgroups.JGroupsAddressCache.fromJGroupsAddress) Address(org.infinispan.remoting.transport.Address) ValidResponse(org.infinispan.remoting.responses.ValidResponse) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) SiteMaster(org.jgroups.protocols.relay.SiteMaster) SiteUnreachableXSiteResponse(org.infinispan.remoting.transport.impl.SiteUnreachableXSiteResponse) XSiteResponseImpl(org.infinispan.remoting.transport.impl.XSiteResponseImpl)

Aggregations

XSiteResponseImpl (org.infinispan.remoting.transport.impl.XSiteResponseImpl)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CacheContainer (org.infinispan.manager.CacheContainer)1 DeliverOrder (org.infinispan.remoting.inboundhandler.DeliverOrder)1 ValidResponse (org.infinispan.remoting.responses.ValidResponse)1 AbstractDelegatingTransport (org.infinispan.remoting.transport.AbstractDelegatingTransport)1 Address (org.infinispan.remoting.transport.Address)1 Transport (org.infinispan.remoting.transport.Transport)1 XSiteResponse (org.infinispan.remoting.transport.XSiteResponse)1 SiteUnreachableXSiteResponse (org.infinispan.remoting.transport.impl.SiteUnreachableXSiteResponse)1 JGroupsAddressCache.fromJGroupsAddress (org.infinispan.remoting.transport.jgroups.JGroupsAddressCache.fromJGroupsAddress)1 CheckPoint (org.infinispan.test.fwk.CheckPoint)1 XSiteBackup (org.infinispan.xsite.XSiteBackup)1 XSiteReplicateCommand (org.infinispan.xsite.XSiteReplicateCommand)1 XSiteStatePushCommand (org.infinispan.xsite.statetransfer.XSiteStatePushCommand)1 PhysicalAddress (org.jgroups.PhysicalAddress)1 SiteAddress (org.jgroups.protocols.relay.SiteAddress)1 SiteMaster (org.jgroups.protocols.relay.SiteMaster)1