Skip to content

Commit

Permalink
[esArchiver] automatically retry if alias creation fails (#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 8cb4e35 commit 963f298
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 963f298

Please sign in to comment.