Skip to content

Commit

Permalink
remove 6.3.x constants
Browse files Browse the repository at this point in the history
relates to refactoring effort elastic#41164.
  • Loading branch information
talevy committed May 10, 2019
1 parent f42dcf2 commit a4e102d
Show file tree
Hide file tree
Showing 48 changed files with 137 additions and 903 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ public boolean equals(Object other) {

public static class Builder {
private String jobId;

// Stored snapshot documents created prior to 6.3.0 will have no value for min_version.
private Version minVersion = Version.V_6_3_0;

private Version minVersion;
private Date timestamp;
private String description;
private String snapshotId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.index.rankeval;

import org.elasticsearch.Version;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
Expand Down Expand Up @@ -51,18 +50,8 @@ public RankEvalRequest(RankEvalSpec rankingEvaluationSpec, String[] indices) {
RankEvalRequest(StreamInput in) throws IOException {
super.readFrom(in);
rankingEvaluationSpec = new RankEvalSpec(in);
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
indices = in.readStringArray();
indicesOptions = IndicesOptions.readIndicesOptions(in);
} else {
// readStringArray uses readVInt for size, we used readInt in 6.2
int indicesSize = in.readInt();
String[] indices = new String[indicesSize];
for (int i = 0; i < indicesSize; i++) {
indices[i] = in.readString();
}
// no indices options yet
}
indices = in.readStringArray();
indicesOptions = IndicesOptions.readIndicesOptions(in);
}

RankEvalRequest() {
Expand Down Expand Up @@ -131,17 +120,8 @@ public void readFrom(StreamInput in) throws IOException {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
rankingEvaluationSpec.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_6_3_0)) {
out.writeStringArray(indices);
indicesOptions.writeIndicesOptions(out);
} else {
// writeStringArray uses writeVInt for size, we used writeInt in 6.2
out.writeInt(indices.length);
for (String index : indices) {
out.writeString(index);
}
// no indices options yet
}
out.writeStringArray(indices);
indicesOptions.writeIndicesOptions(out);
}

@Override
Expand Down
34 changes: 11 additions & 23 deletions server/src/main/java/org/elasticsearch/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,10 @@ public String date() {
public static Build readBuild(StreamInput in) throws IOException {
final Flavor flavor;
final Type type;
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
// be lenient when reading on the wire, the enumeration values from other versions might be different than what we know
flavor = Flavor.fromDisplayName(in.readString(), false);
} else {
flavor = Flavor.OSS;
}
if (in.getVersion().onOrAfter(Version.V_6_3_0)) {
// be lenient when reading on the wire, the enumeration values from other versions might be different than what we know
type = Type.fromDisplayName(in.readString(), false);
} else {
type = Type.UNKNOWN;
}
// be lenient when reading on the wire, the enumeration values from other versions might be different than what we know
flavor = Flavor.fromDisplayName(in.readString(), false);
// be lenient when reading on the wire, the enumeration values from other versions might be different than what we know
type = Type.fromDisplayName(in.readString(), false);
String hash = in.readString();
String date = in.readString();
boolean snapshot = in.readBoolean();
Expand All @@ -250,18 +242,14 @@ public static Build readBuild(StreamInput in) throws IOException {
}

public static void writeBuild(Build build, StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_6_3_0)) {
out.writeString(build.flavor().displayName());
}
if (out.getVersion().onOrAfter(Version.V_6_3_0)) {
final Type buildType;
if (out.getVersion().before(Version.V_6_7_0) && build.type() == Type.DOCKER) {
buildType = Type.TAR;
} else {
buildType = build.type();
}
out.writeString(buildType.displayName());
out.writeString(build.flavor().displayName());
final Type buildType;
if (out.getVersion().before(Version.V_6_7_0) && build.type() == Type.DOCKER) {
buildType = Type.TAR;
} else {
buildType = build.type();
}
out.writeString(buildType.displayName());
out.writeString(build.shortHash());
out.writeString(build.date());
out.writeBoolean(build.isSnapshot());
Expand Down
12 changes: 0 additions & 12 deletions server/src/main/java/org/elasticsearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ public class Version implements Comparable<Version>, ToXContentFragment {
public static final Version V_6_2_3 = new Version(V_6_2_3_ID, LUCENE_7_2_1);
public static final int V_6_2_4_ID = 6020499;
public static final Version V_6_2_4 = new Version(V_6_2_4_ID, LUCENE_7_2_1);
public static final int V_6_3_0_ID = 6030099;
public static final Version V_6_3_0 = new Version(V_6_3_0_ID, org.apache.lucene.util.Version.LUCENE_7_3_1);
public static final int V_6_3_1_ID = 6030199;
public static final Version V_6_3_1 = new Version(V_6_3_1_ID, org.apache.lucene.util.Version.LUCENE_7_3_1);
public static final int V_6_3_2_ID = 6030299;
public static final Version V_6_3_2 = new Version(V_6_3_2_ID, org.apache.lucene.util.Version.LUCENE_7_3_1);
public static final int V_6_4_0_ID = 6040099;
public static final Version V_6_4_0 = new Version(V_6_4_0_ID, org.apache.lucene.util.Version.LUCENE_7_4_0);
public static final int V_6_4_1_ID = 6040199;
Expand Down Expand Up @@ -186,12 +180,6 @@ public static Version fromId(int id) {
return V_6_4_1;
case V_6_4_0_ID:
return V_6_4_0;
case V_6_3_2_ID:
return V_6_3_2;
case V_6_3_1_ID:
return V_6_3_1;
case V_6_3_0_ID:
return V_6_3_0;
case V_6_2_4_ID:
return V_6_2_4;
case V_6_2_3_ID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.elasticsearch.index.mapper;

import org.apache.logging.log4j.LogManager;
import org.elasticsearch.Version;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.xcontent.ToXContentObject;
Expand Down Expand Up @@ -160,8 +159,7 @@ public static XContentFieldType fromString(String value) {
public abstract String defaultMappingType();
}

public static DynamicTemplate parse(String name, Map<String, Object> conf,
Version indexVersionCreated) throws MapperParsingException {
public static DynamicTemplate parse(String name, Map<String, Object> conf) throws MapperParsingException {
String match = null;
String pathMatch = null;
String unmatch = null;
Expand Down Expand Up @@ -207,18 +205,16 @@ public static DynamicTemplate parse(String name, Map<String, Object> conf,

final MatchType matchType = MatchType.fromString(matchPattern);

if (indexVersionCreated.onOrAfter(Version.V_6_3_0)) {
// Validate that the pattern
for (String regex : new String[] { pathMatch, match, pathUnmatch, unmatch }) {
if (regex == null) {
continue;
}
try {
matchType.matches(regex, "");
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Pattern [" + regex + "] of type [" + matchType
+ "] is invalid. Cannot create dynamic template [" + name + "].", e);
}
// Validate that the pattern
for (String regex : new String[] { pathMatch, match, pathUnmatch, unmatch }) {
if (regex == null) {
continue;
}
try {
matchType.matches(regex, "");
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Pattern [" + regex + "] of type [" + matchType
+ "] is invalid. Cannot create dynamic template [" + name + "].", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected boolean processField(RootObjectMapper.Builder builder, String fieldNam
Map.Entry<String, Object> entry = tmpl.entrySet().iterator().next();
String templateName = entry.getKey();
Map<String, Object> templateParams = (Map<String, Object>) entry.getValue();
DynamicTemplate template = DynamicTemplate.parse(templateName, templateParams, indexVersionCreated);
DynamicTemplate template = DynamicTemplate.parse(templateName, templateParams);
if (template != null) {
templates.add(template);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,6 @@ boolean includeNumDocs(Version version) {
return version.onOrAfter(Version.V_6_2_2);
}

boolean includeExistingSyncId(Version version) {
return version.onOrAfter(Version.V_6_3_0);
}

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
Expand All @@ -611,9 +607,7 @@ public void readFrom(StreamInput in) throws IOException {
} else {
numDocs = UNKNOWN_NUM_DOCS;
}
if (includeExistingSyncId(in.getVersion())) {
existingSyncId = in.readOptionalString();
}
existingSyncId = in.readOptionalString();
}

@Override
Expand All @@ -623,9 +617,7 @@ public void writeTo(StreamOutput out) throws IOException {
if (includeNumDocs(out.getVersion())) {
out.writeInt(numDocs);
}
if (includeExistingSyncId(out.getVersion())) {
out.writeOptionalString(existingSyncId);
}
out.writeOptionalString(existingSyncId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

/**
* A slice builder allowing to split a scroll in multiple partitions.
* If the provided field is the "_uid" it uses a {@link org.elasticsearch.search.slice.TermsSliceQuery}
* If the provided field is the "_id" it uses a {@link org.elasticsearch.search.slice.TermsSliceQuery}
* to do the slicing. The slicing is done at the shard level first and then each shard is split into multiple slices.
* For instance if the number of shards is equal to 2 and the user requested 4 slices
* then the slices 0 and 2 are assigned to the first shard and the slices 1 and 3 are assigned to the second shard.
Expand All @@ -79,7 +79,7 @@ public class SliceBuilder implements Writeable, ToXContentObject {
PARSER.declareInt(SliceBuilder::setMax, MAX_FIELD);
}

/** Name of field to slice against (_uid by default) */
/** Name of field to slice against (_id by default) */
private String field = IdFieldMapper.NAME;
/** The id of the slice */
private int id = -1;
Expand All @@ -106,22 +106,14 @@ public SliceBuilder(String field, int id, int max) {

public SliceBuilder(StreamInput in) throws IOException {
String field = in.readString();
if ("_uid".equals(field) && in.getVersion().before(Version.V_6_3_0)) {
// This is safe because _id and _uid are handled the same way in #toFilter
field = IdFieldMapper.NAME;
}
this.field = field;
this.id = in.readVInt();
this.max = in.readVInt();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
if (IdFieldMapper.NAME.equals(field) && out.getVersion().before(Version.V_6_3_0)) {
out.writeString("_uid");
} else {
out.writeString(field);
}
out.writeString(field);
out.writeVInt(id);
out.writeVInt(max);
}
Expand Down Expand Up @@ -257,15 +249,7 @@ public Query toFilter(ClusterService clusterService, ShardSearchRequest request,

String field = this.field;
boolean useTermQuery = false;
if ("_uid".equals(field)) {
// on new indices, the _id acts as a _uid
field = IdFieldMapper.NAME;
if (context.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_7_0_0)) {
throw new IllegalArgumentException("Computing slices on the [_uid] field is illegal for 7.x indices, use [_id] instead");
}
DEPRECATION_LOG.deprecated("Computing slices on the [_uid] field is deprecated for 6.x indices, use [_id] instead");
useTermQuery = true;
} else if (IdFieldMapper.NAME.equals(field)) {
if (IdFieldMapper.NAME.equals(field)) {
useTermQuery = true;
} else if (type.hasDocValues() == false) {
throw new IllegalArgumentException("cannot load numeric doc values on " + field);
Expand Down
11 changes: 0 additions & 11 deletions server/src/test/java/org/elasticsearch/BuildTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,30 +199,19 @@ public void testSerializationBWC() throws IOException {
randomAlphaOfLength(6), randomAlphaOfLength(6), randomBoolean(), randomAlphaOfLength(6)));

final List<Version> versions = Version.getDeclaredVersions(Version.class);
final Version pre63Version = randomFrom(versions.stream().filter(v -> v.before(Version.V_6_3_0)).collect(Collectors.toList()));
final Version post63Pre67Version = randomFrom(versions.stream()
.filter(v -> v.onOrAfter(Version.V_6_3_0) && v.before(Version.V_6_7_0)).collect(Collectors.toList()));
final Version post67Pre70Version = randomFrom(versions.stream()
.filter(v -> v.onOrAfter(Version.V_6_7_0) && v.before(Version.V_7_0_0)).collect(Collectors.toList()));
final Version post70Version = randomFrom(versions.stream().filter(v -> v.onOrAfter(Version.V_7_0_0)).collect(Collectors.toList()));

final WriteableBuild pre63 = copyWriteable(dockerBuild, writableRegistry(), WriteableBuild::new, pre63Version);
final WriteableBuild post63pre67 = copyWriteable(dockerBuild, writableRegistry(), WriteableBuild::new, post63Pre67Version);
final WriteableBuild post67pre70 = copyWriteable(dockerBuild, writableRegistry(), WriteableBuild::new, post67Pre70Version);
final WriteableBuild post70 = copyWriteable(dockerBuild, writableRegistry(), WriteableBuild::new, post70Version);

assertThat(pre63.build.flavor(), equalTo(Build.Flavor.OSS));
assertThat(post63pre67.build.flavor(), equalTo(dockerBuild.build.flavor()));
assertThat(post67pre70.build.flavor(), equalTo(dockerBuild.build.flavor()));
assertThat(post70.build.flavor(), equalTo(dockerBuild.build.flavor()));

assertThat(pre63.build.type(), equalTo(Build.Type.UNKNOWN));
assertThat(post63pre67.build.type(), equalTo(Build.Type.TAR));
assertThat(post67pre70.build.type(), equalTo(dockerBuild.build.type()));
assertThat(post70.build.type(), equalTo(dockerBuild.build.type()));

assertThat(pre63.build.getQualifiedVersion(), equalTo(pre63Version.toString()));
assertThat(post63pre67.build.getQualifiedVersion(), equalTo(post63Pre67Version.toString()));
assertThat(post67pre70.build.getQualifiedVersion(), equalTo(post67Pre70Version.toString()));
assertThat(post70.build.getQualifiedVersion(), equalTo(dockerBuild.build.getQualifiedVersion()));
}
Expand Down
36 changes: 18 additions & 18 deletions server/src/test/java/org/elasticsearch/VersionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
import java.util.Map;
import java.util.Set;

import static org.elasticsearch.Version.V_6_3_0;
import static org.elasticsearch.Version.V_7_0_0;
import static org.elasticsearch.test.VersionUtils.allVersions;
import static org.elasticsearch.test.VersionUtils.randomVersion;
import static org.hamcrest.CoreMatchers.equalTo;
Expand All @@ -50,30 +48,32 @@
public class VersionTests extends ESTestCase {

public void testVersionComparison() throws Exception {
assertThat(V_6_3_0.before(V_7_0_0), is(true));
assertThat(V_6_3_0.before(V_6_3_0), is(false));
assertThat(V_7_0_0.before(V_6_3_0), is(false));
Version V_7_2_0 = Version.fromString("7.2.0");
Version V_8_0_0 = Version.fromString("8.0.0");
assertThat(V_7_2_0.before(V_8_0_0), is(true));
assertThat(V_7_2_0.before(V_7_2_0), is(false));
assertThat(V_8_0_0.before(V_7_2_0), is(false));

assertThat(V_6_3_0.onOrBefore(V_7_0_0), is(true));
assertThat(V_6_3_0.onOrBefore(V_6_3_0), is(true));
assertThat(V_7_0_0.onOrBefore(V_6_3_0), is(false));
assertThat(V_7_2_0.onOrBefore(V_8_0_0), is(true));
assertThat(V_7_2_0.onOrBefore(V_7_2_0), is(true));
assertThat(V_8_0_0.onOrBefore(V_7_2_0), is(false));

assertThat(V_6_3_0.after(V_7_0_0), is(false));
assertThat(V_6_3_0.after(V_6_3_0), is(false));
assertThat(V_7_0_0.after(V_6_3_0), is(true));
assertThat(V_7_2_0.after(V_8_0_0), is(false));
assertThat(V_7_2_0.after(V_7_2_0), is(false));
assertThat(V_8_0_0.after(V_7_2_0), is(true));

assertThat(V_6_3_0.onOrAfter(V_7_0_0), is(false));
assertThat(V_6_3_0.onOrAfter(V_6_3_0), is(true));
assertThat(V_7_0_0.onOrAfter(V_6_3_0), is(true));
assertThat(V_7_2_0.onOrAfter(V_8_0_0), is(false));
assertThat(V_7_2_0.onOrAfter(V_7_2_0), is(true));
assertThat(V_8_0_0.onOrAfter(V_7_2_0), is(true));

assertTrue(Version.fromString("5.0.0-alpha2").onOrAfter(Version.fromString("5.0.0-alpha1")));
assertTrue(Version.fromString("5.0.0").onOrAfter(Version.fromString("5.0.0-beta2")));
assertTrue(Version.fromString("5.0.0-rc1").onOrAfter(Version.fromString("5.0.0-beta24")));
assertTrue(Version.fromString("5.0.0-alpha24").before(Version.fromString("5.0.0-beta0")));

assertThat(V_6_3_0, is(lessThan(V_7_0_0)));
assertThat(V_6_3_0.compareTo(V_6_3_0), is(0));
assertThat(V_7_0_0, is(greaterThan(V_6_3_0)));
assertThat(V_7_2_0, is(lessThan(V_8_0_0)));
assertThat(V_7_2_0.compareTo(V_7_2_0), is(0));
assertThat(V_8_0_0, is(greaterThan(V_7_2_0)));
}

public void testMin() {
Expand Down Expand Up @@ -182,7 +182,7 @@ public void testMinCompatVersion() {

Version major56x = Version.fromString("5.6.0");
assertThat(Version.V_6_5_0.minimumCompatibilityVersion(), equalTo(major56x));
assertThat(Version.V_6_3_1.minimumCompatibilityVersion(), equalTo(major56x));
assertThat(Version.fromString("6.3.1").minimumCompatibilityVersion(), equalTo(major56x));

// from 7.0 on we are supporting the latest minor of the previous major... this might fail once we add a new version ie. 5.x is
// released since we need to bump the supported minor in Version#minimumCompatibilityVersion()
Expand Down
Loading

0 comments on commit a4e102d

Please sign in to comment.