Skip to content

Commit

Permalink
Cleanup from separation cherry pick
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <[email protected]>
  • Loading branch information
Peter Alfonsi committed Dec 28, 2023
1 parent be1fe01 commit e33f43f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ public final class IndicesRequestCache implements TieredCacheEventListener<Indic
private final ByteSizeValue size;
private final TimeValue expire;
private final TieredCacheService<Key, BytesReference> tieredCacheService;

private final TieredCacheHandler<Key, BytesReference> tieredCacheHandler;
private final IndicesService indicesService;

IndicesRequestCache(Settings settings, IndicesService indicesService) {
this.size = INDICES_CACHE_QUERY_SIZE.get(settings);
this.expire = INDICES_CACHE_QUERY_EXPIRE.exists(settings) ? INDICES_CACHE_QUERY_EXPIRE.get(settings) : null;
long sizeInBytes = size.getBytes();
this.indicesService = indicesService;

// Initialize onHeap cache tier first.
OnHeapCachingTier<Key, BytesReference> openSearchOnHeapCache = new OpenSearchOnHeapCache.Builder<Key, BytesReference>().setWeigher(
Expand Down Expand Up @@ -208,7 +208,7 @@ void invalidate(CacheEntity cacheEntity, DirectoryReader reader, BytesReference
IndexReader.CacheHelper cacheHelper = ((OpenSearchDirectoryReader) reader).getDelegatingCacheHelper();
readerCacheKeyId = ((OpenSearchDirectoryReader.DelegatingCacheHelper) cacheHelper).getDelegatingCacheKey().getId();
}
cache.invalidate(new Key(cacheEntity, cacheKey, readerCacheKeyId));
tieredCacheService.invalidate(new Key(cacheEntity, cacheKey, readerCacheKeyId));
}

/**
Expand Down Expand Up @@ -283,8 +283,8 @@ interface CacheEntity extends Accountable, Writeable {
*
* @opensearch.internal
*/
public static class Key implements Accountable {
private static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(Key.class);
public class Key implements Accountable {
private final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(Key.class);

public final CacheEntity entity; // use as identity equality
public final String readerCacheKeyId;
Expand Down Expand Up @@ -331,13 +331,6 @@ public int hashCode() {
result = 31 * result + value.hashCode();
return result;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalWriteable(entity);
out.writeOptionalString(readerCacheKeyId);
out.writeBytesReference(value);
}
}

private class CleanupKey implements IndexReader.ClosedListener {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -468,32 +468,6 @@ public void testEqualsKey() throws IOException {
assertNotEquals(key1, key5);
}

public void testSerializationDeserializationOfCacheKey() throws Exception {
TermQueryBuilder termQuery = new TermQueryBuilder("id", "0");
BytesReference termBytes = XContentHelper.toXContent(termQuery, MediaTypeRegistry.JSON, false);
ShardRequestCache shardRequestCache = new ShardRequestCache();
IndicesService indicesService = getInstanceFromNode(IndicesService.class);
IndicesRequestCache indicesRequestCache = indicesService.indicesRequestCache;
IndexService indexService = createIndex("test");
IndexShard indexShard = indexService.getShard(0);
IndicesService.IndexShardCacheEntity shardCacheEntity = indicesService.new IndexShardCacheEntity(indexShard);
String readerCacheKeyId = UUID.randomUUID().toString();
IndicesRequestCache.Key key1 = indicesRequestCache.new Key(shardCacheEntity, termBytes, readerCacheKeyId);
BytesReference bytesReference = null;
try (BytesStreamOutput out = new BytesStreamOutput()) {
key1.writeTo(out);
bytesReference = out.bytes();
}
StreamInput in = bytesReference.streamInput();

IndicesRequestCache.Key key2 = indicesRequestCache.new Key(in);

assertEquals(readerCacheKeyId, key2.readerCacheKeyId);
assertEquals(shardCacheEntity.getCacheIdentity(), key2.entity.getCacheIdentity());
assertEquals(termBytes, key2.value);

}

private class TestBytesReference extends AbstractBytesReference {

int dummyValue;
Expand Down

0 comments on commit e33f43f

Please sign in to comment.