Skip to content

Fix the request cache keys to not hold references to the SearchContext. #21284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 3, 2016

Conversation

jpountz
Copy link
Contributor

@jpountz jpountz commented Nov 2, 2016

Currently the request cache adds a CacheEntity object. It looks quite innocent
but in practice it has a reference to a lambda that knows how to create a value.
The issue is that this lambda has implicit references to the SearchContext
object, which can be quite heavy since it holds a structured representation of
aggregations for instance.

This pull request splits the CacheEntity object from the object that generates
cache values.

Currently the request cache adds a `CacheEntity` object. It looks quite innocent
but in practice it has a reference to a lambda that knows how to create a value.
The issue is that this lambda has implicit references to the SearchContext
object, which can be quite heavy since it holds a structured representation of
aggregations for instance.

This pull request splits the `CacheEntity` object from the object that generates
cache values.
Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a couple of comments, looks great!

try {
context.queryResult().writeToNoId(out);
} catch (IOException e) {
throw new IllegalStateException("Could not serialize response", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe make this even an AssertionError?

IndexShardCacheEntity cacheEntity = new IndexShardCacheEntity(shard, loader);
return indicesRequestCache.getOrCompute(cacheEntity, reader, cacheKey);
IndexShardCacheEntity cacheEntity = new IndexShardCacheEntity(shard);
boolean[] loadedFromCache = new boolean[] { true };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to return this, I think we can rely on that the loader is called when we load the result again so the caller can use this to obtain that boolean...?

queryPhase.execute(context);
context.queryResult().writeToNoId(out);
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use a boolean here that we set to false when this loader is executed?

Copy link
Contributor

@s1monw s1monw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jpountz jpountz merged commit 5d79eab into elastic:master Nov 3, 2016
@jpountz jpountz deleted the fix/request_cache_memory_usage branch November 3, 2016 07:58
jpountz added a commit that referenced this pull request Nov 3, 2016
…t. (#21284)

Currently the request cache adds a `CacheEntity` object. It looks quite innocent
but in practice it has a reference to a lambda that knows how to create a value.
The issue is that this lambda has implicit references to the SearchContext
object, which can be quite heavy since it holds a structured representation of
aggregations for instance.

This pull request splits the `CacheEntity` object from the object that generates
cache values.
jpountz added a commit that referenced this pull request Nov 3, 2016
…t. (#21284)

Currently the request cache adds a `CacheEntity` object. It looks quite innocent
but in practice it has a reference to a lambda that knows how to create a value.
The issue is that this lambda has implicit references to the SearchContext
object, which can be quite heavy since it holds a structured representation of
aggregations for instance.

This pull request splits the `CacheEntity` object from the object that generates
cache values.
@ywelsch ywelsch mentioned this pull request Dec 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants