Skip to content

Commit

Permalink
[Migrations] Systematically wait for newly created indices to turn gr…
Browse files Browse the repository at this point in the history
…een (#157973)

Tackles #157968

When creating new indices during SO migrations, we used to rely on the
`res.acknowledged && res.shardsAcknowledged` of the
`esClient.indices.create(...)` to determine that the indices are ready
to use.

However, we believe that due to certain race conditions, this can cause
Kibana migrations to fail (refer to the [related
issue](#157968)).

This PR aims at fixing recent CI failures by adding a systematic
`waitForIndexStatus` after creating an index.
  • Loading branch information
gsoldevila authored May 17, 2023
1 parent 58be0c9 commit 71125b1
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,21 @@ export const createIndex = ({
AcknowledgeResponse,
'create_index_succeeded'
>((res) => {
if (res.acknowledged && res.shardsAcknowledged) {
// If the cluster state was updated and all shards started we're done
return TaskEither.right('create_index_succeeded');
} else {
// Otherwise, wait until the target index has a 'green' status meaning
// the primary (and on multi node clusters) the replica has been started
return pipe(
waitForIndexStatus({
client,
index: indexName,
timeout: DEFAULT_TIMEOUT,
status: 'green',
}),
TaskEither.map(() => {
/** When the index status is 'green' we know that all shards were started */
return 'create_index_succeeded';
})
);
}
// Systematicaly wait until the target index has a 'green' status meaning
// the primary (and on multi node clusters) the replica has been started
// see https://github.com/elastic/kibana/issues/157968
return pipe(
waitForIndexStatus({
client,
index: indexName,
timeout: DEFAULT_TIMEOUT,
status: 'green',
}),
TaskEither.map(() => {
/** When the index status is 'green' we know that all shards were started */
return 'create_index_succeeded';
})
);
})
);
};

0 comments on commit 71125b1

Please sign in to comment.