Skip to content

Commit

Permalink
Fix BWC after backport of elastic#65564
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner committed Dec 2, 2020
1 parent 2ebab21 commit 1ed5dc2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 45 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ tasks.register("verifyVersions") {
* after the backport of the backcompat code is complete.
*/

boolean bwc_tests_enabled = false
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/65689" /* place a PR link here when committing bwc changes */
boolean bwc_tests_enabled = true
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
if (bwc_tests_enabled == false) {
if (bwc_tests_disabled_issue.isEmpty()) {
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import java.util.Objects;
import java.util.stream.IntStream;

import static org.elasticsearch.index.shard.ShardLongFieldRange.LONG_FIELD_RANGE_VERSION_INTRODUCED;

/**
* Class representing an (inclusive) range of {@code long} values in a field in an index which may comprise multiple shards. This
* information is accumulated shard-by-shard, and we keep track of which shards are represented in this value. Only once all shards are
Expand Down Expand Up @@ -120,33 +118,26 @@ public long getMax() {

@Override
public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(LONG_FIELD_RANGE_VERSION_INTRODUCED)) {
if (this == NO_SHARDS) {
out.writeByte(WIRE_TYPE_NO_SHARDS);
} else if (this == UNKNOWN) {
out.writeByte(WIRE_TYPE_UNKNOWN);
} else if (this == EMPTY) {
out.writeByte(WIRE_TYPE_EMPTY);
if (this == NO_SHARDS) {
out.writeByte(WIRE_TYPE_NO_SHARDS);
} else if (this == UNKNOWN) {
out.writeByte(WIRE_TYPE_UNKNOWN);
} else if (this == EMPTY) {
out.writeByte(WIRE_TYPE_EMPTY);
} else {
out.writeByte(WIRE_TYPE_OTHER);
if (shards == null) {
out.writeBoolean(false);
} else {
out.writeByte(WIRE_TYPE_OTHER);
if (shards == null) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeVIntArray(shards);
}
out.writeZLong(min);
out.writeZLong(max);
out.writeBoolean(true);
out.writeVIntArray(shards);
}
out.writeZLong(min);
out.writeZLong(max);
}
}

public static IndexLongFieldRange readFrom(StreamInput in) throws IOException {
if (in.getVersion().before(LONG_FIELD_RANGE_VERSION_INTRODUCED)) {
// conservative treatment for BWC
return UNKNOWN;
}

final byte type = in.readByte();
switch (type) {
case WIRE_TYPE_NO_SHARDS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.index.shard;

import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
Expand All @@ -32,8 +31,6 @@
*/
public class ShardLongFieldRange implements Writeable {

public static final Version LONG_FIELD_RANGE_VERSION_INTRODUCED = Version.V_8_0_0;

/**
* Sentinel value indicating an empty range, for instance because the field is missing or has no values.
*/
Expand Down Expand Up @@ -91,11 +88,6 @@ public String toString() {
private static final byte WIRE_TYPE_EMPTY = (byte)2;

public static ShardLongFieldRange readFrom(StreamInput in) throws IOException {
if (in.getVersion().before(LONG_FIELD_RANGE_VERSION_INTRODUCED)) {
// conservative treatment for BWC
return UNKNOWN;
}

final byte type = in.readByte();
switch (type) {
case WIRE_TYPE_UNKNOWN:
Expand All @@ -111,16 +103,14 @@ public static ShardLongFieldRange readFrom(StreamInput in) throws IOException {

@Override
public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(LONG_FIELD_RANGE_VERSION_INTRODUCED)) {
if (this == UNKNOWN) {
out.writeByte(WIRE_TYPE_UNKNOWN);
} else if (this == EMPTY) {
out.writeByte(WIRE_TYPE_EMPTY);
} else {
out.writeByte(WIRE_TYPE_OTHER);
out.writeZLong(min);
out.writeZLong(max);
}
if (this == UNKNOWN) {
out.writeByte(WIRE_TYPE_UNKNOWN);
} else if (this == EMPTY) {
out.writeByte(WIRE_TYPE_EMPTY);
} else {
out.writeByte(WIRE_TYPE_OTHER);
out.writeZLong(min);
out.writeZLong(max);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,7 @@ public void testStartedShardEntrySerialization() throws Exception {
assertThat(deserialized.allocationId, equalTo(allocationId));
assertThat(deserialized.primaryTerm, equalTo(primaryTerm));
assertThat(deserialized.message, equalTo(message));
assertThat(deserialized.timestampMillisRange, version.onOrAfter(ShardLongFieldRange.LONG_FIELD_RANGE_VERSION_INTRODUCED) ?
equalTo(timestampMillisRange) : sameInstance(ShardLongFieldRange.UNKNOWN));
assertThat(deserialized.timestampMillisRange, equalTo(timestampMillisRange));
}
}

Expand Down

0 comments on commit 1ed5dc2

Please sign in to comment.