Search in sources :

Example 1 with XSiteReplicateCommand

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;
}
Also used : XSiteReplicateCommand(org.infinispan.xsite.XSiteReplicateCommand) CompletableFuture(java.util.concurrent.CompletableFuture) Address(org.infinispan.remoting.transport.Address) ReplicableCommand(org.infinispan.commands.ReplicableCommand) InboundInvocationHandler(org.infinispan.remoting.inboundhandler.InboundInvocationHandler) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) Reply(org.infinispan.remoting.inboundhandler.Reply) ByteString(org.infinispan.util.ByteString) ClusteredGetCommand(org.infinispan.commands.remote.ClusteredGetCommand)

Example 2 with XSiteReplicateCommand

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();
}
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 3 with XSiteReplicateCommand

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);
    }
}
Also used : XSiteReplicateCommand(org.infinispan.xsite.XSiteReplicateCommand) SiteAddress(org.jgroups.protocols.relay.SiteAddress) ExceptionResponse(org.infinispan.remoting.responses.ExceptionResponse) CacheException(org.infinispan.commons.CacheException) ReplicableCommand(org.infinispan.commands.ReplicableCommand) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) Reply(org.infinispan.remoting.inboundhandler.Reply) TraceException(org.infinispan.commons.util.logging.TraceException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CacheConfigurationException(org.infinispan.commons.CacheConfigurationException) CacheException(org.infinispan.commons.CacheException) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException)

Aggregations

XSiteReplicateCommand (org.infinispan.xsite.XSiteReplicateCommand)3 ReplicableCommand (org.infinispan.commands.ReplicableCommand)2 DeliverOrder (org.infinispan.remoting.inboundhandler.DeliverOrder)2 Reply (org.infinispan.remoting.inboundhandler.Reply)2 IOException (java.io.IOException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ClusteredGetCommand (org.infinispan.commands.remote.ClusteredGetCommand)1 CacheConfigurationException (org.infinispan.commons.CacheConfigurationException)1 CacheException (org.infinispan.commons.CacheException)1 IllegalLifecycleStateException (org.infinispan.commons.IllegalLifecycleStateException)1 TraceException (org.infinispan.commons.util.logging.TraceException)1 CacheContainer (org.infinispan.manager.CacheContainer)1 InboundInvocationHandler (org.infinispan.remoting.inboundhandler.InboundInvocationHandler)1 ExceptionResponse (org.infinispan.remoting.responses.ExceptionResponse)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