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

sergey-chugunov-1985 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 56c847eb7c5 IGNITE-28806 Fix dynamic cache group affinity init during 
first local join (#13263)
56c847eb7c5 is described below

commit 56c847eb7c513170a64f85ca0d408e0919b6f42c
Author: oleg-vlsk <[email protected]>
AuthorDate: Wed Jul 15 16:36:11 2026 +1000

    IGNITE-28806 Fix dynamic cache group affinity init during first local join 
(#13263)
---
 .../cache/CacheAffinitySharedManager.java          |  43 +++++++-
 .../cache/CacheAffinityCoordinatorInitTest.java    | 111 +++++++++++++++++++++
 .../ignite/testsuites/IgniteCacheTestSuite6.java   |   3 +
 3 files changed, 153 insertions(+), 4 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
index b363cbef0ce..613e49c3908 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheAffinitySharedManager.java
@@ -1955,16 +1955,27 @@ public class CacheAffinitySharedManager<K, V> extends 
GridCacheSharedManagerAdap
 
         forAllRegisteredCacheGroups(new 
IgniteInClosureX<CacheGroupDescriptor>() {
             @Override public void applyx(CacheGroupDescriptor desc) throws 
IgniteCheckedException {
+                int grpId = desc.groupId();
+
+                CacheGroupContext grp = cctx.cache().cacheGroup(grpId);
+
+                if (skipNotStartedDynamicGroup(fut, desc, grp, newAff)) {
+                    if (log.isDebugEnabled()) {
+                        log.debug("Skip coordinator affinity initialization 
for cache group started after" +
+                            " current exchange [grp=" + 
desc.cacheOrGroupName() +
+                            ", grpId=" + grpId + ", curTopVer=" + topVer +
+                            ", grpStartTopVer=" + desc.startTopologyVersion() 
+ ']');
+                    }
+
+                    return;
+                }
+
                 CacheGroupHolder grpHolder = getOrCreateGroupHolder(topVer, 
desc);
 
                 if (grpHolder.affinity().idealAssignmentRaw() != null)
                     return;
 
                 // Need initialize holders and affinity if this node became 
coordinator during this exchange.
-                int grpId = desc.groupId();
-
-                CacheGroupContext grp = cctx.cache().cacheGroup(grpId);
-
                 if (grp == null) {
                     grpHolder = CacheGroupNoAffOrFilteredHolder.create(cctx, 
desc, topVer, null);
 
@@ -2079,6 +2090,30 @@ public class CacheAffinitySharedManager<K, V> extends 
GridCacheSharedManagerAdap
         return null;
     }
 
+    /**
+     * Checks whether the given cache group has not started at this exchange. 
If so, it is safe to skip it here as
+     * its affinity and local group context will be initialized later by its 
own exchange.
+     *
+     * @param fut Current exchange future.
+     * @param desc Cache group descriptor.
+     * @param grp Local cache group context.
+     * @param newAff {@code True} if there are no older nodes with affinity 
info available.
+     * @return {@code True} if the group must be skipped by the current 
exchange.
+     */
+    private boolean skipNotStartedDynamicGroup(
+        GridDhtPartitionsExchangeFuture fut,
+        CacheGroupDescriptor desc,
+        @Nullable CacheGroupContext grp,
+        boolean newAff
+    ) {
+        if (grp != null || newAff)
+            return false;
+
+        AffinityTopologyVersion grpStartTopVer = desc.startTopologyVersion();
+
+        return grpStartTopVer != null && 
grpStartTopVer.after(fut.initialVersion());
+    }
+
     /**
      * @param topVer Topology version.
      * @param desc Cache descriptor.
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAffinityCoordinatorInitTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAffinityCoordinatorInitTest.java
new file mode 100644
index 00000000000..87489b8337d
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheAffinityCoordinatorInitTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+/** */
+public class CacheAffinityCoordinatorInitTest extends GridCommonAbstractTest {
+    /** */
+    private static final int SRV_NODES = 3;
+
+    /** */
+    private static final int STATIC_GROUPS = 3;
+
+    /** */
+    private static final int CACHES_PER_GROUP = 2;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        List<CacheConfiguration<?, ?>> caches = new ArrayList<>();
+
+        for (int grpIdx = 0; grpIdx < STATIC_GROUPS; grpIdx++) {
+            for (int cacheIdx = 0; cacheIdx < CACHES_PER_GROUP; cacheIdx++) {
+                caches.add(new CacheConfiguration<>(cacheName(grpIdx, 
cacheIdx))
+                    .setGroupName(groupName(grpIdx))
+                    .setCacheMode(CacheMode.PARTITIONED)
+                    .setAtomicityMode(CacheAtomicityMode.ATOMIC)
+                    .setBackups(1));
+            }
+        }
+
+        cfg.setCacheConfiguration(caches.toArray(new CacheConfiguration[0]));
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids(true);
+
+        super.afterTest();
+    }
+
+    /** */
+    @Test
+    public void testStaticCacheGroupsOnCoordinatorStart() throws Exception {
+        startGrids(SRV_NODES);
+
+        awaitPartitionMapExchange();
+
+        for (int i = 0; i < SRV_NODES; i++) {
+            IgniteEx node = grid(i);
+
+            for (int grpIdx = 0; grpIdx < STATIC_GROUPS; grpIdx++) {
+                String grpName = groupName(grpIdx);
+
+                int grpId = CU.cacheId(grpName);
+
+                assertNotNull(
+                    "Cache group context was not created [node=" + i + ", 
grp=" + grpName + ']',
+                    node.context().cache().cacheGroup(grpId)
+                );
+
+                for (int cacheIdx = 0; cacheIdx < CACHES_PER_GROUP; 
cacheIdx++) {
+                    String cacheName = cacheName(grpIdx, cacheIdx);
+
+                    assertNotNull(
+                        "Cache was not started [node=" + i + ", cache=" + 
cacheName + ']',
+                        node.cache(cacheName)
+                    );
+                }
+            }
+        }
+    }
+
+    /** */
+    private String cacheName(int grpIdx, int cacheIdx) {
+        return "static-cache-" + grpIdx + '-' + cacheIdx;
+    }
+
+    /** */
+    private String groupName(int grpIdx) {
+        return "static-group-" + grpIdx;
+    }
+}
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite6.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite6.java
index 2b29ca6c085..9a606cf27b8 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite6.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite6.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import org.apache.ignite.cache.affinity.PendingExchangeTest;
+import 
org.apache.ignite.internal.processors.cache.CacheAffinityCoordinatorInitTest;
 import 
org.apache.ignite.internal.processors.cache.CacheIgniteOutOfMemoryExceptionTest;
 import org.apache.ignite.internal.processors.cache.CacheNoAffinityExchangeTest;
 import 
org.apache.ignite.internal.processors.cache.ClientFastReplyCoordinatorFailureTest;
@@ -118,6 +119,8 @@ public class IgniteCacheTestSuite6 {
 
         GridTestUtils.addTestIfNeeded(suite, 
TransactionContextCleanupTest.class, ignoredTests);
 
+        GridTestUtils.addTestIfNeeded(suite, 
CacheAffinityCoordinatorInitTest.class, ignoredTests);
+
         return suite;
     }
 }

Reply via email to