Search in sources :

Example 11 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class SlowRecDUnitTest method forceQueuing.

private void forceQueuing(final Region r) throws CacheException {
    Connection.FORCE_ASYNC_QUEUE = true;
    final DMStats stats = getSystem().getDistributionManager().getStats();
    r.put("forcekey", "forcevalue");
    // wait for the flusher to get its first flush in progress
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return stats.getAsyncQueueFlushesInProgress() != 0;
        }

        public String description() {
            return "waiting for flushes to start";
        }
    };
    Wait.waitForCriterion(ev, 2 * 1000, 200, true);
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 12 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class SlowRecDUnitTest method testTimeoutDisconnect.

/**
   * Make sure that exceeding the async-queue-timeout causes a disconnect.
   * <p>
   * [bruce] This test was disabled when the SlowRecDUnitTest was re-enabled in build.xml in the
   * splitbrainNov07 branch. It had been disabled since June 2006 due to hangs. Some of the tests,
   * like this one, still need work because the periodically (some quite often) fail.
   */
@Test
public void testTimeoutDisconnect() throws Exception {
    final String expected = "org.apache.geode.internal.tcp.ConnectionException: Forced disconnect sent to" + "||java.io.IOException: Broken pipe";
    final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
    final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
    final AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_NO_ACK);
    final Region r = createRootRegion("slowrec", factory.create());
    final DM dm = getSystem().getDistributionManager();
    final DMStats stats = dm.getStats();
    // set others before vm0 connects
    final Set others = dm.getOtherDistributionManagerIds();
    // create receiver in vm0 with queuing enabled
    Properties p = new Properties();
    p.setProperty(ASYNC_DISTRIBUTION_TIMEOUT, "5");
    // 500 ms
    p.setProperty(ASYNC_QUEUE_TIMEOUT, "500");
    doCreateOtherVm(p, true);
    final Object key = "key";
    // 1k
    final int VALUE_SIZE = 1024;
    final byte[] value = new byte[VALUE_SIZE];
    int count = 0;
    long queuedMsgs = stats.getAsyncQueuedMsgs();
    long queueSize = stats.getAsyncQueueSize();
    final long timeoutLimit = System.currentTimeMillis() + 5000;
    getCache().getLogger().info(addExpected);
    try {
        while (stats.getAsyncQueueTimeouts() == 0) {
            r.put(key, value);
            count++;
            if (stats.getAsyncQueueSize() > 0) {
                queuedMsgs = stats.getAsyncQueuedMsgs();
                queueSize = stats.getAsyncQueueSize();
            }
            if (System.currentTimeMillis() > timeoutLimit) {
                fail("should have exceeded async-queue-timeout by now");
            }
        }
        LogWriterUtils.getLogWriter().info("After " + count + " " + VALUE_SIZE + " byte puts slowrec mode kicked in but the queue filled when its size reached " + queueSize + " with " + queuedMsgs + " msgs");
        // make sure we lost a connection to vm0
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                if (dm.getOtherDistributionManagerIds().size() > others.size()) {
                    return false;
                }
                return stats.getAsyncQueueSize() == 0;
            }

            public String description() {
                return "waiting for departure";
            }
        };
        Wait.waitForCriterion(ev, 2 * 1000, 200, true);
    } finally {
        getCache().getLogger().info(removeExpected);
    }
    assertEquals(others, dm.getOtherDistributionManagerIds());
    assertEquals(0, stats.getAsyncQueueSize());
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) AttributesFactory(org.apache.geode.cache.AttributesFactory) Set(java.util.Set) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region) DM(org.apache.geode.distributed.internal.DM) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 13 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class SlowRecDUnitTest method testSizeDisconnect.

/**
   * Make sure that exceeding the queue size limit causes a disconnect.
   */
