-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrating IndicesRequestCache with CacheService controlled by a fea…
…ture flag Signed-off-by: Sagar Upadhyaya <[email protected]>
- Loading branch information
Showing
14 changed files
with
276 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
...src/internalClusterTest/java/org.opensearch.cache.common.tier/TieredSpilloverCacheIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cache.common.tier; | ||
|
||
import org.opensearch.action.admin.cluster.node.info.NodeInfo; | ||
import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest; | ||
import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse; | ||
import org.opensearch.action.admin.cluster.node.info.PluginsAndModules; | ||
import org.opensearch.action.search.SearchResponse; | ||
import org.opensearch.action.search.SearchType; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.common.cache.CacheType; | ||
import org.opensearch.common.cache.ICache; | ||
import org.opensearch.common.cache.settings.CacheSettings; | ||
import org.opensearch.common.cache.store.OpenSearchOnHeapCache; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.common.util.FeatureFlags; | ||
import org.opensearch.indices.IndicesRequestCache; | ||
import org.opensearch.plugins.CachePlugin; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.plugins.PluginInfo; | ||
import org.opensearch.search.aggregations.bucket.histogram.DateHistogramInterval; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.junit.Assert; | ||
|
||
import java.time.ZoneId; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static org.opensearch.search.aggregations.AggregationBuilders.dateHistogram; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; | ||
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
|
||
public class TieredSpilloverCacheIT extends OpenSearchIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Arrays.asList(TieredSpilloverCachePlugin.class, MockDiskCachePlugin.class); | ||
} | ||
|
||
@Override | ||
protected Settings featureFlagSettings() { | ||
return Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.TIERED_CACHING, "true").build(); | ||
} | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
return Settings.builder() | ||
.put(super.nodeSettings(nodeOrdinal)) | ||
.put( | ||
CacheSettings.getConcreteSettingForCacheType(CacheType.INDICES_REQUEST_CACHE).getKey(), | ||
TieredSpilloverCache.TieredSpilloverCacheFactory.TIERED_SPILLOVER_CACHE_NAME | ||
) | ||
.put( | ||
TieredSpilloverCacheSettings.TIERED_SPILLOVER_ONHEAP_STORE_NAME.getConcreteSettingForNamespace( | ||
CacheType.INDICES_REQUEST_CACHE.getSettingPrefix() | ||
).getKey(), | ||
OpenSearchOnHeapCache.OpenSearchOnHeapCacheFactory.NAME | ||
) | ||
.put( | ||
TieredSpilloverCacheSettings.TIERED_SPILLOVER_DISK_STORE_NAME.getConcreteSettingForNamespace( | ||
CacheType.INDICES_REQUEST_CACHE.getSettingPrefix() | ||
).getKey(), | ||
MockOnDiskCache.MockDiskCacheFactory.NAME | ||
) | ||
.build(); | ||
} | ||
|
||
public void testPluginsAreInstalled() { | ||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); | ||
nodesInfoRequest.addMetric(NodesInfoRequest.Metric.PLUGINS.metricName()); | ||
NodesInfoResponse nodesInfoResponse = OpenSearchIntegTestCase.client().admin().cluster().nodesInfo(nodesInfoRequest).actionGet(); | ||
List<PluginInfo> pluginInfos = nodesInfoResponse.getNodes() | ||
.stream() | ||
.flatMap( | ||
(Function<NodeInfo, Stream<PluginInfo>>) nodeInfo -> nodeInfo.getInfo(PluginsAndModules.class).getPluginInfos().stream() | ||
) | ||
.collect(Collectors.toList()); | ||
Assert.assertTrue( | ||
pluginInfos.stream() | ||
.anyMatch(pluginInfo -> pluginInfo.getName().equals("org.opensearch.cache.common" + ".tier.TieredSpilloverCachePlugin")) | ||
); | ||
} | ||
|
||
public void testSanityChecksWithIndicesRequestCache() throws InterruptedException { | ||
Client client = client(); | ||
assertAcked( | ||
client.admin() | ||
.indices() | ||
.prepareCreate("index") | ||
.setMapping("f", "type=date") | ||
.setSettings(Settings.builder().put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true).build()) | ||
.get() | ||
); | ||
indexRandom( | ||
true, | ||
client.prepareIndex("index").setSource("f", "2014-03-10T00:00:00.000Z"), | ||
client.prepareIndex("index").setSource("f", "2014-05-13T00:00:00.000Z") | ||
); | ||
ensureSearchable("index"); | ||
|
||
// This is not a random example: serialization with time zones writes shared strings | ||
// which used to not work well with the query cache because of the handles stream output | ||
// see #9500 | ||
final SearchResponse r1 = client.prepareSearch("index") | ||
.setSize(0) | ||
.setSearchType(SearchType.QUERY_THEN_FETCH) | ||
.addAggregation( | ||
dateHistogram("histo").field("f") | ||
.timeZone(ZoneId.of("+01:00")) | ||
.minDocCount(0) | ||
.dateHistogramInterval(DateHistogramInterval.MONTH) | ||
) | ||
.get(); | ||
assertSearchResponse(r1); | ||
|
||
// The cached is actually used | ||
assertThat( | ||
client.admin().indices().prepareStats("index").setRequestCache(true).get().getTotal().getRequestCache().getMemorySizeInBytes(), | ||
greaterThan(0L) | ||
); | ||
} | ||
|
||
public static class MockDiskCachePlugin extends Plugin implements CachePlugin { | ||
|
||
public MockDiskCachePlugin() {} | ||
|
||
@Override | ||
public Map<String, ICache.Factory> getCacheFactoryMap() { | ||
return Map.of(MockOnDiskCache.MockDiskCacheFactory.NAME, new MockOnDiskCache.MockDiskCacheFactory(0, 1000)); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "mock_disk_plugin"; | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...s/cache-ehcache/src/internalClusterTest/java/org/opensearch/cache/EhcacheDiskCacheIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.cache; | ||
|
||
import org.opensearch.action.admin.cluster.node.info.NodeInfo; | ||
import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest; | ||
import org.opensearch.action.admin.cluster.node.info.NodesInfoResponse; | ||
import org.opensearch.action.admin.cluster.node.info.PluginsAndModules; | ||
import org.opensearch.plugins.Plugin; | ||
import org.opensearch.plugins.PluginInfo; | ||
import org.opensearch.test.OpenSearchIntegTestCase; | ||
import org.junit.Assert; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class EhcacheDiskCacheIT extends OpenSearchIntegTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
return Arrays.asList(EhcacheCachePlugin.class); | ||
} | ||
|
||
public void testPluginsAreInstalled() { | ||
NodesInfoRequest nodesInfoRequest = new NodesInfoRequest(); | ||
nodesInfoRequest.addMetric(NodesInfoRequest.Metric.PLUGINS.metricName()); | ||
NodesInfoResponse nodesInfoResponse = OpenSearchIntegTestCase.client().admin().cluster().nodesInfo(nodesInfoRequest).actionGet(); | ||
List<PluginInfo> pluginInfos = nodesInfoResponse.getNodes() | ||
.stream() | ||
.flatMap( | ||
(Function<NodeInfo, Stream<PluginInfo>>) nodeInfo -> nodeInfo.getInfo(PluginsAndModules.class).getPluginInfos().stream() | ||
) | ||
.collect(Collectors.toList()); | ||
Assert.assertTrue( | ||
pluginInfos.stream().anyMatch(pluginInfo -> pluginInfo.getName().equals("org.opensearch.cache.EhcacheCachePlugin")) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.