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
Fix updating templates. #10526
Conversation
CompiledScript compiled = cache.getIfPresent(cacheKey); | ||
CompiledScript compiled = null; | ||
if (! ignoreCache) { | ||
cache.getIfPresent(cacheKey); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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 ;)
Hi @MaineC I don't think the problem stems from the validate method. 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 |
I did some research, this is a regression introduced with #10033 . |
@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); |
There was a problem hiding this comment.
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)?
looks good, left a couple of comments around testing. |
@javanna Thanks for the review and comments - good suggestions, will update accordingly. |
As per comments on PR elastic#10526 adding more tests around updating scripts and templates.
3842605
to
8125941
Compare
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++) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m(
Good catch.
I left a small comments around tests, LGTM besides that |
7656986
to
acf8961
Compare
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.
acf8961
to
a9d540a
Compare
…not-recompiled Closes #10397: Fix updating indexed search templates.
See elastic#10526 for more details.
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.