Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

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

* print aliases to a string when logging

Co-authored-by: spalger <[email protected]>
  • Loading branch information
Spencer and spalger committed Jul 16, 2020
1 parent b582681 commit d368860
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 d368860

Please sign in to comment.