migrations: handle 200 response code from _cluster/health API on timeout

This commit is contained in:
Rudolf Meijering 2021-11-08 21:06:07 +01:00 committed by GitHub
parent 30493f90be
commit 853a0126fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 12 deletions

View file

@ -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 };
})
);

View file

@ -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",
},
}
`);
});
});

View file

@ -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);