Skip to content

Commit ef875cf

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

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)) {
@@ -70,8 +69,9 @@ export function createCreateIndexStream({
7069

7170
async function attemptToCreate(attemptNumber = 1) {
7271
try {
73-
if (isKibana) {
74-
await deleteKibanaIndicesOnce({ client, stats, log });
72+
if (isKibana && !kibanaIndexAlreadyDeleted) {
73+
await deleteKibanaIndices({ client, stats, log });
74+
kibanaIndexAlreadyDeleted = true;
7575
}
7676

7777
await client.indices.create({
@@ -90,6 +90,7 @@ export function createCreateIndexStream({
9090
err?.body?.error?.reason?.includes('index exists with the same name as the alias') &&
9191
attemptNumber < 3
9292
) {
93+
kibanaIndexAlreadyDeleted = false;
9394
const aliasStr = inspect(aliases);
9495
log.info(
9596
`failed to create aliases [${aliasStr}] because ES indicated an index/alias already exists, trying again`
@@ -98,10 +99,7 @@ export function createCreateIndexStream({
9899
return;
99100
}
100101

101-
if (
102-
get(err, 'body.error.type') !== 'resource_already_exists_exception' ||
103-
attemptNumber >= 3
104-
) {
102+
if (err?.body?.error?.type !== 'resource_already_exists_exception' || attemptNumber >= 3) {
105103
throw err;
106104
}
107105

0 commit comments

Comments
 (0)