GEODE-7593: Force index to use Strings instead of PdxStrings when eviction is enabled on region (#4500)
(cherry picked from commit 1beec9e3930a071031b960f045874fb337e72e7c)
diff --git a/geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/AbstractIndexMaintenanceIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/AbstractIndexMaintenanceIntegrationTest.java
index 9917dd1..53a9d9d 100644
--- a/geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/AbstractIndexMaintenanceIntegrationTest.java
+++ b/geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/index/AbstractIndexMaintenanceIntegrationTest.java
@@ -22,6 +22,7 @@
import org.junit.experimental.categories.Category;
import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.EvictionAttributes;
import org.apache.geode.cache.RegionShortcut;
import org.apache.geode.cache.query.CacheUtils;
import org.apache.geode.cache.query.IndexExistsException;
@@ -116,6 +117,23 @@
statusIndex.removeIndexMapping(entry, IndexProtocol.OTHER_OP);
}
+ @Test
+ public void indexKeysShouldBeStringIfRegionHasEvictionEnabled() throws Exception {
+ CacheUtils.startCache();
+ Cache cache = CacheUtils.getCache();
+ LocalRegion region =
+ (LocalRegion) cache.createRegionFactory(RegionShortcut.REPLICATE)
+ .setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes())
+ .create("portfolios");
+ QueryService qs = cache.getQueryService();
+ AbstractIndex statusIndex =
+ createIndex(qs, "statusIndex", "value.status", "/portfolios.entrySet()");
+
+ statusIndex.setPdxStringFlag(new PdxString("IndexKey"));
+ assertFalse(statusIndex.isIndexOnPdxKeys());
+ }
+
+
protected abstract AbstractIndex createIndex(final QueryService qs, String name,
String indexExpression, String regionPath)
throws IndexNameConflictException, IndexExistsException, RegionNotFoundException;
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/AbstractIndex.java b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/AbstractIndex.java
index 98f7a91..bec7fb6 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/AbstractIndex.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/AbstractIndex.java
@@ -2024,7 +2024,8 @@
return;
}
if (!this.isIndexedPdxKeys) {
- if (key instanceof PdxString && this.region.getAttributes().getCompressor() == null) {
+ if (region.getAttributes().getEvictionAttributes().isNoEviction() == true
+ && key instanceof PdxString && this.region.getAttributes().getCompressor() == null) {
this.isIndexedPdxKeys = true;
}
}