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

File scripts cache key to include language and prevent conflicts #10033

Closed
wants to merge 1 commit into from

Conversation

javanna
Copy link
Member

@javanna javanna commented Mar 8, 2015

The file scripts cache key should include the language of the script to prevent conflicts between scripts with same name but different extension (hence lang). Note that script engines can register multiple acronyms that may be used as lang at execution time (e.g. javascript and js are synonyms). We then need to make sure that the same script gets loaded no matter which of the acronyms is used at execution time. This problem didn't exist before this change as the lang was simply ignored, while now we take it into account.

This change has also some positive effect on inline scripts caching. Up until now, the same script referred to with different acronyms would be compiled and cached multiple times, once per acronym. After this change every script gets compiled and cached only once, as we chose internally the acronym used as part of the cache key, no matter which one the user provides.

Also made sure that the same engine is closed only once.

@javanna javanna added :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >bug v1.5.0 v2.0.0-beta1 v1.4.5 review labels Mar 8, 2015
@javanna
Copy link
Member Author

javanna commented Mar 10, 2015

hey @s1monw @dakrone can either of you have a look at this please ;)

}
}
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should just build a map for this? I don't like the linear nature

Copy link
Member Author

Choose a reason for hiding this comment

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

not that we'll ever have thousands of engines registered, but we can do this yes

Copy link
Contributor

Choose a reason for hiding this comment

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

that doesn't matter here really it's just so much simpler to get the stuff from it?

Copy link
Member Author

Choose a reason for hiding this comment

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

done, also noticed that we were closing multiple times the same engine pontentially, fixed that too.

@javanna javanna force-pushed the fix/static_script_cache_key branch from af88036 to 4e3a9a1 Compare March 10, 2015 23:58
@javanna
Copy link
Member Author

javanna commented Mar 11, 2015

Pushed a new commit, can you have a look @s1monw please?

@@ -194,8 +202,8 @@ public void setClient(Client client) {
}

public void close() {
for (ScriptEngineService engineService : scriptEngines.values()) {
engineService.close();
for (ScriptEngineService scriptEngine : scriptEngines) {
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 use IOUtils.close() here please it will close all even if there are exceptions

@s1monw
Copy link
Contributor

s1monw commented Mar 12, 2015

left one comment other than that LGTM

@javanna
Copy link
Member Author

javanna commented Mar 12, 2015

@s1monw I made ScriptEngineService extend Closeable and moved to IOUtils#close. This doesn't break existing plugins though as as the signature of the close method doesn't change.

for (ScriptEngineService engineService : scriptEngines.values()) {
engineService.close();
}
IOUtils.closeWhileHandlingException(scriptEngines);
Copy link
Contributor

Choose a reason for hiding this comment

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

please use just close here

@s1monw
Copy link
Contributor

s1monw commented Mar 13, 2015

left a tiny comment LGTM otherwise

@javanna javanna force-pushed the fix/static_script_cache_key branch from aba38de to 7cb709b Compare March 13, 2015 03:21
@javanna javanna force-pushed the fix/static_script_cache_key branch from 7cb709b to 2a29e2b Compare March 13, 2015 03:38
…licts

The file scripts cache key should include the language of the script to prevent conflicts between scripts with same name but different extension (hence lang). Note that script engines can register multiple acronyms that may be used as lang at execution time (e.g. javascript and js are synonyms). We then need to make sure that the same script gets loaded no matter which of the acronyms is used at execution time. The problem didn't exist before this change ad the lang was simply ignored, while now we take it into account.

This change has also some positive effect on inline scripts caching. Up until now, the same script referred to with different acronyms would be compiled and cached multiple times, once per acronym. After this change every script gets compiled and cached only once, as we chose internally the acronym used as part of the cache key, no matter which one the user provides.

Closes elastic#10033
@javanna javanna force-pushed the fix/static_script_cache_key branch from 2a29e2b to 67a3f31 Compare March 13, 2015 03:40
javanna added a commit to javanna/elasticsearch that referenced this pull request Mar 13, 2015
…licts

The file scripts cache key should include the language of the script to prevent conflicts between scripts with same name but different extension (hence lang). Note that script engines can register multiple acronyms that may be used as lang at execution time (e.g. javascript and js are synonyms). We then need to make sure that the same script gets loaded no matter which of the acronyms is used at execution time. The problem didn't exist before this change ad the lang was simply ignored, while now we take it into account.

This change has also some positive effect on inline scripts caching. Up until now, the same script referred to with different acronyms would be compiled and cached multiple times, once per acronym. After this change every script gets compiled and cached only once, as we chose internally the acronym used as part of the cache key, no matter which one the user provides.

Closes elastic#10033
javanna added a commit to javanna/elasticsearch that referenced this pull request Mar 13, 2015
…licts

The file scripts cache key should include the language of the script to prevent conflicts between scripts with same name but different extension (hence lang). Note that script engines can register multiple acronyms that may be used as lang at execution time (e.g. javascript and js are synonyms). We then need to make sure that the same script gets loaded no matter which of the acronyms is used at execution time. The problem didn't exist before this change ad the lang was simply ignored, while now we take it into account.

This change has also some positive effect on inline scripts caching. Up until now, the same script referred to with different acronyms would be compiled and cached multiple times, once per acronym. After this change every script gets compiled and cached only once, as we chose internally the acronym used as part of the cache key, no matter which one the user provides.

Closes elastic#10033
@javanna javanna closed this in a827159 Mar 13, 2015
@javanna javanna removed the review label Mar 13, 2015
@clintongormley clintongormley changed the title Scripting: File scripts cache key to include language and prevent conflicts File scripts cache key to include language and prevent conflicts Jun 8, 2015
mute pushed a commit to mute/elasticsearch that referenced this pull request Jul 29, 2015
…licts

The file scripts cache key should include the language of the script to prevent conflicts between scripts with same name but different extension (hence lang). Note that script engines can register multiple acronyms that may be used as lang at execution time (e.g. javascript and js are synonyms). We then need to make sure that the same script gets loaded no matter which of the acronyms is used at execution time. The problem didn't exist before this change ad the lang was simply ignored, while now we take it into account.

This change has also some positive effect on inline scripts caching. Up until now, the same script referred to with different acronyms would be compiled and cached multiple times, once per acronym. After this change every script gets compiled and cached only once, as we chose internally the acronym used as part of the cache key, no matter which one the user provides.

Closes elastic#10033
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.4.5 v1.5.0 v2.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants