Skip to content

Commit 1a1bccd

Browse files
Spencerspalger
andcommitted
[esArchiver] actually re-delete the .kibana index if we lose recreate race (#72354)
Co-authored-by: spalger <spalger@users.noreply.github.com>
1 parent 6c0e671 commit 1a1bccd

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/es_archiver/lib/indices/create_index_stream.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import { Transform, Readable } from 'stream';
2121
import { inspect } from 'util';
2222

23-
import { get, once } from 'lodash';
2423
import { Client } from 'elasticsearch';
2524
import { ToolingLog } from '@kbn/dev-utils';
2625

@@ -54,7 +53,7 @@ export function createCreateIndexStream({
5453
// If we're trying to import Kibana index docs, we need to ensure that
5554
// previous indices are removed so we're starting w/ a clean slate for
5655
// migrations. This only needs to be done once per archive load operation.
57-
const deleteKibanaIndicesOnce = once(deleteKibanaIndices);
56+
let kibanaIndexAlreadyDeleted = false;
5857

5958
async function handleDoc(stream: Readable, record: DocRecord) {
6059
if (skipDocsFromIndices.has(record.value.index)) {
@@ -73,8 +72,9 @@ export function createCreateIndexStream({
7372

7473
async function attemptToCreate(attemptNumber = 1) {
7574
try {
76-
if (isKibana) {
77-
await deleteKibanaIndicesOnce({ client, stats, log });
75+
if (isKibana && !kibanaIndexAlreadyDeleted) {
76+
await deleteKibanaIndices({ client, stats, log });
77+
kibanaIndexAlreadyDeleted = true;
7878
}
7979

8080
await client.indices.create({
@@ -94,6 +94,7 @@ export function createCreateIndexStream({
9494
err?.body?.error?.reason?.includes('index exists with the same name as the alias') &&
9595
attemptNumber < 3
9696
) {
97+
kibanaIndexAlreadyDeleted = false;
9798
const aliasStr = inspect(aliases);
9899
log.info(
99100
`failed to create aliases [${aliasStr}] because ES indicated an index/alias already exists, trying again`
@@ -102,10 +103,7 @@ export function createCreateIndexStream({
102103
return;
103104
}
104105

105-
if (
106-
get(err, 'body.error.type') !== 'resource_already_exists_exception' ||
107-
attemptNumber >= 3
108-
) {
106+
if (err?.body?.error?.type !== 'resource_already_exists_exception' || attemptNumber >= 3) {
109107
throw err;
110108
}
111109

0 commit comments

Comments
 (0)