@Test
public void testSizeDisconnect() throws Exception {
    final String expected = "org.apache.geode.internal.tcp.ConnectionException: Forced disconnect sent to" + "||java.io.IOException: Broken pipe";
    final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
    final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
    final AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_NO_ACK);
    final Region r = createRootRegion("slowrec", factory.create());
    final DM dm = getSystem().getDistributionManager();
    final DMStats stats = dm.getStats();
    // set others before vm0 connects
    final Set others = dm.getOtherDistributionManagerIds();
    // create receiver in vm0 with queuing enabled
    Properties p = new Properties();
    p.setProperty(ASYNC_DISTRIBUTION_TIMEOUT, "5");
    // 1 meg
    p.setProperty(ASYNC_MAX_QUEUE_SIZE, "1");
    doCreateOtherVm(p, false);
    final Object key = "key";
    // .1M async-max-queue-size should give us 10 of these 100K
    final int VALUE_SIZE = 1024 * 100;
    // msgs before queue full
    final byte[] value = new byte[VALUE_SIZE];
    int count = 0;
    forceQueuing(r);
    long queuedMsgs = stats.getAsyncQueuedMsgs();
    long queueSize = stats.getAsyncQueueSize();
    getCache().getLogger().info(addExpected);
    try {
        while (stats.getAsyncQueueSizeExceeded() == 0 && stats.getAsyncQueueTimeouts() == 0) {
            r.put(key, value);
            count++;
            if (stats.getAsyncQueueSize() > 0) {
                queuedMsgs = stats.getAsyncQueuedMsgs();
                queueSize = stats.getAsyncQueueSize();
            }
            if (count > 100) {
                fail("should have exceeded max-queue-size by now");
            }
        }
        LogWriterUtils.getLogWriter().info("After " + count + " " + VALUE_SIZE + " byte puts slowrec mode kicked in but the queue filled when its size reached " + queueSize + " with " + queuedMsgs + " msgs");
        // make sure we lost a connection to vm0
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                return dm.getOtherDistributionManagerIds().size() <= others.size() && stats.getAsyncQueueSize() == 0;
            }

            public String description() {
                return "waiting for connection loss";
            }
        };
        Wait.waitForCriterion(ev, 30 * 1000, 200, true);
    } finally {
        forceQueueFlush();
        getCache().getLogger().info(removeExpected);
    }
    assertEquals(others, dm.getOtherDistributionManagerIds());
    assertEquals(0, stats.getAsyncQueueSize());
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) AttributesFactory(org.apache.geode.cache.AttributesFactory) Set(java.util.Set) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region) DM(org.apache.geode.distributed.internal.DM) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 14 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class GMSMembershipManagerJUnitTest method testReplyProcessorInitiatesSuspicion.

