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

Make mapping updates more robust. #15539

Merged
merged 1 commit into from
Dec 23, 2015

Conversation

jpountz
Copy link
Contributor

@jpountz jpountz commented Dec 18, 2015

This changes a couple of things:

Mappings are truly immutable. Before, each field mapper stored a
MappedFieldTypeReference that was shared across fields that have the same name
across types. This means that a mapping update could have the side-effect of
changing the field type in other types when updateAllTypes is true. This works
differently now: after a mapping update, a new copy of the mappings is created
in such a way that fields across different types have the same MappedFieldType.
See the new Mapper.updateFieldType API which replaces MappedFieldTypeReference.

DocumentMapper is now immutable and MapperService.merge has been refactored in
such a way that if an exception is thrown while eg. lookup structures are being
updated, then the whole mapping update will be aborted. As a consequence,
FieldTypeLookup's checkCompatibility has been folded into copyAndAddAll.

Synchronization was simplified: given that mappings are truly immutable, we
don't need the read/write lock so that no documents can be parsed while a
mapping update is being processed. Document parsing is not performed under a
lock anymore, and mapping merging uses a simple synchronized block.

@jpountz jpountz added >enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types v5.0.0-alpha1 v2.2.0 labels Dec 18, 2015
fieldMappers.put(mapper.name(), mapper);
MappedFieldType fieldType = mapper.fieldType();
put(indexAnalyzers, fieldType.names().indexName(), fieldType.indexAnalyzer(), analysisService.defaultIndexAnalyzer());
put(indexAnalyzers, fieldType.names().indexName(), fieldType.searchAnalyzer(), analysisService.defaultSearchAnalyzer());
Copy link
Member

Choose a reason for hiding this comment

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

Typo here? indexAnalyzers -> searchAnalyzers? And indexAnalyzers -> searchQuoteAnalyzers on the next line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. This is concerning that no tests caught this mistake, I'll add one.

@rjernst
Copy link
Member

rjernst commented Dec 22, 2015

I discussed with @jpountz and I agree now making mappings completely immutable is more important here. We should separately drive the simplification of types (ie type removal/turning them into just a simple set-of-fields-selector). +1 to this PR.

@jpountz
Copy link
Contributor Author

jpountz commented Dec 22, 2015

@rjernst I rebased with master and pushed a new commit to address the problem you found with index analyzers.

@rjernst
Copy link
Member

rjernst commented Dec 23, 2015

LGTM

This changes a couple of things:

Mappings are truly immutable. Before, each field mapper stored a
MappedFieldTypeReference that was shared across fields that have the same name
across types. This means that a mapping update could have the side-effect of
changing the field type in other types when updateAllTypes is true. This works
differently now: after a mapping update, a new copy of the mappings is created
in such a way that fields across different types have the same MappedFieldType.
See the new Mapper.updateFieldType API which replaces MappedFieldTypeReference.

DocumentMapper is now immutable and MapperService.merge has been refactored in
such a way that if an exception is thrown while eg. lookup structures are being
updated, then the whole mapping update will be aborted. As a consequence,
FieldTypeLookup's checkCompatibility has been folded into copyAndAddAll.

Synchronization was simplified: given that mappings are truly immutable, we
don't need the read/write lock so that no documents can be parsed while a
mapping update is being processed. Document parsing is not performed under a
lock anymore, and mapping merging uses a simple synchronized block.
@jpountz jpountz force-pushed the fix/immutable_document_mapper branch from 6bc7f97 to f535c27 Compare December 23, 2015 08:55
jpountz added a commit that referenced this pull request Dec 23, 2015
@jpountz jpountz merged commit a2072fe into elastic:master Dec 23, 2015
@jpountz jpountz deleted the fix/immutable_document_mapper branch December 23, 2015 08:55
@jpountz jpountz added v2.3.0 and removed v2.2.0 labels Dec 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types v2.3.0 v5.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants