-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[Transform] Improve force stop robustness in case of an error #51072
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
Merged
hendrikmuhs
merged 3 commits into
elastic:master
from
hendrikmuhs:transform-remove-dangling-tasks
Jan 17, 2020
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...ts/src/test/java/org/elasticsearch/xpack/transform/integration/TransformRobustnessIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.transform.integration; | ||
|
|
||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.ResponseException; | ||
| import org.elasticsearch.xpack.core.transform.TransformField; | ||
| import org.elasticsearch.xpack.core.transform.transforms.persistence.TransformInternalIndexConstants; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import java.util.Map.Entry; | ||
|
|
||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class TransformRobustnessIT extends TransformRestTestCase { | ||
|
|
||
| public void testTaskRemovalAfterInternalIndexGotDeleted() throws Exception { | ||
| String indexName = "continuous_reviews"; | ||
| createReviewsIndex(indexName); | ||
| String transformId = "simple_continuous_pivot"; | ||
| String transformIndex = "pivot_reviews_continuous"; | ||
| final Request createTransformRequest = new Request("PUT", TransformField.REST_BASE_PATH_TRANSFORMS + transformId); | ||
| String config = "{" | ||
| + " \"source\": {\"index\":\"" | ||
| + indexName | ||
| + "\"}," | ||
| + " \"dest\": {\"index\":\"" | ||
| + transformIndex | ||
| + "\"}," | ||
| + " \"frequency\": \"1s\"," | ||
| + " \"sync\": {\"time\": {\"field\": \"timestamp\", \"delay\": \"1s\"}}," | ||
| + " \"pivot\": {" | ||
| + " \"group_by\": {" | ||
| + " \"reviewer\": {" | ||
| + " \"terms\": {" | ||
| + " \"field\": \"user_id\"" | ||
| + " } } }," | ||
| + " \"aggregations\": {" | ||
| + " \"avg_rating\": {" | ||
| + " \"avg\": {" | ||
| + " \"field\": \"stars\"" | ||
| + " } } } }" | ||
| + "}"; | ||
| createTransformRequest.setJsonEntity(config); | ||
| Map<String, Object> createTransformResponse = entityAsMap(client().performRequest(createTransformRequest)); | ||
| assertThat(createTransformResponse.get("acknowledged"), equalTo(Boolean.TRUE)); | ||
| assertEquals(1, getTransforms().size()); | ||
| // there shouldn't be a task yet | ||
| assertEquals(0, getNumberOfTransformTasks()); | ||
| startAndWaitForContinuousTransform(transformId, transformIndex, null); | ||
| assertTrue(indexExists(transformIndex)); | ||
|
|
||
| // a task exists | ||
| assertEquals(1, getNumberOfTransformTasks()); | ||
| // get and check some users | ||
| assertOnePivotValue(transformIndex + "/_search?q=reviewer:user_0", 3.776978417); | ||
| assertOnePivotValue(transformIndex + "/_search?q=reviewer:user_5", 3.72); | ||
| assertNotNull(getTransformState(transformId)); | ||
|
|
||
| assertEquals(1, getTransforms().size()); | ||
|
|
||
| // delete the transform index | ||
| beEvilAndDeleteTheTransformIndex(); | ||
| // transform is gone | ||
| assertEquals(0, getTransforms().size()); | ||
| // but the task is still there | ||
| assertEquals(1, getNumberOfTransformTasks()); | ||
|
|
||
| Request stopTransformRequest = new Request("POST", TransformField.REST_BASE_PATH_TRANSFORMS + transformId + "/_stop"); | ||
| ResponseException e = expectThrows(ResponseException.class, () -> client().performRequest(stopTransformRequest)); | ||
|
|
||
| assertEquals(409, e.getResponse().getStatusLine().getStatusCode()); | ||
| assertThat(e.getMessage(), containsString("Detected dangling transforms [" + transformId + "]. Use force to stop/delete them.")); | ||
| stopTransformRequest.addParameter(TransformField.FORCE.getPreferredName(), Boolean.toString(true)); | ||
| Map<String, Object> stopTransformResponse = entityAsMap(client().performRequest(stopTransformRequest)); | ||
| assertThat(stopTransformResponse.get("acknowledged"), equalTo(Boolean.TRUE)); | ||
|
|
||
| // the task is gone | ||
| assertEquals(1, getNumberOfTransformTasks()); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private int getNumberOfTransformTasks() throws IOException { | ||
| final Request tasksRequest = new Request("GET", "/_tasks"); | ||
| tasksRequest.addParameter("actions", TransformField.TASK_NAME + "*"); | ||
| Map<String, Object> tasksResponse = entityAsMap(client().performRequest(tasksRequest)); | ||
|
|
||
| Map<String, Object> nodes = (Map<String, Object>) tasksResponse.get("nodes"); | ||
| if (nodes == null) { | ||
| return 0; | ||
| } | ||
|
|
||
| int foundTasks = 0; | ||
| for (Entry<String, Object> node : nodes.entrySet()) { | ||
| Map<String, Object> nodeInfo = (Map<String, Object>) node.getValue(); | ||
| Map<String, Object> tasks = (Map<String, Object>) nodeInfo.get("tasks"); | ||
| foundTasks += tasks != null ? tasks.size() : 0; | ||
| } | ||
|
|
||
| return foundTasks; | ||
| } | ||
|
|
||
| private void beEvilAndDeleteTheTransformIndex() throws IOException { | ||
| adminClient().performRequest(new Request("DELETE", TransformInternalIndexConstants.LATEST_INDEX_NAME)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.