Skip to content

Commit

Permalink
migrations: handle 200 response code from _cluster/health API on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf authored Nov 8, 2021
1 parent 30493f9 commit 853a012
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ export const cloneIndex = ({
// If the cluster state was updated and all shards ackd we're done
return TaskEither.right(res);
} else {
// Otherwise, wait until the target index has a 'green' status.
// Otherwise, wait until the target index has a 'yellow' status.
return pipe(
waitForIndexStatusYellow({ client, index: target, timeout }),
TaskEither.map((value) => {
/** When the index status is 'green' we know that all shards were started */
/** When the index status is 'yellow' we know that all shards were started */
return { acknowledged: true, shardsAcknowledged: true };
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,15 @@ describe('migration actions', () => {
timeout: '0s',
})();

await expect(cloneIndexPromise).resolves.toMatchObject({
_tag: 'Left',
left: {
error: expect.any(errors.ResponseError),
message: expect.stringMatching(/\"timed_out\":true/),
type: 'retryable_es_client_error',
},
});
await expect(cloneIndexPromise).resolves.toMatchInlineSnapshot(`
Object {
"_tag": "Left",
"left": Object {
"message": "Timeout waiting for the status of the [clone_red_index] index to become 'yellow'",
"type": "retryable_es_client_error",
},
}
`);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,18 @@ export const waitForIndexStatusYellow =
}: WaitForIndexStatusYellowParams): TaskEither.TaskEither<RetryableEsClientError, {}> =>
() => {
return client.cluster
.health({ index, wait_for_status: 'yellow', timeout })
.then(() => {
.health({
index,
wait_for_status: 'yellow',
timeout,
})
.then((res) => {
if (res.body.timed_out === true) {
return Either.left({
type: 'retryable_es_client_error' as const,
message: `Timeout waiting for the status of the [${index}] index to become 'yellow'`,
});
}
return Either.right({});
})
.catch(catchRetryableEsClientErrors);
Expand Down

0 comments on commit 853a012

Please sign in to comment.