Skip to content

Commit

Permalink
fix clearing number of replicas from existing policy (#31905)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcconaghy authored Feb 25, 2019
1 parent 77f72f7 commit ae72315
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ export const splitSizeAndUnits = field => {
};

export const isNumber = value => typeof value === 'number';
export const isEmptyObject = (obj) => {
return Object.entries(obj).length === 0 && obj.constructor === Object;
};

export const phaseFromES = (phase, phaseName, defaultPolicy) => {
const policy = { ...defaultPolicy };
Expand Down Expand Up @@ -259,15 +262,29 @@ export const phaseToES = (phase, originalEsPhase) => {
esPhase.actions.allocate.require = {
[name]: value
};
} else {
if (esPhase.actions.allocate) {
delete esPhase.actions.allocate.require;
}
}
if (isNumber(phase[PHASE_REPLICA_COUNT])) {
esPhase.actions.allocate = esPhase.actions.allocate || {};
esPhase.actions.allocate.number_of_replicas = phase[PHASE_REPLICA_COUNT];
} else {
if (esPhase.actions.allocate) {
delete esPhase.actions.allocate.require;
delete esPhase.actions.allocate.number_of_replicas;
}
}
if (esPhase.actions.allocate
&& !esPhase.actions.allocate.require
&& !esPhase.actions.allocate.number_of_replicas
&& isEmptyObject(esPhase.actions.allocate.include)
&& isEmptyObject(esPhase.actions.allocate.exclude)
) {
// remove allocate action if it does not define require or number of nodes
// and both include and exclude are empty objects (ES will fail to parse if we don't)
delete esPhase.actions.allocate;
}

if (phase[PHASE_FORCE_MERGE_ENABLED]) {
esPhase.actions.forcemerge = {
Expand Down

0 comments on commit ae72315

Please sign in to comment.