-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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 a mappings update test #33146
Fix a mappings update test #33146
Conversation
This commit fixes a mappings update test. The test is broken in the sense that it passes, but for the wrong reason. The test here is testing that if we make a mapping update but do not commit that mapping update then the mapper service still maintains the previous document mapper. This was not the case long, long ago when a mapping update would update the in-memory state before the cluster state update was committed. This test was passing, but it was passing because the mapping update was never even updated. It was never even updated because it was encountering a null pointer exception. Of course the in-memory state is not going to be updated in that case, we are simply going to end up with a failed cluster state update. Fixing that leads to another issue which is that the mapping source does not even parse so again we would, of course, end up with the in-memory state not being modified. We fix these issues, assert that the result cluster state task completed successfully, and finally that the in-memory state was not updated since we never committed the resulting cluster state.
Pinging @elastic/es-distributed |
I discovered this while adding mapping versions to index metadata. |
@@ -47,8 +51,18 @@ public void testMappingClusterStateUpdateDoesntChangeExistingIndices() throws Ex | |||
final ClusterService clusterService = getInstanceFromNode(ClusterService.class); | |||
// TODO - it will be nice to get a random mapping generator | |||
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest().type("type"); | |||
request.source("{ \"properties\" { \"field\": { \"type\": \"text\" }}}"); | |||
mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request)); | |||
request.indices(new Index[] {indexService.index()}); |
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.
This line prevents a null pointer exception when handling the request.
request.source("{ \"properties\" { \"field\": { \"type\": \"text\" }}}"); | ||
mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request)); | ||
request.indices(new Index[] {indexService.index()}); | ||
request.source("{ \"properties\": { \"field\": { \"type\": \"text\" }}}"); |
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.
This line adds a :
after \"properties\"
so that the mapping source parses properly.
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.
💥
mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request)); | ||
request.indices(new Index[] {indexService.index()}); | ||
request.source("{ \"properties\": { \"field\": { \"type\": \"text\" }}}"); | ||
final ClusterStateTaskExecutor.ClusterTasksResult<PutMappingClusterStateUpdateRequest> result = |
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.
This line is unchanged except now we capture the result of the cluster state update task.
// the task really was a mapping update | ||
assertThat( | ||
indexService.mapperService().documentMapper("type").mappingSource(), | ||
not(equalTo(result.resultingState.metaData().index("test").mapping("type").source()))); |
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 above lines assert that the cluster state update task completed successfully and that if the result cluster state were committed then the mapping for the type would change.
assertThat( | ||
indexService.mapperService().documentMapper("type").mappingSource(), | ||
not(equalTo(result.resultingState.metaData().index("test").mapping("type").source()))); | ||
// since we never committed the cluster state update, the in-memory state is unchanged | ||
assertThat(indexService.mapperService().documentMapper("type").mappingSource(), equalTo(currentMapping)); |
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.
We finally end with the existing assertion that the in-memory state of the mapping was not changed as a result of processing the mapping update. This is expected since the mapping update (the resulting cluster state) was never committed.
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.
LGTM
request.source("{ \"properties\" { \"field\": { \"type\": \"text\" }}}"); | ||
mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request)); | ||
request.indices(new Index[] {indexService.index()}); | ||
request.source("{ \"properties\": { \"field\": { \"type\": \"text\" }}}"); |
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.
💥
@elasticmachine test this please |
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.
LGTM
Thanks for fixing and making this test better!
This commit fixes a mappings update test. The test is broken in the sense that it passes, but for the wrong reason. The test here is testing that if we make a mapping update but do not commit that mapping update then the mapper service still maintains the previous document mapper. This was not the case long, long ago when a mapping update would update the in-memory state before the cluster state update was committed. This test was passing, but it was passing because the mapping update was never even updated. It was never even updated because it was encountering a null pointer exception. Of course the in-memory state is not going to be updated in that case, we are simply going to end up with a failed cluster state update. Fixing that leads to another issue which is that the mapping source does not even parse so again we would, of course, end up with the in-memory state not being modified. We fix these issues, assert that the result cluster state task completed successfully, and finally that the in-memory state was not updated since we never committed the resulting cluster state.
* master: Fix a mappings update test (elastic#33146) Reload Secure Settings REST specs & docs (elastic#32990) Refactor CachingUsernamePassword realm (elastic#32646) Add proxy support to RemoteClusterConnection (elastic#33062)
* master: Adjust BWC version on mapping version Token API supports the client_credentials grant (#33106) Build: forked compiler max memory matches jvmArgs (#33138) Introduce mapping version to index metadata (#33147) SQL: Enable aggregations to create a separate bucket for missing values (#32832) Fix grammar in contributing docs SECURITY: Fix Compile Error in ReservedRealmTests (#33166) APM server monitoring (#32515) Support only string `format` in date, root object & date range (#28117) [Rollup] Move toBuilders() methods out of rollup config objects (#32585) Fix forbiddenapis on java 11 (#33116) Apply publishing to genreate pom (#33094) Have circuit breaker succeed on unknown mem usage Do not lose default mapper on metadata updates (#33153) Fix a mappings update test (#33146) Reload Secure Settings REST specs & docs (#32990) Refactor CachingUsernamePassword realm (#32646)
* 6.x: Introduce mapping version to index metadata (#33147) Move non duplicated actions back into xpack core (#32952) HLRC: Create server agnostic request and response (#32912) Build: forked compiler max memory matches jvmArgs (#33138) * Added breaking change section for GROUP BY behavior: now it considers null or empty values as a separate group/bucket. Previously, they were ignored. * This is part of backporting of #32832 SQL: Enable aggregations to create a separate bucket for missing values (#32832) [TEST] version guard for reload rest-api-spec Fix grammar in contributing docs APM server monitoring (#32515) Support only string `format` in date, root object & date range (#28117) [Rollup] Move toBuilders() methods out of rollup config objects (#32585) Accept Gradle build scan agreement (#30645) Fix forbiddenapis on java 11 (#33116) Run forbidden api checks with runtimeJavaVersion (#32947) Apply publishing to genreate pom (#33094) Fix a mappings update test (#33146) Reload Secure Settings REST specs & docs (#32990) Refactor CachingUsernamePassword realm (#32646)
This commit fixes a mappings update test. The test is broken in the sense that it passes, but for the wrong reason. The test here is testing that if we make a mapping update but do not commit that mapping update then the mapper service still maintains the previous document mapper. This was not the case long, long ago when a mapping update would update the in-memory state before the cluster state update was committed. This test was passing, but it was passing because the mapping update was never even updated. It was never even updated because it was encountering a null pointer exception. Of course the in-memory state is not going to be updated in that case, we are simply going to end up with a failed cluster state update. Fixing that leads to another issue which is that the mapping source does not even parse so again we would, of course, end up with the in-memory state not being modified. We fix these issues, assert that the result cluster state task completed successfully, and finally that the in-memory state was not updated since we never committed the resulting cluster state.