You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ja...@apache.org on 2017/09/22 17:18:07 UTC

[geode] branch develop updated: GEODE-3672: Partitioned Indexes now properly clean up if they fail to create

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

jasonhuynh pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 124be5d  GEODE-3672: Partitioned Indexes now properly clean up if they fail to create
124be5d is described below

commit 124be5d8ebfda3b112abf2a6a8c1bf921a74a22b
Author: Jason Huynh <hu...@gmail.com>
AuthorDate: Tue Sep 19 13:58:29 2017 -0700

    GEODE-3672: Partitioned Indexes now properly clean up if they fail to create
---
 .../geode/internal/cache/PartitionedRegion.java    |  2 +-
 .../query/functional/IndexCreationJUnitTest.java   | 32 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
index 8410c00..907df88 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PartitionedRegion.java
@@ -8355,7 +8355,7 @@ public class PartitionedRegion extends LocalRegion
       // If the index is not successfully created, remove IndexTask from the map.
       if (index == null) {
         ind = this.indexes.get(indexTask);
-        if (index != null && !(index instanceof Index)) {
+        if (ind != null && !(ind instanceof Index)) {
           this.indexes.remove(indexTask);
         }
       }
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/functional/IndexCreationJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/functional/IndexCreationJUnitTest.java
index 3c64465..c3be306 100755
--- a/geode-core/src/test/java/org/apache/geode/cache/query/functional/IndexCreationJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/functional/IndexCreationJUnitTest.java
@@ -41,8 +41,10 @@ import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.EvictionAction;
 import org.apache.geode.cache.EvictionAttributes;
 import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
 import org.apache.geode.cache.query.CacheUtils;
 import org.apache.geode.cache.query.Index;
+import org.apache.geode.cache.query.IndexInvalidException;
 import org.apache.geode.cache.query.IndexStatistics;
 import org.apache.geode.cache.query.IndexType;
 import org.apache.geode.cache.query.Query;
@@ -79,6 +81,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Properties;
 import java.util.Set;
+import java.util.stream.IntStream;
 
 @Category(IntegrationTest.class)
 public class IndexCreationJUnitTest {
@@ -1004,6 +1007,35 @@ public class IndexCreationJUnitTest {
     assertEquals("Index should not have been empty ", 4, i3.getStatistics().getNumberOfValues());
   }
 
+
+  @Test
+  public void failedIndexCreationCorrectlyRemovesItself() throws Exception {
+    QueryService qs;
+    qs = CacheUtils.getQueryService();
+    Cache cache = CacheUtils.getCache();
+    cache.createRegionFactory(RegionShortcut.PARTITION).create("portfoliosInPartitionedRegion");
+    Region region = CacheUtils.getCache().getRegion("/portfoliosInPartitionedRegion");
+    IntStream.range(0, 3).forEach((i) -> {
+      region.put(i, new Portfolio(i));
+    });
+
+    Index i1 = qs.createIndex("statusIndex", "secId",
+        "/portfoliosInPartitionedRegion p, p.positions pos, pos.secId secId");
+    try {
+      Index i2 =
+          qs.createIndex("anotherIndex", "secId", "/portfoliosInPartitionedRegion p, p.positions");
+      // index should fail to create
+      fail();
+    } catch (IndexInvalidException e) {
+    }
+    qs.removeIndex(i1);
+    // This test should not throw an exception if i2 was properly cleaned up.
+    Index i3 = qs.createIndex("anotherIndex", "secType",
+        "/portfoliosInPartitionedRegion p, p.positions pos, pos.secType secType");
+    assertNotNull(i3);
+  }
+
+
   private static class QueryObserverImpl extends QueryObserverAdapter {
 
     boolean isIndexesUsed = false;

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].