diff --git a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/model/helpers.ts b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/model/helpers.ts index 9763eda1c5b15..30e6d3d53e664 100644 --- a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/model/helpers.ts +++ b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/model/helpers.ts @@ -19,6 +19,9 @@ import type { AliasAction, FetchIndexResponse } from '../actions'; import type { BulkIndexOperationTuple } from './create_batches'; import { OutdatedDocumentsSearchRead, ReindexSourceToTempRead } from '../state'; +/** @internal */ +export const REINDEX_TEMP_SUFFIX = '_reindex_temp'; + /** @internal */ export type Aliases = Partial>; @@ -309,7 +312,7 @@ export function getMigrationType({ * @returns A temporary index name to reindex documents */ export const getTempIndexName = (indexPrefix: string, kibanaVersion: string): string => - `${indexPrefix}_${kibanaVersion}_reindex_temp`; + `${indexPrefix}_${kibanaVersion}${REINDEX_TEMP_SUFFIX}`; /** Increase batchSize by 20% until a maximum of maxBatchSize */ export const increaseBatchSize = ( diff --git a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/model/model.ts b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/model/model.ts index 38eccfd3bb087..e4f38c2a32a3c 100644 --- a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/model/model.ts +++ b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/model/model.ts @@ -46,6 +46,7 @@ import { increaseBatchSize, hasLaterVersionAlias, aliasVersion, + REINDEX_TEMP_SUFFIX, } from './helpers'; import { buildTempIndexMap, createBatches } from './create_batches'; import type { MigrationLog } from '../types'; @@ -1541,7 +1542,7 @@ export const model = (currentState: State, resW: ResponseType): // migration from the same source. return { ...stateP, controlState: 'MARK_VERSION_INDEX_READY_CONFLICT' }; } else if (isTypeof(left, 'index_not_found_exception')) { - if (left.index === stateP.tempIndex) { + if (left.index.endsWith(REINDEX_TEMP_SUFFIX)) { // another instance has already completed the migration and deleted // the temporary index return { ...stateP, controlState: 'MARK_VERSION_INDEX_READY_CONFLICT' }; diff --git a/src/core/server/integration_tests/saved_objects/migrations/group3/dot_kibana_split.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group3/dot_kibana_split.test.ts index 72fc1aad81e3e..a7377ec2050d1 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group3/dot_kibana_split.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group3/dot_kibana_split.test.ts @@ -12,6 +12,7 @@ import { type ISavedObjectTypeRegistry, type SavedObjectsType, MAIN_SAVED_OBJECT_INDEX, + ALL_SAVED_OBJECT_INDICES, } from '@kbn/core-saved-objects-server'; import { DEFAULT_INDEX_TYPES_MAP } from '@kbn/core-saved-objects-base-server-internal'; import { @@ -406,6 +407,7 @@ describe('split .kibana index into multiple system indices', () => { }); // FLAKY: https://github.com/elastic/kibana/issues/157510 + // This test takes too long. Can be manually executed to verify the correct behavior. describe.skip('when multiple Kibana migrators run in parallel', () => { it('correctly migrates 7.7.2_xpack_100k_obj.zip archive', async () => { esServer = await startElasticsearch({ @@ -414,15 +416,29 @@ describe('split .kibana index into multiple system indices', () => { const esClient = await getEsClient(); const breakdownBefore = await getAggregatedTypesCountAllIndices(esClient); - expect(breakdownBefore).toMatchSnapshot('before migration'); + expect(breakdownBefore).toEqual({ + '.kibana': { + 'apm-telemetry': 1, + config: 1, + dashboard: 52994, + 'index-pattern': 1, + search: 1, + space: 1, + 'ui-metric': 5, + visualization: 53004, + }, + '.kibana_task_manager': { + task: 5, + }, + }); for (let i = 0; i < PARALLEL_MIGRATORS; ++i) { await clearLog(Path.join(__dirname, `dot_kibana_split_instance_${i}.log`)); } const testKits = await Promise.all( - new Array(PARALLEL_MIGRATORS) - .fill({ + new Array(PARALLEL_MIGRATORS).fill(true).map((_, index) => + getKibanaMigratorTestKit({ settings: { migrations: { discardUnknownObjects: currentVersion, @@ -431,13 +447,10 @@ describe('split .kibana index into multiple system indices', () => { }, kibanaIndex: MAIN_SAVED_OBJECT_INDEX, types: typeRegistry.getAllTypes(), + defaultIndexTypesMap: DEFAULT_INDEX_TYPES_MAP, + logFilePath: Path.join(__dirname, `dot_kibana_split_instance_${index}.log`), }) - .map((config, index) => - getKibanaMigratorTestKit({ - ...config, - logFilePath: Path.join(__dirname, `dot_kibana_split_instance_${index}.log`), - }) - ) + ) ); const results = await Promise.all(testKits.map((testKit) => testKit.runMigrations())); @@ -447,9 +460,30 @@ describe('split .kibana index into multiple system indices', () => { .every((result) => result.status === 'migrated' || result.status === 'patched') ).toEqual(true); + await esClient.indices.refresh({ index: ALL_SAVED_OBJECT_INDICES }); + const breakdownAfter = await getAggregatedTypesCountAllIndices(esClient); - expect(breakdownAfter).toMatchSnapshot('after migration'); - }); + expect(breakdownAfter).toEqual({ + '.kibana': { + 'apm-telemetry': 1, + config: 1, + space: 1, + 'ui-metric': 5, + }, + '.kibana_alerting_cases': {}, + '.kibana_analytics': { + dashboard: 52994, + 'index-pattern': 1, + search: 1, + visualization: 53004, + }, + '.kibana_ingest': {}, + '.kibana_security_solution': {}, + '.kibana_task_manager': { + task: 5, + }, + }); + }, 1200000); afterEach(async () => { await esServer?.stop();