Skip to content

Commit

Permalink
Adjust RolloverAction serialization of maxPrimaryShardSize during an …
Browse files Browse the repository at this point in the history
…upgrade.

If node doesn't support maxPrimaryShardSize then serialize maxPrimaryShardSize as maxSize.
This should fix a problematic situation if an older node doesn't support maxPrimaryShardSize
and this is the only condition specified then the older node ends up with a instance without
any conditions. This could lead to upgrade failures, new nodes not able to start because
local cluster state can't be read.

Relates to elastic#69918
  • Loading branch information
martijnvg committed Mar 8, 2021
1 parent 172ca20 commit 7b01378
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,17 @@ public RolloverAction(StreamInput in) throws IOException {
@Override
public void writeTo(StreamOutput out) throws IOException {
boolean hasMaxSize = maxSize != null;
out.writeBoolean(hasMaxSize);
boolean hasMaxPrimaryShardSize = maxPrimaryShardSize != null;
if (hasMaxSize) {
out.writeBoolean(true);
maxSize.writeTo(out);
} else if (hasMaxPrimaryShardSize && out.getVersion().before(Version.V_7_13_0)) {
out.writeBoolean(true);
maxPrimaryShardSize.writeTo(out);
} else {
out.writeBoolean(false);
}
if (out.getVersion().onOrAfter(Version.V_7_13_0)) {
boolean hasMaxPrimaryShardSize = maxPrimaryShardSize != null;
out.writeBoolean(hasMaxPrimaryShardSize);
if (hasMaxPrimaryShardSize) {
maxPrimaryShardSize.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.elasticsearch.xpack.core.ilm;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
Expand All @@ -16,6 +17,9 @@
import java.io.IOException;
import java.util.List;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;

public class RolloverActionTests extends AbstractActionTestCase<RolloverAction> {

@Override
Expand Down Expand Up @@ -118,4 +122,18 @@ public void testToSteps() {
assertEquals(action.getMaxDocs(), firstStep.getMaxDocs());
assertEquals(nextStepKey, fifthStep.getNextStepKey());
}

public void testBwcSerializationWithMaxPrimaryShardSize() throws Exception {
// In case of serializing to node with older version, replace maxPrimaryShardSize with maxSize.
RolloverAction instance = new RolloverAction(null, new ByteSizeValue(1L), null, null);
RolloverAction deserializedInstance = copyInstance(instance, Version.V_7_11_2);
assertThat(deserializedInstance.getMaxPrimaryShardSize(), nullValue());
assertThat(deserializedInstance.getMaxSize(), equalTo(instance.getMaxPrimaryShardSize()));

// But not if maxSize is also specified:
instance = new RolloverAction(new ByteSizeValue(1L), new ByteSizeValue(2L), null, null);
deserializedInstance = copyInstance(instance, Version.V_7_11_2);
assertThat(deserializedInstance.getMaxPrimaryShardSize(), nullValue());
assertThat(deserializedInstance.getMaxSize(), equalTo(instance.getMaxSize()));
}
}

0 comments on commit 7b01378

Please sign in to comment.