Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Kiran Prakash <awskiran@amazon.com>
  • Loading branch information
kiranprakash154 committed Apr 25, 2024
1 parent 0d85e10 commit a3c12cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ public final class IndicesRequestCache implements RemovalListener<ICacheKey<Indi
public static final String SHARD_ID_DIMENSION_NAME = "shards";
public static final String INDEX_DIMENSION_NAME = "indices";

// These values determine the valid names for levels in the cache stats API
public static final String SHARD_ID_DIMENSION_NAME = "shards";
public static final String INDEX_DIMENSION_NAME = "indices";

IndicesRequestCache(
Settings settings,
Function<ShardId, Optional<CacheEntity>> cacheEntityFunction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.service.ClusterService;
import org.opensearch.common.CheckedSupplier;
import org.opensearch.common.cache.ICacheKey;
import org.opensearch.common.cache.RemovalNotification;
Expand Down Expand Up @@ -908,51 +907,17 @@ public void testClosingIndexWipesStats() throws Exception {
}

public void testCacheCleanupBasedOnStaleThreshold_thresholdUpdate() throws Exception {
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
IndexShard indexShard = createIndex("test").getShard(0);
ThreadPool threadPool = getThreadPool();
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
threadPool = getThreadPool();
Settings settings = Settings.builder().put(INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING.getKey(), "51%").build();
IndicesRequestCache cache = new IndicesRequestCache(settings, (shardId -> {
IndexService indexService = null;
try {
indexService = indicesService.indexServiceSafe(shardId.getIndex());
} catch (IndexNotFoundException ex) {
return Optional.empty();
}
return Optional.of(new IndicesService.IndexShardCacheEntity(indexService.getShard(shardId.id())));
}), new CacheModule(new ArrayList<>(), Settings.EMPTY).getCacheService(), threadPool, clusterService);
Directory dir = newDirectory();
IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig());
cache = getIndicesRequestCache(settings);

writer.addDocument(newDoc(0, "foo"));
DirectoryReader reader = OpenSearchDirectoryReader.wrap(DirectoryReader.open(writer), new ShardId("foo", "bar", 1));
TermQueryBuilder termQuery = new TermQueryBuilder("id", "0");
BytesReference termBytes = XContentHelper.toXContent(termQuery, MediaTypeRegistry.JSON, false);
if (randomBoolean()) {
writer.flush();
IOUtils.close(writer);
writer = new IndexWriter(dir, newIndexWriterConfig());
}
writer.updateDocument(new Term("id", "0"), newDoc(0, "bar"));
DirectoryReader secondReader = OpenSearchDirectoryReader.wrap(DirectoryReader.open(writer), new ShardId("foo", "bar", 1));

// Get 2 entries into the cache
IndicesService.IndexShardCacheEntity entity = new IndicesService.IndexShardCacheEntity(indexShard);
Loader loader = new Loader(reader, 0);
cache.getOrCompute(entity, loader, reader, termBytes);

entity = new IndicesService.IndexShardCacheEntity(indexShard);
loader = new Loader(reader, 0);
cache.getOrCompute(entity, loader, reader, termBytes);

IndicesService.IndexShardCacheEntity secondEntity = new IndicesService.IndexShardCacheEntity(indexShard);
loader = new Loader(secondReader, 0);
cache.getOrCompute(entity, loader, secondReader, termBytes);

secondEntity = new IndicesService.IndexShardCacheEntity(indexShard);
loader = new Loader(secondReader, 0);
cache.getOrCompute(secondEntity, loader, secondReader, termBytes);
cache.getOrCompute(getEntity(indexShard), getLoader(reader), reader, getTermBytes());
cache.getOrCompute(getEntity(indexShard), getLoader(secondReader), secondReader, getTermBytes());
assertEquals(2, cache.count());

// Close the reader, to be enqueued for cleanup
Expand All @@ -972,8 +937,7 @@ public void testCacheCleanupBasedOnStaleThreshold_thresholdUpdate() throws Excep
// cleanup should NOT have been ignored
assertEquals(1, cache.count());

IOUtils.close(secondReader, writer, dir, cache);
terminate(threadPool);
IOUtils.close(secondReader);
}

public void testEviction() throws Exception {
Expand Down

0 comments on commit a3c12cd

Please sign in to comment.