Skip to content

Commit 7b2b3d8

Browse files
Spencerspalger
andauthored
[esArchiver] automatically retry if alias creation fails (#71910)
* [esArchiver] automatically retry if alias creation fails * print aliases to a string when logging Co-authored-by: spalger <spalger@users.noreply.github.com>
1 parent 9ba750e commit 7b2b3d8

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/es_archiver/lib/indices/create_index_stream.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919

2020
import { Transform, Readable } from 'stream';
21+
import { inspect } from 'util';
22+
2123
import { get, once } from 'lodash';
2224
import { Client } from 'elasticsearch';
2325
import { ToolingLog } from '@kbn/dev-utils';
@@ -84,6 +86,18 @@ export function createCreateIndexStream({
8486

8587
stats.createdIndex(index, { settings });
8688
} catch (err) {
89+
if (
90+
err?.body?.error?.reason?.includes('index exists with the same name as the alias') &&
91+
attemptNumber < 3
92+
) {
93+
const aliasStr = inspect(aliases);
94+
log.info(
95+
`failed to create aliases [${aliasStr}] because ES indicated an index/alias already exists, trying again`
96+
);
97+
await attemptToCreate(attemptNumber + 1);
98+
return;
99+
}
100+
87101
if (
88102
get(err, 'body.error.type') !== 'resource_already_exists_exception' ||
89103
attemptNumber >= 3

0 commit comments

Comments
 (0)