You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by on...@apache.org on 2020/08/04 02:40:08 UTC

[geode] branch support/1.12 updated: GEODE-6564: fix entryExpiryTasks leak (#5419)

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

onichols pushed a commit to branch support/1.12
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/support/1.12 by this push:
     new f64838f  GEODE-6564: fix entryExpiryTasks leak (#5419)
f64838f is described below

commit f64838f695d56029c0a8b08804f16d5ca9da7156
Author: Darrel Schneider <ds...@pivotal.io>
AuthorDate: Mon Aug 3 14:37:39 2020 -0700

    GEODE-6564: fix entryExpiryTasks leak (#5419)
    
    (cherry picked from commit 53abb22cd295441f8794e15550b72ec81113ec05)
---
 .../apache/geode/internal/cache/LocalRegion.java   | 10 ++-
 ...eplicateWithExpirationClearIntegrationTest.java | 71 ++++++++++++++++++++++
 2 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
index 6a7e2d2..a4ccb73 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java
@@ -7955,7 +7955,10 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
       return;
     }
     boolean doPurge = false;
-    for (EntryExpiryTask task : entryExpiryTasks.values()) {
+    Iterator<EntryExpiryTask> iterator = entryExpiryTasks.values().iterator();
+    while (iterator.hasNext()) {
+      EntryExpiryTask task = iterator.next();
+      iterator.remove();
       // no need to call incCancels since we will call forcePurge
       task.cancel();
       doPurge = true;
@@ -11283,4 +11286,9 @@ public class LocalRegion extends AbstractRegion implements LoaderHelperFactory,
       }
     }
   }
+
+  @VisibleForTesting
+  ConcurrentHashMap<RegionEntry, EntryExpiryTask> getEntryExpiryTasks() {
+    return entryExpiryTasks;
+  }
 }
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/ReplicateWithExpirationClearIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/ReplicateWithExpirationClearIntegrationTest.java
new file mode 100644
index 0000000..6ddb31c
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/ReplicateWithExpirationClearIntegrationTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.geode.internal.cache;
+
+import static org.apache.geode.cache.ExpirationAction.DESTROY;
+import static org.apache.geode.cache.RegionShortcut.REPLICATE;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.ExpirationAttributes;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+
+public class ReplicateWithExpirationClearIntegrationTest {
+
+  private Cache cache;
+  private String regionName;
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Before
+  public void setUp() {
+    regionName = testName.getMethodName() + "_Region";
+    cache = new CacheFactory().set(LOCATORS, "").set(MCAST_PORT, "0").create();
+  }
+
+  @After
+  public void tearDown() {
+    cache.close();
+  }
+
+  @Test
+  public void clearDoesNotLeaveEntryExpiryTaskInRegion() {
+    RegionFactory<String, String> regionFactory = cache.createRegionFactory(REPLICATE);
+    regionFactory.setEntryTimeToLive(new ExpirationAttributes(2000, DESTROY));
+    Region<String, String> region = regionFactory.create(regionName);
+    try {
+      LocalRegion localRegion = (LocalRegion) region;
+      region.put("key", "value");
+      assertThat(localRegion.getEntryExpiryTasks()).hasSize(1);
+      region.clear();
+      assertThat(localRegion.getEntryExpiryTasks()).isEmpty();
+    } finally {
+      region.destroyRegion();
+    }
+  }
+}