alex-plekhanov commented on code in PR #11736: URL: https://github.com/apache/ignite/pull/11736#discussion_r1895833526
########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java: ########## @@ -1365,12 +1365,16 @@ private void sendTtlUpdateRequest( @Nullable UUID srcNodeId ) { if (!F.isEmpty(expiryPlc.entries())) { + Map<KeyCacheObject, GridCacheVersion> entries = Map.copyOf(expiryPlc.entries()); + + assert entries != null && !entries.isEmpty(); Review Comment: 1. Can be replaced with `!F.isEmpty(entries)` 2. Already checked two lines before and looks like can't be modified concurrently now ########## modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite4.java: ########## @@ -101,6 +102,8 @@ ScanQueryTransactionsUnsupportedModesTest.class, ScanQueryTransactionIsolationTest.class, + + ScanQueryUpdateTtlTest.class, Review Comment: It's strange that we have all scan-query tests in indexing-module suite. Looks like they are not related to indexing and should be in core-module. But ok, let's keep it as is. ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java: ########## @@ -1365,12 +1365,16 @@ private void sendTtlUpdateRequest( @Nullable UUID srcNodeId ) { if (!F.isEmpty(expiryPlc.entries())) { + Map<KeyCacheObject, GridCacheVersion> entries = Map.copyOf(expiryPlc.entries()); + + assert entries != null && !entries.isEmpty(); + + Map<UUID, Collection<IgniteBiTuple<KeyCacheObject, GridCacheVersion>>> rdrs = + expiryPlc.readers() != null ? Map.copyOf(expiryPlc.readers()) : null; + ctx.closures().runLocalSafe(new GridPlainRunnable() { @SuppressWarnings({"ForLoopReplaceableByForEach"}) @Override public void run() { - Map<KeyCacheObject, GridCacheVersion> entries = expiryPlc.entries(); - - assert entries != null && !entries.isEmpty(); Review Comment: Redundant NL ########## modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryUpdateTtlTest.java: ########## @@ -0,0 +1,112 @@ +/* + * 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; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; +import javax.cache.expiry.Duration; +import javax.cache.expiry.TouchedExpiryPolicy; +import org.apache.ignite.IgniteException; +import org.apache.ignite.cache.query.ScanQuery; +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.TestRecordingCommunicationSpi; +import org.apache.ignite.internal.managers.communication.GridIoMessage; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.distributed.GridCacheTtlUpdateRequest; +import org.apache.ignite.lang.IgniteInClosure; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.apache.ignite.spi.IgniteSpiException; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.apache.ignite.internal.processors.cache.query.ScanQueryIterator.EXPIRE_ENTRIES_FLUSH_CNT; + +/** */ +public class ScanQueryUpdateTtlTest extends GridCommonAbstractTest { + /** */ + private static final int KEYS = EXPIRE_ENTRIES_FLUSH_CNT * 3; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + if (!cfg.isClientMode()) { + cfg.setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME) + .setBackups(1) + .setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 60)))); + } + + cfg.setCommunicationSpi(new CheckingCommunicationSpi()); + + return cfg; + } + + /** */ + @Test + public void testScanQueryIteratorExpireEntriesFlush() throws Exception { + try (IgniteEx ignored = startGrids(2)) { + try (IgniteEx cln = startClientGrid(2)) { + for (int i = 0; i < KEYS; i++) + cln.cache(DEFAULT_CACHE_NAME).put(i, i); + + cln.cache(DEFAULT_CACHE_NAME).query(new ScanQuery<>()).forEach((v) -> {}); + } + + grid(0).context().pools().getStripedExecutorService().awaitComplete(); + grid(1).context().pools().getStripedExecutorService().awaitComplete(); + + assertTrue("Each key must be sent only once", CheckingCommunicationSpi.keyCnt.values().stream().allMatch(c -> c == 1)); + + assertTrue("Single GridCacheTtlUpdateRequest must be sent with no more then maximum allowed keys " + + "[maxAllowed=" + (EXPIRE_ENTRIES_FLUSH_CNT + 1) + Review Comment: Let's add comment why `EXPIRE_ENTRIES_FLUSH_CNT + 1` (`readyToFlush` method checks `entries.size() > EXPIRE_ENTRIES_FLUSH_CNT`) ########## modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/ScanQueryUpdateTtlTest.java: ########## @@ -0,0 +1,112 @@ +/* + * 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; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; +import javax.cache.expiry.Duration; +import javax.cache.expiry.TouchedExpiryPolicy; +import org.apache.ignite.IgniteException; +import org.apache.ignite.cache.query.ScanQuery; +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.TestRecordingCommunicationSpi; +import org.apache.ignite.internal.managers.communication.GridIoMessage; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.distributed.GridCacheTtlUpdateRequest; +import org.apache.ignite.lang.IgniteInClosure; +import org.apache.ignite.plugin.extensions.communication.Message; +import org.apache.ignite.spi.IgniteSpiException; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +import static org.apache.ignite.internal.processors.cache.query.ScanQueryIterator.EXPIRE_ENTRIES_FLUSH_CNT; + +/** */ +public class ScanQueryUpdateTtlTest extends GridCommonAbstractTest { + /** */ + private static final int KEYS = EXPIRE_ENTRIES_FLUSH_CNT * 3; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + if (!cfg.isClientMode()) { + cfg.setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME) + .setBackups(1) + .setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 60)))); + } + + cfg.setCommunicationSpi(new CheckingCommunicationSpi()); + + return cfg; + } + + /** */ + @Test + public void testScanQueryIteratorExpireEntriesFlush() throws Exception { + try (IgniteEx ignored = startGrids(2)) { + try (IgniteEx cln = startClientGrid(2)) { + for (int i = 0; i < KEYS; i++) + cln.cache(DEFAULT_CACHE_NAME).put(i, i); + + cln.cache(DEFAULT_CACHE_NAME).query(new ScanQuery<>()).forEach((v) -> {}); + } + + grid(0).context().pools().getStripedExecutorService().awaitComplete(); + grid(1).context().pools().getStripedExecutorService().awaitComplete(); + + assertTrue("Each key must be sent only once", CheckingCommunicationSpi.keyCnt.values().stream().allMatch(c -> c == 1)); + + assertTrue("Single GridCacheTtlUpdateRequest must be sent with no more then maximum allowed keys " + + "[maxAllowed=" + (EXPIRE_ENTRIES_FLUSH_CNT + 1) + + ", maxActual=" + CheckingCommunicationSpi.maxKeyBatchCnt + "]", + CheckingCommunicationSpi.maxKeyBatchCnt <= EXPIRE_ENTRIES_FLUSH_CNT + 1); + + assertEquals("All keys must be sent", KEYS, CheckingCommunicationSpi.keyCnt.keySet().size()); + } + } + + /** */ + private static class CheckingCommunicationSpi extends TestRecordingCommunicationSpi { + /** */ + private static int maxKeyBatchCnt = 0; + + /** */ + private static Map<KeyCacheObject, Integer> keyCnt = new ConcurrentHashMap<>(KEYS); Review Comment: 1. `private static final` 2. `new ConcurrentHashMap<>(U.capacity(KEYS))` -- 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. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org