-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fix upgrading indices which use a custom similarity plugin. #26985
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| import org.elasticsearch.index.analysis.NamedAnalyzer; | ||
| import org.elasticsearch.index.mapper.MapperService; | ||
| import org.elasticsearch.index.similarity.SimilarityService; | ||
| import org.elasticsearch.index.similarity.SimilarityProvider; | ||
| import org.elasticsearch.indices.mapper.MapperRegistry; | ||
|
|
||
| import java.util.AbstractMap; | ||
|
|
@@ -136,7 +137,24 @@ private void checkMappingsCompatibility(IndexMetaData indexMetaData) { | |
| // We cannot instantiate real analysis server at this point because the node might not have | ||
| // been started yet. However, we don't really need real analyzers at this stage - so we can fake it | ||
| IndexSettings indexSettings = new IndexSettings(indexMetaData, this.settings); | ||
| SimilarityService similarityService = new SimilarityService(indexSettings, null, Collections.emptyMap()); | ||
| final Map<String, SimilarityProvider.Factory> similarityMap = new AbstractMap<String, SimilarityProvider.Factory>() { | ||
| @Override | ||
| public boolean containsKey(Object key) { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public SimilarityProvider.Factory get(Object key) { | ||
| assert key instanceof String : "key must be a string but was: " + key.getClass(); | ||
| return SimilarityService.BUILT_IN.get(SimilarityService.DEFAULT_SIMILARITY); | ||
| } | ||
|
|
||
| @Override | ||
| public Set<Entry<String, SimilarityProvider.Factory>> entrySet() { | ||
| return Collections.emptySet(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize the analyzer hack does this, but it is inconsistent with what is returned above. I would rather throw a UEO here so that if entrySet begins to be used, we will catch this rather than get weird behavior. (And we should, in a followup or in this PR, fix the other entrySet() impl as well).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can do that but need to know what an UEO is (I'm not a Java programmer).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, Jason is correct on what I meant.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get test failures if make this change. For example:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this happens because |
||
| } | ||
| }; | ||
| SimilarityService similarityService = new SimilarityService(indexSettings, null, similarityMap); | ||
| final NamedAnalyzer fakeDefault = new NamedAnalyzer("default", AnalyzerScope.INDEX, new Analyzer() { | ||
| @Override | ||
| protected TokenStreamComponents createComponents(String fieldName) { | ||
|
|
||
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 add a comment here that having a dummy map works because we assume any similarity providers were known before the upgrade, so allowing any key below is ok.
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 did test the patch with a elasticsearch server without the custom similarity installed. The server starts but does not recover the index with an appropriate error message. I did not test restoring a snapshot from an old version. But as far as I understand the situation, we do not assume all used similarities are actually known here, but just defer the error to a point when we actually know all available similarities.
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.
Defer is what I meant by "assume". We allow any similarity name to be looked up without error. We don't actually use it, we just need to ensure the lookup does not fail. This is ok because we assume whatever was present when ES last shut down had all known similarities.