Skip to content
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

Prevent requests that use scripts or now() from being cached #20750

Merged
merged 24 commits into from
Oct 6, 2016

Conversation

s1monw
Copy link
Contributor

@s1monw s1monw commented Oct 5, 2016

We already have some mechanism in place that prevents requests from being cached in the request cache if they use now(). Yet we don't have any streamlined way to assert that we are not accessing it later. We found some issues in #20645 that relate to stored scripts or scripts that are not pure functions. The immediate fix is to disable caching for these scripts. Unfortunately the script access wasn't streamlined in aggregations nor in query parsing / creation. This change adds a contained API that allows up to make cachabiltily decisions in a single place and causes requests to fail if they access scripts or now() after we cache the request.

Relates to #20645

s1monw and others added 14 commits October 4, 2016 18:05
This commit changes the strict REST parameters message to say that
unconsumed parameters are unrecognized rather than unused. Additionally,
the test is beefed up to include two unused parameters.

Relates #20745
This commit adds a did you mean feature to the strict REST params error
message. This works by comparing any unconsumed parameters to all of the
consumer parameters, comparing the Levenstein distance between those
parameters, and taking any consumed parameters that are close to an
unconsumed parameter as candiates for the did you mean.

* Fix pluralization in strict REST params message

This commit fixes the pluralization in the strict REST parameters error
message so that the word "parameter" is not unconditionally written as
"parameters" even when there is only one unrecognized parameter.

* Strength strict REST params did you mean test

This commit adds an unconsumed parameter that is too far from every
consumed parameter to have any candidate suggestions.

Relates #20747
Before this change the processing of the ranges in the date range (and
other range type) aggregations was done when the Aggregator was created.
This meant that the SearchContext did not know that now had been used in
a range until after the decision to cache was made.

This change moves the processing of the ranges to the aggregation builders
so that the search context is made aware that now has been used before
it decides if the request should be cached
Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

Looks ok to me (although I'm not that familiar with the aggs parts).

@@ -327,4 +338,75 @@ private ParsedQuery toQuery(QueryBuilder queryBuilder, CheckedFunction<QueryBuil
public final Index index() {
return indexSettings.getIndex();
}

/**
* Compiles (or retrieves from cache) and executes the provided script
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't actually execute right? It is the binding that happens immediately (vs lazy below is binding to params later).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah gotta fix this

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed

return search(lookup, compiledScript, script.getParams());
}

public SearchScript search(SearchLookup lookup, CompiledScript compiledScript, Map<String, Object> params) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some minimal javadocs?

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed

if (isCachable(firstQuery)) {
assert context.isCachable() : firstQuery.toString();
} else {
assert context.isCachable() == false : firstQuery.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

since it's a test case, should it use the junit assertions instead of the assert keyword?

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed

@colings86 colings86 merged commit 3aed047 into master Oct 6, 2016
@s1monw s1monw deleted the dont_cache_scripts branch October 6, 2016 10:12
colings86 added a commit that referenced this pull request Oct 6, 2016
Prevent requests that use scripts or now() from being cached
colings86 added a commit that referenced this pull request Oct 6, 2016
Prevent requests that use scripts or now() from being cached
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query Refactoring labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocker >bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache :Search/Search Search-related issues that do not fall into other categories v5.0.0-rc1 v6.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants