Skip to content

Commit

Permalink
fix: improve disabling and restoration of ES indexing settings (#4187)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j authored Jun 28, 2024
1 parent 3433560 commit d65c7e6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ interface LastEvaluatedKey {
}

interface IndexSettings {
number_of_replicas: number;
refresh_interval: `${number}s`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ interface LastEvaluatedKey {
}

interface IndexSettings {
number_of_replicas: number;
refresh_interval: `${number}s`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ interface LastEvaluatedKey {
}

interface IndexSettings {
number_of_replicas: number;
refresh_interval: `${number}s`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ interface LastEvaluatedKey {
}

interface IndexSettings {
number_of_replicas: number;
refresh_interval: `${number}s`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const disableElasticsearchIndexing = async (
elasticsearchClient: params.elasticsearchClient,
index,
settings: {
number_of_replicas: 0,
refresh_interval: -1
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface FetchOriginalElasticsearchSettingsParams {
}

interface IndexSettings {
number_of_replicas: number;
refresh_interval: `${number}s`;
}

Expand All @@ -21,10 +20,9 @@ export const fetchOriginalElasticsearchSettings = async (
const settings = await esGetIndexSettings({
elasticsearchClient: params.elasticsearchClient,
index,
fields: ["number_of_replicas", "refresh_interval"]
fields: ["refresh_interval"]
});
return {
number_of_replicas: settings.number_of_replicas || 1,
refresh_interval: settings.refresh_interval || "1s"
};
} catch (ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Logger } from "@webiny/data-migration";
import { Client } from "@elastic/elasticsearch";

interface IndexSettings {
number_of_replicas: number;
refresh_interval: `${number}s`;
refresh_interval: `${number}s` | "-1";
}

interface RestoreOriginalElasticsearchSettingsParams {
Expand All @@ -30,13 +29,22 @@ export const restoreOriginalElasticsearchSettings = async (
if (!settings || typeof settings !== "object") {
continue;
}

// We must ensure that the refresh interval is not set to a negative value. Why?
// We've had a case where a migration run has been manually stopped, and the index settings
// were never restored. Once a second run was started and this restore function
// was called, the refresh interval was set to `-1s`, which effectively disabled indexing.
let refreshInterval = settings.refresh_interval || `1s`;
if (refreshInterval === "-1") {
refreshInterval = "1s";
}

try {
await esPutIndexSettings({
elasticsearchClient: params.elasticsearchClient,
index,
settings: {
number_of_replicas: settings.number_of_replicas || 1,
refresh_interval: settings.refresh_interval || `1s`
refresh_interval: refreshInterval
}
});
} catch (ex) {
Expand Down

0 comments on commit d65c7e6

Please sign in to comment.