Skip to content

Commit

Permalink
[Transform] Ignore "index not found" error when delete_dest_index f…
Browse files Browse the repository at this point in the history
…lag is set but the dest index doesn't exist (elastic#99738) (elastic#99785)
  • Loading branch information
przemekwitek authored Sep 21, 2023
1 parent fe3ffd6 commit 9091b39
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/99738.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 99738
summary: Ignore "index not found" error when `delete_dest_index` flag is set but the
dest index doesn't exist
area: Transform
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void testDeleteWithParamDeletesAutoCreatedDestinationIndex() throws Excep
assertTrue(indexExists(transformDest));
assertTrue(aliasExists(transformDestAlias));

deleteTransform(transformId, true);
deleteTransform(transformId, false, true);
assertFalse(indexExists(transformDest));
assertFalse(aliasExists(transformDest));
}
Expand All @@ -134,7 +134,7 @@ public void testDeleteWithParamDeletesManuallyCreatedDestinationIndex() throws E
assertTrue(indexExists(transformDest));
assertTrue(aliasExists(transformDestAlias));

deleteTransform(transformId, true);
deleteTransform(transformId, false, true);
assertFalse(indexExists(transformDest));
assertFalse(aliasExists(transformDestAlias));
}
Expand All @@ -158,7 +158,7 @@ public void testDeleteWithParamDoesNotDeleteManuallySetUpAlias() throws Exceptio
assertTrue(indexExists(transformDest));
assertTrue(aliasExists(transformDestAlias));

ResponseException e = expectThrows(ResponseException.class, () -> deleteTransform(transformId, true));
ResponseException e = expectThrows(ResponseException.class, () -> deleteTransform(transformId, false, true));
assertThat(
e.getMessage(),
containsString(
Expand All @@ -170,6 +170,21 @@ public void testDeleteWithParamDoesNotDeleteManuallySetUpAlias() throws Exceptio
);
}

public void testDeleteDestinationIndexIsNoOpWhenNoDestinationIndexExists() throws Exception {
String transformId = "transform-5";
String transformDest = transformId + "_idx";
String transformDestAlias = transformId + "_alias";
setupDataAccessRole(DATA_ACCESS_ROLE, REVIEWS_INDEX_NAME, transformDest, transformDestAlias);

createTransform(transformId, transformDest, transformDestAlias);
assertFalse(indexExists(transformDest));
assertFalse(aliasExists(transformDestAlias));

deleteTransform(transformId, false, true);
assertFalse(indexExists(transformDest));
assertFalse(aliasExists(transformDestAlias));
}

private void createTransform(String transformId, String destIndex, String destAlias) throws IOException {
final Request createTransformRequest = createRequestWithAuth(
"PUT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,15 @@ protected static Map<String, Object> getTransformsStateAndStats(int from, int si
}

protected static void deleteTransform(String transformId) throws IOException {
deleteTransform(transformId, false);
// Ignore 404s because they imply someone was racing us to delete this transform.
deleteTransform(transformId, true, false);
}

protected static void deleteTransform(String transformId, boolean deleteDestIndex) throws IOException {
protected static void deleteTransform(String transformId, boolean ignoreNotFound, boolean deleteDestIndex) throws IOException {
Request request = new Request("DELETE", getTransformEndpoint() + transformId);
request.addParameter("ignore", "404"); // Ignore 404s because they imply someone was racing us to delete this
if (ignoreNotFound) {
request.addParameter("ignore", "404");
}
if (deleteDestIndex) {
request.addParameter(TransformField.DELETE_DEST_INDEX.getPreferredName(), Boolean.TRUE.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskId;
Expand Down Expand Up @@ -135,6 +136,15 @@ private void deleteDestinationIndex(
TimeValue timeout,
ActionListener<AcknowledgedResponse> listener
) {
// <3> Check if the error is "index not found" error. If so, just move on. The index is already deleted.
ActionListener<AcknowledgedResponse> deleteDestIndexListener = ActionListener.wrap(listener::onResponse, e -> {
if (e instanceof IndexNotFoundException) {
listener.onResponse(AcknowledgedResponse.TRUE);
} else {
listener.onFailure(e);
}
});

// <2> Delete destination index
ActionListener<Tuple<TransformConfig, SeqNoPrimaryTermAndIndex>> getTransformConfigurationListener = ActionListener.wrap(
transformConfigAndVersion -> {
Expand All @@ -149,7 +159,7 @@ private void deleteDestinationIndex(
client,
DeleteIndexAction.INSTANCE,
deleteDestIndexRequest,
listener
deleteDestIndexListener
);
},
listener::onFailure
Expand Down

0 comments on commit 9091b39

Please sign in to comment.