You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/07/06 11:10:14 UTC

[GitHub] [ignite] Mmuzaf commented on a change in pull request #7881: IGNITE-10959: Continuous query pending buffer limit

Mmuzaf commented on a change in pull request #7881:
URL: https://github.com/apache/ignite/pull/7881#discussion_r450149629



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEventBuffer.java
##########
@@ -172,21 +204,51 @@ private Object process0(long cntr, CacheContinuousQueryEntry entry, boolean back
                 if (res == RETRY)
                     continue;
             }
-            else
+            else {
+                if (batch.endCntr < ackedUpdCntr.get())
+                    batch.tryRollOver(entry.topologyVersion());
+
+                if (pendingSize.get() > MAX_PENDING_BUFF_SIZE) {
+                    LT.warn(log, "Buffer for pending events reached max of its size " +
+                        "[cacheId=" + entry.cacheId() + ", maxSize=" + MAX_PENDING_BUFF_SIZE +
+                        ", partId=" + entry.partition() + ']');
+
+                    // Remove first BUFF_SIZE keys.
+                    int keysToRemove = BUF_SIZE;
+
+                    Iterator<Map.Entry<Long, CacheContinuousQueryEntry>> iter = pending.entrySet().iterator();
+
+                    while (iter.hasNext() && keysToRemove > 0) {
+                        CacheContinuousQueryEntry entry0 = iter.next().getValue();
+
+                        // Discard messages on backup and send to client if primary.
+                        if (!backup)
+                            res = addResult(res, entry0, !backup);

Review comment:
       Fixed.

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryBufferLimitTest.java
##########
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.query.continuous;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+import javax.cache.configuration.FactoryBuilder;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
+import org.apache.ignite.cache.query.CacheQueryEntryEvent;
+import org.apache.ignite.cache.query.ContinuousQuery;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.TestRecordingCommunicationSpi;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheIdMessage;
+import org.apache.ignite.internal.processors.continuous.GridContinuousProcessor;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.plugin.extensions.communication.Message;
+import org.apache.ignite.spi.systemview.view.ContinuousQueryView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.WithSystemProperty;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+import static org.apache.ignite.internal.TestRecordingCommunicationSpi.spi;
+import static org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.CQ_SYS_VIEW;
+import static org.apache.ignite.testframework.GridTestUtils.getFieldValue;
+import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+
+/**
+ *
+ */
+@RunWith(Parameterized.class)
+public class CacheContinuousQueryBufferLimitTest extends GridCommonAbstractTest {
+    /** Cache partitions count. */
+    private static final int PARTS = 1;
+
+    /** Total number of cache keys. */
+    private static final int TOTAL_KEYS = 1024;
+
+    /** Number of pending entries.  */
+    private static final int PENDING_LIMIT = 1100;
+
+    /** Timeout to wait for pending buffer overflow. */
+    private static final long OVERFLOW_TIMEOUT_MS = 15_000L;
+
+    /** Default remote no-op filter. */
+    private static final CacheEntryEventSerializableFilter<Integer, Integer> RMT_FILTER = e -> true;
+
+    /** Counter of cache messages being send. */
+    private final AtomicInteger msgCntr = new AtomicInteger();
+
+    /** Cache mode. */
+    @Parameterized.Parameter(0)
+    public CacheMode cacheMode;
+
+    /** Cache atomicity mode. */
+    @Parameterized.Parameter(1)
+    public CacheAtomicityMode atomicityMode;
+
+    /** @return Test parameters. */
+    @Parameterized.Parameters(name = "cacheMode={0}, atomicityMode={1}")
+    public static Collection<?> parameters() {
+        return Arrays.asList(new Object[][] {
+            {REPLICATED, ATOMIC},
+            {REPLICATED, TRANSACTIONAL},
+            {PARTITIONED, ATOMIC},
+            {PARTITIONED, TRANSACTIONAL}
+        });
+    }
+
+    /** @throws Exception If fails. */
+    @Test
+    public void testContinuousQueryBatchSwitchOnAck() throws Exception {
+        doTestContinuousQueryPendingBufferLimit((n, msg) ->
+            msg instanceof GridCacheIdMessage && msgCntr.getAndIncrement() == 10);
+    }
+
+    /** @throws Exception If fails. */
+    @Test
+    @WithSystemProperty(key = "IGNITE_CONTINUOUS_QUERY_PENDING_BUFF_SIZE", value = "1000")
+    public void testContinuousQueryPendingBufferLimit() throws Exception {
+        doTestContinuousQueryPendingBufferLimit((n, msg) ->
+            (msg instanceof GridCacheIdMessage && msgCntr.getAndIncrement() == 10) ||
+                msg instanceof CacheContinuousQueryBatchAck);
+    }
+
+

Review comment:
       Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org