Skip to content

Commit e5bfbb1

Browse files
github-actions[bot]Peter Alfonsi
andcommitted
[Bugfix] Fix TieredSpilloverCache flaky tests (#14333)
* Fix flaky TSC stats tests Signed-off-by: Peter Alfonsi <[email protected]> * Addressed andrross's comment Signed-off-by: Peter Alfonsi <[email protected]> * fix forbidden API Signed-off-by: Peter Alfonsi <[email protected]> --------- Signed-off-by: Peter Alfonsi <[email protected]> Co-authored-by: Peter Alfonsi <[email protected]> (cherry picked from commit 56c5dcc) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent bbea194 commit e5bfbb1

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

modules/cache-common/src/internalClusterTest/java/org/opensearch/cache/common/tier/TieredSpilloverCacheStatsIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest;
1212
import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;
13+
import org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse;
1314
import org.opensearch.action.admin.indices.stats.CommonStatsFlags;
1415
import org.opensearch.action.search.SearchResponse;
1516
import org.opensearch.client.Client;
@@ -20,6 +21,7 @@
2021
import org.opensearch.common.cache.stats.ImmutableCacheStatsHolder;
2122
import org.opensearch.common.settings.Settings;
2223
import org.opensearch.common.unit.TimeValue;
24+
import org.opensearch.index.IndexSettings;
2325
import org.opensearch.index.cache.request.RequestCacheStats;
2426
import org.opensearch.index.query.QueryBuilders;
2527
import org.opensearch.indices.IndicesRequestCache;
@@ -351,11 +353,15 @@ private void startIndex(Client client, String indexName) throws InterruptedExcep
351353
.put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true)
352354
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
353355
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
356+
// Disable index refreshing to avoid cache being invalidated mid-test
357+
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), TimeValue.timeValueMillis(-1))
354358
.build()
355359
)
356360
.get()
357361
);
358362
indexRandom(true, client.prepareIndex(indexName).setSource("k", "hello"));
363+
// Force merge the index to ensure there can be no background merges during the subsequent searches that would invalidate the cache
364+
ForceMergeResponse forceMergeResponse = client.admin().indices().prepareForceMerge(indexName).setFlush(true).get();
359365
ensureSearchable(indexName);
360366
}
361367

server/src/internalClusterTest/java/org/opensearch/indices/CacheStatsAPIIndicesRequestCacheIT.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest;
1414
import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;
1515
import org.opensearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
16+
import org.opensearch.action.admin.indices.forcemerge.ForceMergeResponse;
1617
import org.opensearch.action.admin.indices.stats.CommonStatsFlags;
1718
import org.opensearch.action.search.SearchResponse;
1819
import org.opensearch.client.Client;
@@ -23,12 +24,14 @@
2324
import org.opensearch.common.cache.stats.ImmutableCacheStats;
2425
import org.opensearch.common.cache.stats.ImmutableCacheStatsHolder;
2526
import org.opensearch.common.settings.Settings;
27+
import org.opensearch.common.unit.TimeValue;
2628
import org.opensearch.common.util.FeatureFlags;
2729
import org.opensearch.common.xcontent.XContentFactory;
2830
import org.opensearch.common.xcontent.XContentHelper;
2931
import org.opensearch.core.xcontent.MediaTypeRegistry;
3032
import org.opensearch.core.xcontent.ToXContent;
3133
import org.opensearch.core.xcontent.XContentBuilder;
34+
import org.opensearch.index.IndexSettings;
3235
import org.opensearch.index.cache.request.RequestCacheStats;
3336
import org.opensearch.index.query.QueryBuilders;
3437
import org.opensearch.test.OpenSearchIntegTestCase;
@@ -266,10 +269,14 @@ private void startIndex(Client client, String indexName) throws InterruptedExcep
266269
.put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true)
267270
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
268271
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
272+
// Disable index refreshing to avoid cache being invalidated mid-test
273+
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), TimeValue.timeValueMillis(-1))
269274
)
270275
.get()
271276
);
272277
indexRandom(true, client.prepareIndex(indexName).setSource("k", "hello"));
278+
// Force merge the index to ensure there can be no background merges during the subsequent searches that would invalidate the cache
279+
ForceMergeResponse forceMergeResponse = client.admin().indices().prepareForceMerge(indexName).setFlush(true).get();
273280
ensureSearchable(indexName);
274281
}
275282

server/src/main/java/org/opensearch/common/cache/stats/ImmutableCacheStats.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,29 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
115115
return builder;
116116
}
117117

118+
@Override
119+
public String toString() {
120+
return Fields.HIT_COUNT
121+
+ "="
122+
+ hits
123+
+ ", "
124+
+ Fields.MISS_COUNT
125+
+ "="
126+
+ misses
127+
+ ", "
128+
+ Fields.EVICTIONS
129+
+ "="
130+
+ evictions
131+
+ ", "
132+
+ Fields.SIZE_IN_BYTES
133+
+ "="
134+
+ sizeInBytes
135+
+ ", "
136+
+ Fields.ITEM_COUNT
137+
+ "="
138+
+ items;
139+
}
140+
118141
/**
119142
* Field names used to write the values in this object to XContent.
120143
*/

0 commit comments

Comments
 (0)