[ML][Transforms] fix bwc serialization with 7.3 (#48021) (#48048)

This commit is contained in:
Benjamin Trent 2019-10-15 07:52:13 -04:00 committed by GitHub
parent 83321b0e5e
commit 361e7ad0ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 3 deletions

View File

@ -123,7 +123,7 @@ public class TransformStats implements Writeable, ToXContentObject {
TransformState transformState = new TransformState(in); TransformState transformState = new TransformState(in);
this.state = State.fromComponents(transformState.getTaskState(), transformState.getIndexerState()); this.state = State.fromComponents(transformState.getTaskState(), transformState.getIndexerState());
this.reason = transformState.getReason(); this.reason = transformState.getReason();
this.node = null; this.node = transformState.getNode();
this.indexerStats = new TransformIndexerStats(in); this.indexerStats = new TransformIndexerStats(in);
this.checkpointingInfo = new TransformCheckpointingInfo(in); this.checkpointingInfo = new TransformCheckpointingInfo(in);
} }
@ -171,8 +171,8 @@ public class TransformStats implements Writeable, ToXContentObject {
checkpointingInfo.getNext().getPosition(), checkpointingInfo.getNext().getPosition(),
checkpointingInfo.getLast().getCheckpoint(), checkpointingInfo.getLast().getCheckpoint(),
reason, reason,
checkpointingInfo.getNext().getCheckpointProgress()).writeTo(out); checkpointingInfo.getNext().getCheckpointProgress(),
out.writeBoolean(false); node).writeTo(out);
indexerStats.writeTo(out); indexerStats.writeTo(out);
checkpointingInfo.writeTo(out); checkpointingInfo.writeTo(out);
} }

View File

@ -6,6 +6,9 @@
package org.elasticsearch.xpack.core.transform.transforms; package org.elasticsearch.xpack.core.transform.transforms;
import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.Writeable.Reader; import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractSerializingTestCase; import org.elasticsearch.test.AbstractSerializingTestCase;
@ -13,6 +16,9 @@ import org.elasticsearch.test.AbstractSerializingTestCase;
import java.io.IOException; import java.io.IOException;
import java.util.function.Predicate; import java.util.function.Predicate;
import static org.elasticsearch.xpack.core.transform.transforms.TransformStats.State.STARTED;
import static org.hamcrest.Matchers.equalTo;
public class TransformStatsTests extends AbstractSerializingTestCase<TransformStats> { public class TransformStatsTests extends AbstractSerializingTestCase<TransformStats> {
public static TransformStats randomDataFrameTransformStats() { public static TransformStats randomDataFrameTransformStats() {
@ -53,4 +59,28 @@ public class TransformStatsTests extends AbstractSerializingTestCase<TransformSt
protected Predicate<String> getRandomFieldsExcludeFilter() { protected Predicate<String> getRandomFieldsExcludeFilter() {
return field -> !field.isEmpty(); return field -> !field.isEmpty();
} }
public void testBwcWith73() throws IOException {
for(int i = 0; i < NUMBER_OF_TEST_RUNS; i++) {
TransformStats stats = new TransformStats("bwc-id",
STARTED,
randomBoolean() ? null : randomAlphaOfLength(100),
randomBoolean() ? null : NodeAttributeTests.randomNodeAttributes(),
new TransformIndexerStats(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
new TransformCheckpointingInfo(
new TransformCheckpointStats(0, null, null, 10, 100),
new TransformCheckpointStats(0, null, null, 100, 1000),
// changesLastDetectedAt aren't serialized back
100, null));
try (BytesStreamOutput output = new BytesStreamOutput()) {
output.setVersion(Version.V_7_3_0);
stats.writeTo(output);
try (StreamInput in = output.bytes().streamInput()) {
in.setVersion(Version.V_7_3_0);
TransformStats statsFromOld = new TransformStats(in);
assertThat(statsFromOld, equalTo(stats));
}
}
}
}
} }