geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bschucha...@apache.org
Subject [12/26] incubator-geode git commit: GEODE-333: Indexes sometimes are no longer used after a rebalance
Date Thu, 01 Oct 2015 17:58:53 GMT
GEODE-333: Indexes sometimes are no longer used after a rebalance

Incorporated changes from GemFire


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/2c99b9e6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/2c99b9e6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/2c99b9e6

Branch: refs/heads/feature/GEODE-77
Commit: 2c99b9e6dbbae1f7fa169f43b3708328cb4d0ebf
Parents: 4e65f0c
Author: Barry Oglesby <boglesby@pivotal.io>
Authored: Wed Sep 16 14:35:37 2015 -0700
Committer: Barry Oglesby <boglesby@pivotal.io>
Committed: Wed Sep 16 14:47:06 2015 -0700

----------------------------------------------------------------------
 .../index/FunctionalIndexCreationHelper.java    |  1 -
 .../query/internal/index/PartitionedIndex.java  | 16 +++++-
 .../query/internal/index/IndexUseJUnitTest.java | 52 ++++++++++++++++++++
 3 files changed, 67 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2c99b9e6/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/FunctionalIndexCreationHelper.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/FunctionalIndexCreationHelper.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/FunctionalIndexCreationHelper.java
index a2b48c3..e3f5209 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/FunctionalIndexCreationHelper.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/FunctionalIndexCreationHelper.java
@@ -581,7 +581,6 @@ class FunctionalIndexCreationHelper extends IndexCreationHelper {
       }
     }
     catch (Exception e) {
-      e.printStackTrace();
       throw new IndexInvalidException(e);
     }
     return retValues;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2c99b9e6/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/PartitionedIndex.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/PartitionedIndex.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/PartitionedIndex.java
index b89a738..d41f706 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/PartitionedIndex.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/query/internal/index/PartitionedIndex.java
@@ -121,6 +121,9 @@ public class PartitionedIndex extends AbstractIndex
       List<Index> indexes = this.bucketIndexes.get(r);
       if(indexes != null) {
         indexes.remove(index);
+        if (indexes.isEmpty()) {
+          this.bucketIndexes.remove(r);
+        }
       }
     }
   }
@@ -187,6 +190,17 @@ public class PartitionedIndex extends AbstractIndex
     return index;
   }
   
+  protected Map.Entry<Region,List<Index>> getFirstBucketIndex()
+  {
+    Map.Entry<Region,List<Index>> firstIndexEntry = null;
+    synchronized(this.bucketIndexes) {
+      if (this.bucketIndexes.size() > 0) {
+        firstIndexEntry = this.bucketIndexes.entrySet().iterator().next();
+      }
+    }
+    return firstIndexEntry;
+  }
+
   /**
    * Returns the type of index this partitioned index represents.
    * @return  indexType type of partitioned index.
@@ -242,7 +256,7 @@ public class PartitionedIndex extends AbstractIndex
         throw new QueryInvocationTargetException("Bucket not found for the id :" + bId);
       }
       IndexManager im = IndexUtils.getIndexManager(bukRegion, true); 
-      if (im.getIndex(indexName) == null) { 
+      if (im != null && im.getIndex(indexName) == null) { 
         try {
           if (pr.getCache().getLogger().fineEnabled()) {
             pr.getCache().getLogger().fine("Verifying index presence on bucket region. "
+

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/2c99b9e6/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/IndexUseJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/IndexUseJUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/IndexUseJUnitTest.java
index 81bec89..8cb9ded 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/IndexUseJUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/query/internal/index/IndexUseJUnitTest.java
@@ -29,6 +29,8 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import com.gemstone.gemfire.cache.AttributesFactory;
+import com.gemstone.gemfire.cache.PartitionAttributesFactory;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.query.CacheUtils;
 import com.gemstone.gemfire.cache.query.Index;
@@ -1740,6 +1742,51 @@ public class IndexUseJUnitTest
       }
     }
 
+    @Test
+    public void testBug52444() throws Exception {
+        // Create partitioned region
+        PartitionAttributesFactory paf = new PartitionAttributesFactory();
+        AttributesFactory af = new AttributesFactory();
+        af.setPartitionAttributes(paf.create());
+        Region region = CacheUtils.createRegion("testBug52444", af.create(), false);
+
+        // Add index
+        PartitionedIndex index = (PartitionedIndex) qs.createIndex("statusIndex", "status",
region.getFullPath());
+
+        // Do puts
+        for (int i=0; i<200; i++) {
+          region.put(i, new Portfolio(i));
+        }
+        
+        // Initialize query observer
+        QueryObserverImpl observer = new QueryObserverImpl();
+        QueryObserverHolder.setInstance(observer);
+        
+        // Create and run query
+        Query query = qs.newQuery("SELECT * FROM " + region.getFullPath() + " where status
= 'active'");
+        query.execute();
+
+        // Verify index was used
+        assertTrue(observer.isIndexesUsed);
+
+        // Get the first index entry in the PartitionedIndex bucketIndexes and delete the
index from it (to simulate what happens when a bucket is moved)
+        Map.Entry<Region,List<Index>> firstIndexEntry = index.getFirstBucketIndex();
+        assertTrue(!firstIndexEntry.getValue().isEmpty());
+        index.removeFromBucketIndexes(firstIndexEntry.getKey(), firstIndexEntry.getValue().iterator().next());
+        
+        // Verify the index was removed from the entry and the entry was removed from the
bucket indexes
+        assertTrue(firstIndexEntry.getValue().isEmpty());      
+        Map.Entry<Region,List<Index>> nextFirstIndexEntry = index.getFirstBucketIndex();
+        assertTrue(!nextFirstIndexEntry.getValue().isEmpty());
+        
+        // Run query again
+        observer.reset();
+        query.execute();
+        
+        // Verify index was still used
+        assertTrue(observer.isIndexesUsed);
+      }
+
   class QueryObserverImpl extends QueryObserverAdapter
   {
     boolean isIndexesUsed = false;
@@ -1755,6 +1802,11 @@ public class IndexUseJUnitTest
         isIndexesUsed = true;
       }
     }
+    
+    public void reset() {
+      this.isIndexesUsed = false;
+      this.indexesUsed.clear();
+    }
   }
   
   public class RangeIndexTestHook implements TestHook {


Mime
View raw message