Skip to content

Commit f2f809e

Browse files
authored
Fix 1.x compatibility bug with stored Tasks (#5412) (#5440)
When the new 'cancelled' field was introduced it was a miss not to increment the version number on the mapping definitions for the .tasks index. This commit fixes that oversight, as well as modifies the existing backward compatiblity test to ensure that it will catch future mistakes like this one. Closes #5376 Signed-off-by: Andrew Ross <andrross@amazon.com> (cherry picked from commit 4616dfa) Signed-off-by: Andrew Ross <andrross@amazon.com> Signed-off-by: Andrew Ross <andrross@amazon.com>
1 parent b7005c7 commit f2f809e

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
88
### Deprecated
99
### Removed
1010
### Fixed
11+
- Fix 1.x compatibility bug with stored Tasks ([#5412](https://github.com/opensearch-project/OpenSearch/pull/5412))
1112
### Security
1213

1314
## [2.4]

qa/rolling-upgrade/src/test/java/org/opensearch/upgrades/SystemIndicesUpgradeIT.java

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@
3434

3535
import org.opensearch.LegacyESVersion;
3636
import org.opensearch.Version;
37+
import org.hamcrest.MatcherAssert;
3738
import org.opensearch.client.Request;
39+
import org.opensearch.client.Response;
3840
import org.opensearch.client.ResponseException;
3941
import org.opensearch.test.XContentTestUtils.JsonMapView;
4042

43+
import java.io.IOException;
4144
import java.util.Map;
4245

4346
import static org.opensearch.cluster.metadata.IndexNameExpressionResolver.SYSTEM_INDEX_ENFORCEMENT_VERSION;
47+
import static org.hamcrest.Matchers.equalTo;
4448
import static org.hamcrest.Matchers.hasKey;
4549
import static org.hamcrest.Matchers.is;
4650
import static org.hamcrest.Matchers.notNullValue;
@@ -68,25 +72,7 @@ public void testSystemIndicesUpgrades() throws Exception {
6872
}
6973
client().performRequest(bulk);
7074

71-
// start a async reindex job
72-
Request reindex = new Request("POST", "/_reindex");
73-
reindex.setJsonEntity(
74-
"{\n" +
75-
" \"source\":{\n" +
76-
" \"index\":\"test_index_old\"\n" +
77-
" },\n" +
78-
" \"dest\":{\n" +
79-
" \"index\":\"test_index_reindex\"\n" +
80-
" }\n" +
81-
"}");
82-
reindex.addParameter("wait_for_completion", "false");
83-
Map<String, Object> response = entityAsMap(client().performRequest(reindex));
84-
String taskId = (String) response.get("task");
85-
86-
// wait for task
87-
Request getTask = new Request("GET", "/_tasks/" + taskId);
88-
getTask.addParameter("wait_for_completion", "true");
89-
client().performRequest(getTask);
75+
createAndVerifyStoredTask();
9076

9177
// make sure .tasks index exists
9278
Request getTasksIndex = new Request("GET", "/.tasks");
@@ -121,6 +107,8 @@ public void testSystemIndicesUpgrades() throws Exception {
121107
assertThat(client().performRequest(putAliasRequest).getStatusLine().getStatusCode(), is(200));
122108
}
123109
} else if (CLUSTER_TYPE == ClusterType.UPGRADED) {
110+
createAndVerifyStoredTask();
111+
124112
assertBusy(() -> {
125113
Request clusterStateRequest = new Request("GET", "/_cluster/state/metadata");
126114
Map<String, Object> indices = new JsonMapView(entityAsMap(client().performRequest(clusterStateRequest)))
@@ -152,4 +140,29 @@ public void testSystemIndicesUpgrades() throws Exception {
152140
});
153141
}
154142
}
143+
144+
/**
145+
* Completed tasks get persisted into the .tasks index, so this method waits
146+
* until the task is completed in order to verify that it has been successfully
147+
* written to the index and can be retrieved.
148+
*/
149+
private static void createAndVerifyStoredTask() throws Exception {
150+
// Use update by query to create an async task
151+
final Request updateByQueryRequest = new Request("POST", "/test_index_old/_update_by_query");
152+
updateByQueryRequest.addParameter("wait_for_completion", "false");
153+
final Response updateByQueryResponse = client().performRequest(updateByQueryRequest);
154+
MatcherAssert.assertThat(updateByQueryResponse.getStatusLine().getStatusCode(), equalTo(200));
155+
final String taskId = (String) entityAsMap(updateByQueryResponse).get("task");
156+
157+
// wait for task to complete
158+
waitUntil(() -> {
159+
try {
160+
final Response getTaskResponse = client().performRequest(new Request("GET", "/_tasks/" + taskId));
161+
MatcherAssert.assertThat(getTaskResponse.getStatusLine().getStatusCode(), equalTo(200));
162+
return (Boolean) entityAsMap(getTaskResponse).get("completed");
163+
} catch (IOException e) {
164+
throw new AssertionError(e);
165+
}
166+
});
167+
}
155168
}

server/src/main/java/org/opensearch/tasks/TaskResultsService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class TaskResultsService {
8686

8787
public static final String TASK_RESULT_MAPPING_VERSION_META_FIELD = "version";
8888

89-
public static final int TASK_RESULT_MAPPING_VERSION = 3; // must match version in task-index-mapping.json
89+
public static final int TASK_RESULT_MAPPING_VERSION = 4; // must match version in task-index-mapping.json
9090

9191
/**
9292
* The backoff policy to use when saving a task result fails. The total wait

server/src/main/resources/org/opensearch/tasks/task-index-mapping.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"_doc" : {
33
"_meta": {
4-
"version": 3
4+
"version": 4
55
},
66
"dynamic" : "strict",
77
"properties" : {

0 commit comments

Comments
 (0)