@Test
public void testReplyProcessorInitiatesSuspicion() throws Exception {
    DM dm = mock(DM.class);
    DMStats stats = mock(DMStats.class);
    InternalDistributedSystem system = InternalDistributedSystem.newInstanceForTesting(dm, distProperties);
    when(dm.getStats()).thenReturn(stats);
    when(dm.getSystem()).thenReturn(system);
    when(dm.getCancelCriterion()).thenReturn(stopper);
    when(dm.getMembershipManager()).thenReturn(manager);
    when(dm.getViewMembers()).thenReturn(members);
    when(dm.getDistributionManagerIds()).thenReturn(new HashSet(members));
    when(dm.addMembershipListenerAndGetDistributionManagerIds(any(MembershipListener.class))).thenReturn(new HashSet(members));
    manager.start();
    manager.started();
    manager.isJoining = true;
    List<InternalDistributedMember> viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], mockMembers[1], myMemberId });
    manager.installView(new NetView(myMemberId, 2, viewmembers));
    List<InternalDistributedMember> mbrs = new ArrayList<>(1);
    mbrs.add(mockMembers[0]);
    ReplyProcessor21 rp = new ReplyProcessor21(dm, mbrs);
    rp.enableSevereAlertProcessing();
    boolean result = rp.waitForReplies(WAIT_FOR_REPLIES_MILLIS);
    // the wait should have timed out
    assertFalse(result);
    verify(healthMonitor, atLeastOnce()).checkIfAvailable(isA(InternalDistributedMember.class), isA(String.class), isA(Boolean.class));
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) NetView(org.apache.geode.distributed.internal.membership.NetView) ArrayList(java.util.ArrayList) DM(org.apache.geode.distributed.internal.DM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedMembershipListener(org.apache.geode.distributed.internal.membership.DistributedMembershipListener) MembershipListener(org.apache.geode.distributed.internal.MembershipListener) HashSet(java.util.HashSet) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class JGroupsMessenger method send.

private Set<InternalDistributedMember> send(DistributionMessage msg, boolean reliably) {
    // perform the same jgroups messaging as in 8.2's GMSMembershipManager.send() method
    // BUT: when marshalling messages we need to include the version of the product and
    // localAddress at the beginning of the message. These should be used in the receiver
    // code to create a versioned input stream, read the sender address, then read the message
    // and set its sender address
    DMStats theStats = services.getStatistics();
    NetView oldView = this.view;
    if (!myChannel.isConnected()) {
        logger.info("JGroupsMessenger channel is closed - messaging is not possible");
        throw new DistributedSystemDisconnectedException("Distributed System is shutting down");
    }
    filterOutgoingMessage(msg);
    // the message's processor if necessary
    if ((msg instanceof DirectReplyMessage) && msg.isDirectAck() && msg.getProcessorId() <= 0) {
        ((DirectReplyMessage) msg).registerProcessor();
    }
    InternalDistributedMember[] destinations = msg.getRecipients();
    boolean allDestinations = msg.forAll();
    boolean useMcast = false;
    if (services.getConfig().getTransport().isMcastEnabled()) {
        if (msg.getMulticast() || allDestinations) {
            useMcast = services.getManager().isMulticastAllowed();
        }
    }
    if (logger.isDebugEnabled() && reliably) {
        String recips = useMcast ? "multicast" : Arrays.toString(msg.getRecipients());
        logger.debug("sending via JGroups: [{}] recipients: {}", msg, recips);
    }
    JGAddress local = this.jgAddress;
    if (useMcast) {
        long startSer = theStats.startMsgSerialization();
        Message jmsg = createJGMessage(msg, local, Version.CURRENT_ORDINAL);
        theStats.endMsgSerialization(startSer);
        Exception problem;
        try {
            jmsg.setTransientFlag(TransientFlag.DONT_LOOPBACK);
            if (!reliably) {
                jmsg.setFlag(Message.Flag.NO_RELIABILITY);
            }
            theStats.incSentBytes(jmsg.getLength());
            logger.trace("Sending JGroups message: {}", jmsg);
            myChannel.send(jmsg);
        } catch (Exception e) {
            logger.debug("caught unexpected exception", e);
            Throwable cause = e.getCause();
            if (cause instanceof ForcedDisconnectException) {
                problem = (Exception) cause;
            } else {
                problem = e;
            }
            if (services.getShutdownCause() != null) {
                Throwable shutdownCause = services.getShutdownCause();
                // problem.
                if (shutdownCause instanceof ForcedDisconnectException) {
                    problem = (Exception) shutdownCause;
                } else {
                    Throwable ne = problem;
                    while (ne.getCause() != null) {
                        ne = ne.getCause();
                    }
                    ne.initCause(services.getShutdownCause());
                }
            }
            final String channelClosed = LocalizedStrings.GroupMembershipService_CHANNEL_CLOSED.toLocalizedString();
            // services.getManager().membershipFailure(channelClosed, problem);
            throw new DistributedSystemDisconnectedException(channelClosed, problem);
        }
    } else // useMcast
    {
        // ! useMcast
        int len = destinations.length;
        // explicit list of members
        List<GMSMember> calculatedMembers;
        // == calculatedMembers.len
        int calculatedLen;
        if (len == 1 && destinations[0] == DistributionMessage.ALL_RECIPIENTS) {
            // send to all
            // Grab a copy of the current membership
            NetView v = services.getJoinLeave().getView();
            // Construct the list
            calculatedLen = v.size();
            calculatedMembers = new LinkedList<GMSMember>();
            for (int i = 0; i < calculatedLen; i++) {
                InternalDistributedMember m = (InternalDistributedMember) v.get(i);
                calculatedMembers.add((GMSMember) m.getNetMember());
            }
        } else // send to all
        {
            // send to explicit list
            calculatedLen = len;
            calculatedMembers = new LinkedList<GMSMember>();
            for (int i = 0; i < calculatedLen; i++) {
                calculatedMembers.add((GMSMember) destinations[i].getNetMember());
            }
        }
        // send to explicit list
        Int2ObjectOpenHashMap<Message> messages = new Int2ObjectOpenHashMap<>();
        long startSer = theStats.startMsgSerialization();
        boolean firstMessage = true;
        for (GMSMember mbr : calculatedMembers) {
            short version = mbr.getVersionOrdinal();
            if (!messages.containsKey(version)) {
                Message jmsg = createJGMessage(msg, local, version);
                messages.put(version, jmsg);
                if (firstMessage) {
                    theStats.incSentBytes(jmsg.getLength());
                    firstMessage = false;
                }
            }
        }
        theStats.endMsgSerialization(startSer);
        Collections.shuffle(calculatedMembers);
        int i = 0;
        for (GMSMember mbr : calculatedMembers) {
            JGAddress to = new JGAddress(mbr);
            short version = mbr.getVersionOrdinal();
            Message jmsg = messages.get(version);
            Exception problem = null;
            try {
                Message tmp = (i < (calculatedLen - 1)) ? jmsg.copy(true) : jmsg;
                if (!reliably) {
                    jmsg.setFlag(Message.Flag.NO_RELIABILITY);
                }
                tmp.setDest(to);
                tmp.setSrc(this.jgAddress);
                logger.trace("Unicasting to {}", to);
                myChannel.send(tmp);
            } catch (Exception e) {
                problem = e;
            }
            if (problem != null) {
                Throwable cause = services.getShutdownCause();
                if (cause != null) {
                    // problem.
                    if (cause instanceof ForcedDisconnectException) {
                        problem = (Exception) cause;
                    } else {
                        Throwable ne = problem;
                        while (ne.getCause() != null) {
                            ne = ne.getCause();
                        }
                        ne.initCause(cause);
                    }
                }
                final String channelClosed = LocalizedStrings.GroupMembershipService_CHANNEL_CLOSED.toLocalizedString();
                // services.getManager().membershipFailure(channelClosed, problem);
                throw new DistributedSystemDisconnectedException(channelClosed, problem);
            }
        }
    // send individually
    }
    // (i.e., left the view), we signal it here.
    if (msg.forAll()) {
        return Collections.emptySet();
    }
    Set<InternalDistributedMember> result = new HashSet<>();
    NetView newView = this.view;
    if (newView != null && newView != oldView) {
        for (InternalDistributedMember d : destinations) {
            if (!newView.contains(d)) {
                logger.debug("messenger: member has left the view: {}  view is now {}", d, newView);
                result.add(d);
            }
        }
    }
    return result;
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) DMStats(org.apache.geode.distributed.internal.DMStats) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) DirectReplyMessage(org.apache.geode.internal.cache.DirectReplyMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) LocalizedMessage(org.apache.geode.internal.logging.log4j.LocalizedMessage) Message(org.jgroups.Message) HighPriorityDistributionMessage(org.apache.geode.distributed.internal.HighPriorityDistributionMessage) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) NetView(org.apache.geode.distributed.internal.membership.NetView) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DirectReplyMessage(org.apache.geode.internal.cache.DirectReplyMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HashSet(java.util.HashSet)

Aggregations

DMStats (org.apache.geode.distributed.internal.DMStats)29 Region (org.apache.geode.cache.Region)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)10 Properties (java.util.Properties)9 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)9 Test (org.junit.Test)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)7 CacheException (org.apache.geode.cache.CacheException)6 DM (org.apache.geode.distributed.internal.DM)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 Iterator (java.util.Iterator)3 Set (java.util.Set)3 IgnoredException (org.apache.geode.test.dunit.IgnoredException)3 VM (org.apache.geode.test.dunit.VM)3 InterruptedIOException (java.io.InterruptedIOException)2 ConnectException (java.net.ConnectException)2 SocketException (java.net.SocketException)2