Skip to content

Commit

Permalink
remove 6.3.x constants (#42087)
Browse files Browse the repository at this point in the history
relates to refactoring effort #41164.
  • Loading branch information
talevy authored May 24, 2019
1 parent cbf1150 commit da1ba68
Show file tree
Hide file tree
Showing 46 changed files with 110 additions and 841 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ 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 = Version.fromString("6.3.0");

private Date timestamp;
private String description;
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
35 changes: 8 additions & 27 deletions server/src/main/java/org/elasticsearch/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,45 +224,26 @@ 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();

final String version;
if (in.getVersion().onOrAfter(Version.V_7_0_0)) {
version = in.readString();
} else {
version = in.getVersion().toString();
}
version = in.readString();
return new Build(flavor, type, hash, date, snapshot, version);
}

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 = build.type();
out.writeString(buildType.displayName());
}
out.writeString(build.flavor().displayName());
out.writeString(build.type().displayName());
out.writeString(build.shortHash());
out.writeString(build.date());
out.writeBoolean(build.isSnapshot());
if (out.getVersion().onOrAfter(Version.V_7_0_0)) {
out.writeString(build.getQualifiedVersion());
}
out.writeString(build.getQualifiedVersion());
}

/**
Expand Down
14 changes: 0 additions & 14 deletions server/src/main/java/org/elasticsearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ public class Version implements Comparable<Version>, ToXContentFragment {
*/
public static final int V_EMPTY_ID = 0;
public static final Version V_EMPTY = new Version(V_EMPTY_ID, org.apache.lucene.util.Version.LATEST);
// The below version is missing from the 7.3 JAR
private static final org.apache.lucene.util.Version LUCENE_7_2_1 = org.apache.lucene.util.Version.fromBits(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 @@ -152,12 +144,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_EMPTY_ID:
return V_EMPTY;
default:
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 @@ -22,7 +22,6 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.StepListener;
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
Expand Down Expand Up @@ -594,28 +593,20 @@ static final class PreSyncedFlushResponse extends TransportResponse {
this.existingSyncId = existingSyncId;
}

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

@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
commitId = new Engine.CommitId(in);
numDocs = in.readInt();
if (includeExistingSyncId(in.getVersion())) {
existingSyncId = in.readOptionalString();
}
existingSyncId = in.readOptionalString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
commitId.writeTo(out);
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 Down Expand Up @@ -249,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
2 changes: 1 addition & 1 deletion server/src/test/java/org/elasticsearch/BuildTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void testSerialization() {
throw new AssertionError();
});
}

public void testFlavorParsing() {
for (final Build.Flavor flavor : Build.Flavor.values()) {
// strict or not should not impact parsing at all here
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils;

import java.util.Locale;

Expand Down Expand Up @@ -59,7 +60,7 @@ public void testBwcSerialization() throws Exception {
for (int runs = 0; runs < randomIntBetween(5, 20); runs++) {
// Generate a random cluster health request in version < 7.2.0 and serializes it
final BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(randomVersionBetween(random(), Version.V_6_3_0, getPreviousVersion(Version.V_7_2_0)));
out.setVersion(randomVersionBetween(random(), VersionUtils.getFirstVersion(), getPreviousVersion(Version.V_7_2_0)));

final ClusterHealthRequest expected = randomRequest();
{
Expand Down Expand Up @@ -114,7 +115,7 @@ public void testBwcSerialization() throws Exception {

// Serialize to node in version < 7.2.0
final BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(randomVersionBetween(random(), Version.V_6_3_0, getPreviousVersion(Version.V_7_2_0)));
out.setVersion(randomVersionBetween(random(), VersionUtils.getFirstVersion(), getPreviousVersion(Version.V_7_2_0)));
expected.writeTo(out);

// Deserialize and check the cluster health request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public void testParseMixedDimensionPolyWithHoleStoredZ() throws IOException {
parser.nextToken();

Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_6_3_0)
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
Expand Down Expand Up @@ -372,7 +372,7 @@ public void testParsePolyWithStoredZ() throws IOException {
parser.nextToken();

Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_6_3_0)
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
Expand All @@ -393,7 +393,7 @@ public void testParseOpenPolygon() throws IOException {
parser.nextToken();

Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_6_3_0)
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
Expand Down
Loading

0 comments on commit da1ba68

Please sign in to comment.