Skip to content

Commit

Permalink
GEODE-7593: Force index to use Strings instead of PdxStrings when evi…
Browse files Browse the repository at this point in the history
…ction is enabled on region (apache#4500)

(cherry picked from commit 1beec9e)
  • Loading branch information
jhuynh1 authored and mhansonp committed Dec 19, 2019
1 parent 0890c4f commit a36eadc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,6 +117,23 @@ public void whenRemovingRegionEntryFromIndexIfEntryDestroyedIsThrownCorrectlyRem
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,8 @@ synchronized void setPdxStringFlag(Object key) {
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;
}
}
Expand Down

0 comments on commit a36eadc

Please sign in to comment.