Search in sources :

Example 1 with DeliverOrder

use of org.infinispan.remoting.inboundhandler.DeliverOrder 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));
}
Also used : PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) IllegalLifecycleStateException(org.infinispan.commons.IllegalLifecycleStateException) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) TransactionTable(org.infinispan.transaction.impl.TransactionTable) PrepareCommand(org.infinispan.commands.tx.PrepareCommand) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractDelegatingHandler(org.infinispan.remoting.inboundhandler.AbstractDelegatingHandler) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) Reply(org.infinispan.remoting.inboundhandler.Reply) Cache(org.infinispan.Cache)

Example 2 with DeliverOrder

use of org.infinispan.remoting.inboundhandler.DeliverOrder 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 3 with DeliverOrder

use of org.infinispan.remoting.inboundhandler.DeliverOrder 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);
    }
}
Also used : MagicKey(org.infinispan.distribution.MagicKey) TestDataSCI(org.infinispan.test.TestDataSCI) BlockingLocalTopologyManager(org.infinispan.util.BlockingLocalTopologyManager) StateResponseCommand(org.infinispan.commands.statetransfer.StateResponseCommand) Reply(org.infinispan.remoting.inboundhandler.Reply) AssertJUnit.assertFalse(org.testng.AssertJUnit.assertFalse) Test(org.testng.annotations.Test) CacheTopology(org.infinispan.topology.CacheTopology) Cache(org.infinispan.Cache) BiasAcquisition(org.infinispan.configuration.cache.BiasAcquisition) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) AbstractDelegatingHandler(org.infinispan.remoting.inboundhandler.AbstractDelegatingHandler) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) List(java.util.List) Future(java.util.concurrent.Future) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) Stream(java.util.stream.Stream) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) TestingUtil(org.infinispan.test.TestingUtil) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) PerCacheInboundInvocationHandler(org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler) BlockingLocalTopologyManager(org.infinispan.util.BlockingLocalTopologyManager) DeliverOrder(org.infinispan.remoting.inboundhandler.DeliverOrder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) CountDownLatch(java.util.concurrent.CountDownLatch) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) AbstractDelegatingHandler(org.infinispan.remoting.inboundhandler.AbstractDelegatingHandler) CacheRpcCommand(org.infinispan.commands.remote.CacheRpcCommand) Reply(org.infinispan.remoting.inboundhandler.Reply) StateResponseCommand(org.infinispan.commands.statetransfer.StateResponseCommand) MagicKey(org.infinispan.distribution.MagicKey) Cache(org.infinispan.Cache)

Example 4 with DeliverOrder

use of org.infinispan.remoting.inboundhandler.DeliverOrder 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)

Example 5 with DeliverOrder

use of org.infinispan.remoting.inboundhandler.DeliverOrder 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

DeliverOrder (org.infinispan.remoting.inboundhandler.DeliverOrder)8 Reply (org.infinispan.remoting.inboundhandler.Reply)5 Cache (org.infinispan.Cache)3 CacheRpcCommand (org.infinispan.commands.remote.CacheRpcCommand)3 AbstractDelegatingHandler (org.infinispan.remoting.inboundhandler.AbstractDelegatingHandler)3 Address (org.infinispan.remoting.transport.Address)3 SiteAddress (org.jgroups.protocols.relay.SiteAddress)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 ReplicableCommand (org.infinispan.commands.ReplicableCommand)2 IllegalLifecycleStateException (org.infinispan.commons.IllegalLifecycleStateException)2 PerCacheInboundInvocationHandler (org.infinispan.remoting.inboundhandler.PerCacheInboundInvocationHandler)2 ValidResponse (org.infinispan.remoting.responses.ValidResponse)2 JGroupsAddressCache.fromJGroupsAddress (org.infinispan.remoting.transport.jgroups.JGroupsAddressCache.fromJGroupsAddress)2 TestingUtil (org.infinispan.test.TestingUtil)2 XSiteReplicateCommand (org.infinispan.xsite.XSiteReplicateCommand)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1