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

Fix updating templates. #10526

Merged

Conversation

MaineC
Copy link

@MaineC MaineC commented Apr 10, 2015

Closes #10397

When putting new templates to an index they are added to the cache
of compiled templates as a side effect of the validate method. When
updating templates they are also validated but the scripts that are
already in the cache never get updated.

@javanna Assigning to you for review as you seem to have written most of the code this PR touches, feel free to re-assign.

CompiledScript compiled = cache.getIfPresent(cacheKey);
CompiledScript compiled = null;
if (! ignoreCache) {
cache.getIfPresent(cacheKey);
Copy link
Member

Choose a reason for hiding this comment

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

you are entirely disabling the cache if you don't assign the result here to compiled.

Copy link
Author

Choose a reason for hiding this comment

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

That was supposed to read

compiled = cache.getIf...

Stupid typo on my side that lead to fixing the test as a side effect...

Copy link
Member

Choose a reason for hiding this comment

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

the problem is that when you fix it the test fails ;)

@javanna
Copy link
Member

javanna commented Apr 10, 2015

Hi @MaineC I don't think the problem stems from the validate method. validate properly caches using the script itself. The problem is that when we actually retrieve the script from the index as part of the search request, we actually look for and cache the script based on its id. That means it's never going to find the already cached version. Also, once a script is cached based on its id it is never going to be updated in the cache.

I would change the caching mechanism to use the retrieved script as cache key in case the script is indexed, so it will match with the one cached as part of validate and it will get cached again once it changes. makes sense?

@javanna
Copy link
Member

javanna commented Apr 10, 2015

I did some research, this is a regression introduced with #10033 . 1.5.0 and 1.5.1 are affected, meaning that once you executed an indexed script for the first time, that first version is going to stick around in the internal cache although you update the script. We better add some proper test coverage for this :)

@MaineC
Copy link
Author

MaineC commented Apr 13, 2015

@javanna wrt. to your proposal - makes sense, changed the PR accordingly.

I also re-named the "script" parameter in compileInternal to "scriptOrId" to better reflect it's real content.

One thing I was wondering: For indexed scripts we could consistently use their id as part of the cache key. This would save retrieving the string version from the index later (assuming a cache hit). On the flip side it would make it understanding cache keys trickier. Not sure if this is worth the effort?

assertEquals(scriptResponse.getVersion(), 2);
SearchResponse searchResponse = client().prepareSearch("testindex").setTypes("test").
setTemplateName("git01").setTemplateType(ScriptService.ScriptType.INDEXED).setTemplateParams(templateParams).get();
assertHitCount(searchResponse, 1);
Copy link
Member

Choose a reason for hiding this comment

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

I would love to have some more coverage here, maybe update a few more times (randomIntBetween(1,10) ?) and verify that updates always make it through, not just once?

Also, can we write a test for plain indexed scripts too (rather than search templates)?

@javanna
Copy link
Member

javanna commented Apr 16, 2015

looks good, left a couple of comments around testing.

@MaineC
Copy link
Author

MaineC commented Apr 16, 2015

@javanna Thanks for the review and comments - good suggestions, will update accordingly.

MaineC pushed a commit to MaineC/elasticsearch that referenced this pull request Apr 21, 2015
As per comments on PR elastic#10526 adding more tests around updating scripts
and templates.
@MaineC MaineC force-pushed the bug-fix/10397-update-templates-not-recompiled branch from 3842605 to 8125941 Compare April 21, 2015 08:51
MaineC pushed a commit to MaineC/elasticsearch that referenced this pull request Apr 21, 2015
As per comments on PR elastic#10526 adding more tests around updating scripts
and templates.
index("testindex", "test", "1", jsonBuilder().startObject().field("searchtext", "dev1").endObject());
refresh();

for (int i = 1; i < randomIntBetween(2, 11); i++) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it is a good idea to call randomInBetween from here? We should save the result to a variable outside of the loop.

Copy link
Author

Choose a reason for hiding this comment

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

m(

Good catch.

@javanna
Copy link
Member

javanna commented Apr 21, 2015

I left a small comments around tests, LGTM besides that

@MaineC MaineC force-pushed the bug-fix/10397-update-templates-not-recompiled branch from 7656986 to acf8961 Compare April 22, 2015 08:59
MaineC pushed a commit to MaineC/elasticsearch that referenced this pull request Apr 22, 2015
Closes elastic#10397

When putting new templates to an index they are added to the cache
of compiled templates as a side effect of the validate method. When
updating templates they are also validated but the scripts that are
already in the cache never get updated.

As per comments on PR elastic#10526 adding more tests around updating scripts
and templates.
Closes elastic#10397

When putting new templates to an index they are added to the cache
of compiled templates as a side effect of the validate method. When
updating templates they are also validated but the scripts that are
already in the cache never get updated.

As per comments on PR elastic#10526 adding more tests around updating scripts
and templates.
@MaineC MaineC force-pushed the bug-fix/10397-update-templates-not-recompiled branch from acf8961 to a9d540a Compare April 22, 2015 09:00
MaineC pushed a commit that referenced this pull request Apr 22, 2015
…not-recompiled

Closes #10397: Fix updating indexed search templates.
@MaineC MaineC merged commit f857f9e into elastic:master Apr 22, 2015
@kevinkluge kevinkluge removed the review label Apr 22, 2015
MaineC pushed a commit that referenced this pull request Apr 24, 2015
See #10526 for more details.
MaineC pushed a commit that referenced this pull request Apr 24, 2015
See #10526 for more details.
@MaineC MaineC added the v1.5.2 label Apr 24, 2015
@clintongormley clintongormley added :Indexed Scripts/Templates and removed :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache labels Jun 8, 2015
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
@clintongormley clintongormley added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache and removed :Indexed Scripts/Templates labels Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache v1.5.2 v1.6.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

search templates created with restapi are not deleteing completely
4 participants