Skip to content

Commit

Permalink
[esArchiver] automatically retry if alias creation fails (#71910) (#7…
Browse files Browse the repository at this point in the history
…2002)

* [esArchiver] automatically retry if alias creation fails

* print aliases to a string when logging

Co-authored-by: spalger <[email protected]>

Co-authored-by: spalger <[email protected]>
  • Loading branch information
Spencer and spalger authored Jul 16, 2020
1 parent e58794b commit 666846d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/es_archiver/lib/indices/create_index_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

import { Transform, Readable } from 'stream';
import { inspect } from 'util';

import { get, once } from 'lodash';
import { Client } from 'elasticsearch';
import { ToolingLog } from '@kbn/dev-utils';
Expand Down Expand Up @@ -88,6 +90,18 @@ export function createCreateIndexStream({

stats.createdIndex(index, { settings });
} catch (err) {
if (
err?.body?.error?.reason?.includes('index exists with the same name as the alias') &&
attemptNumber < 3
) {
const aliasStr = inspect(aliases);
log.info(
`failed to create aliases [${aliasStr}] because ES indicated an index/alias already exists, trying again`
);
await attemptToCreate(attemptNumber + 1);
return;
}

if (
get(err, 'body.error.type') !== 'resource_already_exists_exception' ||
attemptNumber >= 3
Expand Down

0 comments on commit 666846d

Please sign in to comment.