This is an automated email from the ASF dual-hosted git repository.

alexpl pushed a commit to branch ignite-23578
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit 608d05669713e9949046abba2bea9ee91e6321f2
Author: Aleksey Plekhanov <[email protected]>
AuthorDate: Wed Oct 30 17:42:07 2024 +0300

    IGNITE-23578 Fix removal of affinity assignment necessary instance from 
affinity cache
---
 .../affinity/GridAffinityAssignmentCache.java      |  6 +++
 .../processors/query/SqlAffinityCacheTest.java     | 55 ++++++++++++++++++++++
 .../IgniteBinaryCacheQueryTestSuite4.java          |  5 +-
 3 files changed, 64 insertions(+), 2 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
index 9b3f1346c96..e6bd76adec8 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java
@@ -978,9 +978,15 @@ public class GridAffinityAssignmentCache {
 
             Iterator<HistoryAffinityAssignment> it = 
affCache.values().iterator();
 
+            AffinityTopologyVersion lastAffChangeTopVer =
+                
ctx.cache().context().exchange().lastAffinityChangedTopologyVersion(head.get().topologyVersion());
+
             while (it.hasNext()) {
                 HistoryAffinityAssignment aff0 = it.next();
 
+                if (aff0.topologyVersion().equals(lastAffChangeTopVer))
+                    continue; // Keep lastAffinityChangedTopologyVersion, it's 
required for some operations.
+
                 if (aff0.requiresHistoryCleanup()) {
                     // We can stop cleanup only on non-shallow item.
                     // Keeping part of shallow items chain if corresponding 
real item is missing makes no sense.
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlAffinityCacheTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlAffinityCacheTest.java
new file mode 100644
index 00000000000..01567e11447
--- /dev/null
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/SqlAffinityCacheTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.query;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import 
org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class SqlAffinityCacheTest extends AbstractIndexingCommonTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        return super.getConfiguration(igniteInstanceName)
+            .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
+                .setIndexedTypes(Integer.class, String.class));
+    }
+
+    /**
+     * Test that affinity assignment instance (required for queries) is not 
removed from affinity cache
+     * after numerous client node left/join events.
+     */
+    @Test
+    public void testAffinityCache() throws Exception {
+        startGrid(0);
+
+        for (int i = 0; i < 300; i++) {
+            startClientGrid(1);
+            stopGrid(1);
+        }
+
+        IgniteCache<Integer, String> cache = grid(0).cache(DEFAULT_CACHE_NAME);
+        cache.put(0, "0");
+
+        assertEquals(1, cache.query(new SqlFieldsQuery("SELECT * FROM 
String")).getAll().size());
+    }
+}
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite4.java
 
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite4.java
index 3d2732584b3..e0013831966 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite4.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite4.java
@@ -27,6 +27,7 @@ import 
org.apache.ignite.internal.processors.query.DmlBatchSizeDeadlockTest;
 import 
org.apache.ignite.internal.processors.query.IgniteSqlCreateTableTemplateTest;
 import org.apache.ignite.internal.processors.query.LocalQueryLazyTest;
 import org.apache.ignite.internal.processors.query.LongRunningQueryTest;
+import org.apache.ignite.internal.processors.query.SqlAffinityCacheTest;
 import 
org.apache.ignite.internal.processors.query.SqlLocalQueryConnectionAndStatementTest;
 import 
org.apache.ignite.internal.processors.query.SqlPartOfComplexPkLookupTest;
 import 
org.apache.ignite.internal.processors.query.SqlQueriesTopologyMappingTest;
@@ -93,8 +94,8 @@ import org.junit.runners.Suite;
 
     SqlQueriesTopologyMappingTest.class,
 
-    IgniteCacheQueryReservationOnUnstableTopologyTest.class
-
+    IgniteCacheQueryReservationOnUnstableTopologyTest.class,
+    SqlAffinityCacheTest.class,
 })
 public class IgniteBinaryCacheQueryTestSuite4 {
     /** Setup lazy mode default. */

Reply via email to