Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DB74D18D76 for ; Wed, 16 Sep 2015 22:18:16 +0000 (UTC) Received: (qmail 12285 invoked by uid 500); 16 Sep 2015 22:18:04 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 12248 invoked by uid 500); 16 Sep 2015 22:18:04 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 12239 invoked by uid 99); 16 Sep 2015 22:18:04 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Sep 2015 22:18:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id B537A180333 for ; Wed, 16 Sep 2015 22:18:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.775 X-Spam-Level: * X-Spam-Status: No, score=1.775 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.006, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id GaML0o6mqviu for ; Wed, 16 Sep 2015 22:17:56 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 25D3843DCA for ; Wed, 16 Sep 2015 22:17:56 +0000 (UTC) Received: (qmail 12180 invoked by uid 99); 16 Sep 2015 22:17:55 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Sep 2015 22:17:55 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 91ABCDFAB5; Wed, 16 Sep 2015 22:17:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: boglesby@apache.org To: commits@geode.incubator.apache.org Message-Id: <353aa6f7ef5d4f99ac457b1b5f9d7cb8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: incubator-geode git commit: GEODE-333: Indexes sometimes are no longer used after a rebalance Date: Wed, 16 Sep 2015 22:17:55 +0000 (UTC) Repository: incubator-geode Updated Branches: refs/heads/develop 4e65f0c72 -> 2c99b9e6d 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/develop Commit: 2c99b9e6dbbae1f7fa169f43b3708328cb4d0ebf Parents: 4e65f0c Author: Barry Oglesby Authored: Wed Sep 16 14:35:37 2015 -0700 Committer: Barry Oglesby 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 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> getFirstBucketIndex() + { + Map.Entry> 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> 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> 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 {