Skip to content

Commit 1c318e1

Browse files
IGNITE-21478 Fix OOM crash on unstable topology (#11283)
1 parent db4ac5f commit 1c318e1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

modules/core/src/main/java/org/apache/ignite/internal/processors/affinity/GridAffinityAssignmentCache.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public void clientEventTopologyChange(DiscoveryEvent evt, AffinityTopologyVersio
575575

576576
Map.Entry<AffinityTopologyVersion, HistoryAffinityAssignment> prevHistEntry = affCache.floorEntry(prevVer);
577577

578-
HistoryAffinityAssignment newHistEntry = (prevHistEntry == null) ?
578+
HistoryAffinityAssignment newHistEntry = (prevHistEntry == null || shouldCleanupShallows()) ?
579579
new HistoryAffinityAssignmentImpl(assignmentCpy, backups) :
580580
new HistoryAffinityAssignmentShallowCopy(prevHistEntry.getValue().origin(), topVer);
581581

@@ -1019,6 +1019,11 @@ private boolean shouldContinueCleanup(int nonShallowSize, int totalSize) {
10191019
return nonShallowSize > MAX_NON_SHALLOW_HIST_SIZE || totalSize > MAX_TOTAL_HIST_SIZE;
10201020
}
10211021

1022+
/** */
1023+
private boolean shouldCleanupShallows() {
1024+
return nonShallowHistSize.get() <= MIN_NON_SHALLOW_HIST_SIZE && affCache.size() > MAX_TOTAL_HIST_SIZE;
1025+
}
1026+
10221027
/**
10231028
* @return All initialized versions.
10241029
*/

modules/core/src/test/java/org/apache/ignite/internal/processors/affinity/GridHistoryAffinityAssignmentTest.java

+28
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,32 @@ private GridAffinityAssignmentCache affinityCache(IgniteEx ignite) {
129129

130130
return GridTestUtils.getFieldValue(cctx.affinity(), "aff");
131131
}
132+
133+
/** */
134+
@Test
135+
public void testAffinityCacheSizeOnCacheRecreate() throws Exception {
136+
try (IgniteEx server = startGrid(0)) {
137+
try (IgniteEx client = startClientGrid()) {
138+
for (int i = 0; i < 300; i++) {
139+
client.getOrCreateCache(DEFAULT_CACHE_NAME);
140+
141+
server.context().cache().cacheGroups().forEach(x -> assertTrue(x.affinity().cachedVersions().size() < 260));
142+
143+
client.destroyCache(DEFAULT_CACHE_NAME);
144+
}
145+
}
146+
}
147+
}
148+
149+
/** */
150+
@Test
151+
public void testAffinityCacheSizeOnReconnect() throws Exception {
152+
try (IgniteEx server = startGrid(0)) {
153+
for (int i = 0; i < 300; i++) {
154+
try (IgniteEx client = startClientGrid()) {
155+
server.context().cache().cacheGroups().forEach(x -> assertTrue(x.affinity().cachedVersions().size() < 260));
156+
}
157+
}
158+
}
159+
}
132160
}

0 commit comments

Comments
 (0)