Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gsoldevila committed Jun 4, 2023
1 parent 3c50588 commit 23b4e39
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export async function getIndicesInvolvedInRelocation({
defaultIndexTypesMap: IndexTypesMap;
logger: Logger;
}): Promise<string[]> {
const indicesWithMovingTypesSet = new Set<string>();
const indicesWithRelocatingTypesSet = new Set<string>();

const currentIndexTypesMap = await getCurrentIndexTypesMap({
client,
Expand All @@ -120,11 +120,11 @@ export async function getIndicesInvolvedInRelocation({
Object.values(typeIndexDistribution)
.filter(({ status }) => status === TypeStatus.Moved)
.forEach(({ currentIndex, targetIndex }) => {
indicesWithMovingTypesSet.add(currentIndex!);
indicesWithMovingTypesSet.add(targetIndex!);
indicesWithRelocatingTypesSet.add(currentIndex!);
indicesWithRelocatingTypesSet.add(targetIndex!);
});

return Array.from(indicesWithMovingTypesSet);
return Array.from(indicesWithRelocatingTypesSet);
}

export function indexMapToIndexTypesMap(indexMap: IndexMap): IndexTypesMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const runV2Migration = async (options: RunV2MigrationOpts): Promise<Migra
options.logger.debug(`migrationVersion: ${migrationVersion} saved object type: ${type}`);
});

// build a indexTypesMap from the info present in tye typeRegistry, e.g.:
// build a indexTypesMap from the info present in the typeRegistry, e.g.:
// {
// '.kibana': ['typeA', 'typeB', ...]
// '.kibana_task_manager': ['task', ...]
Expand All @@ -87,7 +87,7 @@ export const runV2Migration = async (options: RunV2MigrationOpts): Promise<Migra

// compare indexTypesMap with the one present (or not) in the .kibana index meta
// and check if some SO types have been moved to different indices
const indicesWithMovingTypes = await getIndicesInvolvedInRelocation({
const indicesWithRelocatingTypes = await getIndicesInvolvedInRelocation({
mainIndex: options.kibanaIndexPrefix,
client: options.elasticsearchClient,
indexTypesMap,
Expand All @@ -100,10 +100,10 @@ export const runV2Migration = async (options: RunV2MigrationOpts): Promise<Migra
// A) reindex some documents TO other indices
// B) receive some documents FROM other indices
// C) both
const readyToReindexWaitGroupMap = createWaitGroupMap(indicesWithMovingTypes);
const doneReindexingWaitGroupMap = createWaitGroupMap(indicesWithMovingTypes);
const readyToReindexWaitGroupMap = createWaitGroupMap(indicesWithRelocatingTypes);
const doneReindexingWaitGroupMap = createWaitGroupMap(indicesWithRelocatingTypes);
const updateAliasesWaitGroupMap = createWaitGroupMap<AliasAction[], Promise<any>>(
indicesWithMovingTypes,
indicesWithRelocatingTypes,
(allAliasActions) =>
updateAliases({
client: options.elasticsearchClient,
Expand All @@ -113,9 +113,9 @@ export const runV2Migration = async (options: RunV2MigrationOpts): Promise<Migra

// build a list of all migrators that must be started
const migratorIndices = new Set(Object.keys(indexMap));
// indices involved in a relocation might no longer be present in current mappings
// the types in indices involved in relocation might not have mappings in the current mappings anymore
// but if their SOs must be relocated to another index, we still need a migrator to do the job
indicesWithMovingTypes.forEach((index) => migratorIndices.add(index));
indicesWithRelocatingTypes.forEach((index) => migratorIndices.add(index));

const migrators = Array.from(migratorIndices).map((indexName, i) => {
return {
Expand All @@ -124,7 +124,7 @@ export const runV2Migration = async (options: RunV2MigrationOpts): Promise<Migra
const doneReindexing = doneReindexingWaitGroupMap[indexName];
const updateRelocationAliases = updateAliasesWaitGroupMap[indexName];
// check if this migrator's index is involved in some document redistribution
const mustRelocateDocuments = indicesWithMovingTypes.includes(indexName);
const mustRelocateDocuments = indicesWithRelocatingTypes.includes(indexName);

return runResilientMigrator({
client: options.elasticsearchClient,
Expand Down

0 comments on commit 23b4e39

Please sign in to comment.