Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove several uses of 6.x version constants #41162

Merged
merged 3 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentHelper;
Expand Down Expand Up @@ -90,8 +89,6 @@
import java.util.Objects;
import java.util.function.Supplier;

import static org.elasticsearch.percolator.PercolatorFieldMapper.parseQuery;

public class PercolateQueryBuilder extends AbstractQueryBuilder<PercolateQueryBuilder> {
public static final String NAME = "percolate";

Expand Down Expand Up @@ -247,14 +244,8 @@ public PercolateQueryBuilder(String field, String documentType, String indexedDo
PercolateQueryBuilder(StreamInput in) throws IOException {
super(in);
field = in.readString();
if (in.getVersion().onOrAfter(Version.V_6_1_0)) {
name = in.readOptionalString();
}
if (in.getVersion().before(Version.V_6_0_0_beta1)) {
documentType = in.readString();
} else {
documentType = in.readOptionalString();
}
name = in.readOptionalString();
documentType = in.readOptionalString();
indexedDocumentIndex = in.readOptionalString();
indexedDocumentType = in.readOptionalString();
indexedDocumentId = in.readOptionalString();
Expand All @@ -265,12 +256,7 @@ public PercolateQueryBuilder(String field, String documentType, String indexedDo
} else {
indexedDocumentVersion = null;
}
if (in.getVersion().onOrAfter(Version.V_6_1_0)) {
documents = in.readList(StreamInput::readBytesReference);
} else {
BytesReference document = in.readOptionalBytesReference();
documents = document != null ? Collections.singletonList(document) : Collections.emptyList();
}
documents = in.readList(StreamInput::readBytesReference);
if (documents.isEmpty() == false) {
documentXContentType = in.readEnum(XContentType.class);
} else {
Expand All @@ -294,14 +280,8 @@ protected void doWriteTo(StreamOutput out) throws IOException {
throw new IllegalStateException("supplier must be null, can't serialize suppliers, missing a rewriteAndFetch?");
}
out.writeString(field);
if (out.getVersion().onOrAfter(Version.V_6_1_0)) {
out.writeOptionalString(name);
}
if (out.getVersion().before(Version.V_6_0_0_beta1)) {
out.writeString(documentType);
} else {
out.writeOptionalString(documentType);
}
out.writeOptionalString(name);
out.writeOptionalString(documentType);
out.writeOptionalString(indexedDocumentIndex);
out.writeOptionalString(indexedDocumentType);
out.writeOptionalString(indexedDocumentId);
Expand Down Expand Up @@ -685,50 +665,30 @@ static PercolateQuery.QueryStore createStore(MappedFieldType queryBuilderFieldTy
if (binaryDocValues == null) {
return docId -> null;
}
if (indexVersion.onOrAfter(Version.V_6_0_0_beta2)) {
return docId -> {
if (binaryDocValues.advanceExact(docId)) {
BytesRef qbSource = binaryDocValues.binaryValue();
try (InputStream in = new ByteArrayInputStream(qbSource.bytes, qbSource.offset, qbSource.length)) {
try (StreamInput input = new NamedWriteableAwareStreamInput(
new InputStreamStreamInput(in, qbSource.length), registry)) {
input.setVersion(indexVersion);
// Query builder's content is stored via BinaryFieldMapper, which has a custom encoding
// to encode multiple binary values into a single binary doc values field.
// This is the reason we need to first need to read the number of values and
// then the length of the field value in bytes.
int numValues = input.readVInt();
assert numValues == 1;
int valueLength = input.readVInt();
assert valueLength > 0;
QueryBuilder queryBuilder = input.readNamedWriteable(QueryBuilder.class);
assert in.read() == -1;
return PercolatorFieldMapper.toQuery(context, mapUnmappedFieldsAsString, queryBuilder);
}
return docId -> {
if (binaryDocValues.advanceExact(docId)) {
BytesRef qbSource = binaryDocValues.binaryValue();
try (InputStream in = new ByteArrayInputStream(qbSource.bytes, qbSource.offset, qbSource.length)) {
try (StreamInput input = new NamedWriteableAwareStreamInput(
new InputStreamStreamInput(in, qbSource.length), registry)) {
input.setVersion(indexVersion);
// Query builder's content is stored via BinaryFieldMapper, which has a custom encoding
// to encode multiple binary values into a single binary doc values field.
// This is the reason we need to first need to read the number of values and
// then the length of the field value in bytes.
int numValues = input.readVInt();
assert numValues == 1;
int valueLength = input.readVInt();
assert valueLength > 0;
QueryBuilder queryBuilder = input.readNamedWriteable(QueryBuilder.class);
assert in.read() == -1;
return PercolatorFieldMapper.toQuery(context, mapUnmappedFieldsAsString, queryBuilder);
}
} else {
return null;
}
};
} else {
return docId -> {
if (binaryDocValues.advanceExact(docId)) {
BytesRef qbSource = binaryDocValues.binaryValue();
if (qbSource.length > 0) {
XContent xContent = PercolatorFieldMapper.QUERY_BUILDER_CONTENT_TYPE.xContent();
try (XContentParser sourceParser = xContent
.createParser(context.getXContentRegistry(), LoggingDeprecationHandler.INSTANCE,
qbSource.bytes, qbSource.offset, qbSource.length)) {
return parseQuery(context, mapUnmappedFieldsAsString, sourceParser);
}
} else {
return null;
}
} else {
return null;
}
};
}
} else {
return null;
}
};
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
Expand Down Expand Up @@ -84,7 +82,6 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -423,21 +420,12 @@ public boolean convertNowRangeToMatchAll() {

static void createQueryBuilderField(Version indexVersion, BinaryFieldMapper qbField,
QueryBuilder queryBuilder, ParseContext context) throws IOException {
if (indexVersion.onOrAfter(Version.V_6_0_0_beta2)) {
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
try (OutputStreamStreamOutput out = new OutputStreamStreamOutput(stream)) {
out.setVersion(indexVersion);
out.writeNamedWriteable(queryBuilder);
byte[] queryBuilderAsBytes = stream.toByteArray();
qbField.parse(context.createExternalValueContext(queryBuilderAsBytes));
}
}
} else {
try (XContentBuilder builder = XContentFactory.contentBuilder(QUERY_BUILDER_CONTENT_TYPE)) {
queryBuilder.toXContent(builder, new MapParams(Collections.emptyMap()));
builder.flush();
byte[] queryBuilderAsBytes = BytesReference.toBytes(BytesReference.bytes(builder));
context.doc().add(new Field(qbField.name(), queryBuilderAsBytes, qbField.fieldType()));
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
try (OutputStreamStreamOutput out = new OutputStreamStreamOutput(stream)) {
out.setVersion(indexVersion);
out.writeNamedWriteable(queryBuilder);
byte[] queryBuilderAsBytes = stream.toByteArray();
qbField.parse(context.createExternalValueContext(queryBuilderAsBytes));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void testStoringQueryBuilders() throws IOException {
BinaryFieldMapper fieldMapper = PercolatorFieldMapper.Builder.createQueryBuilderFieldBuilder(
new Mapper.BuilderContext(settings, new ContentPath(0)));

Version version = Version.V_6_0_0_beta2;
Version version = Version.CURRENT;
try (IndexWriter indexWriter = new IndexWriter(directory, config)) {
for (int i = 0; i < queryBuilders.length; i++) {
queryBuilders[i] = new TermQueryBuilder(randomAlphaOfLength(4), randomAlphaOfLength(8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,7 @@ public void process(Version indexCreatedVersion, @Nullable MappingMetaData mappi
assert ifSeqNo == UNASSIGNED_SEQ_NO;
assert ifPrimaryTerm == UNASSIGNED_PRIMARY_TERM;
autoGeneratedTimestamp = Math.max(0, System.currentTimeMillis()); // extra paranoia
String uid;
if (indexCreatedVersion.onOrAfter(Version.V_6_0_0_beta1)) {
uid = UUIDs.base64UUID();
} else {
uid = UUIDs.legacyBase64UUID();
}
String uid = UUIDs.base64UUID();
id(uid);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,9 @@ public void document(int docID, StoredFieldVisitor visitor) throws IOException {
visitor.stringField(FAKE_ROUTING_FIELD, operation.routing().getBytes(StandardCharsets.UTF_8));
}
if (visitor.needsField(FAKE_ID_FIELD) == StoredFieldVisitor.Status.YES) {
final byte[] id;
if (indexVersionCreated.onOrAfter(Version.V_6_0_0)) {
BytesRef bytesRef = Uid.encodeId(operation.id());
id = new byte[bytesRef.length];
System.arraycopy(bytesRef.bytes, bytesRef.offset, id, 0, bytesRef.length);
} else { // TODO this can go away in 7.0 after backport
id = operation.id().getBytes(StandardCharsets.UTF_8);
}
BytesRef bytesRef = Uid.encodeId(operation.id());
final byte[] id = new byte[bytesRef.length];
System.arraycopy(bytesRef.bytes, bytesRef.offset, id, 0, bytesRef.length);
visitor.stringField(FAKE_ID_FIELD, id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,8 @@ public void recoverToTarget(ActionListener<RecoveryResponse> listener) {

private boolean isTargetSameHistory() {
final String targetHistoryUUID = request.metadataSnapshot().getHistoryUUID();
assert targetHistoryUUID != null || shard.indexSettings().getIndexVersionCreated().before(Version.V_6_0_0_rc1) :
"incoming target history N/A but index was created after or on 6.0.0-rc1";
return targetHistoryUUID != null && targetHistoryUUID.equals(shard.getHistoryUUID());
assert targetHistoryUUID != null : "incoming target history missing";
return targetHistoryUUID.equals(shard.getHistoryUUID());
}

static void runUnderPrimaryPermit(CancellableThreads.Interruptible runnable, String reason,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,6 @@ public void cleanFiles(int totalTranslogOps, long globalCheckpoint, Store.Metada
store.incRef();
try {
store.cleanupAndVerify("recovery CleanFilesRequestHandler", sourceMetaData);
if (indexShard.indexSettings().getIndexVersionCreated().before(Version.V_6_0_0_rc1)) {
store.ensureIndexHasHistoryUUID();
}
assert globalCheckpoint >= Long.parseLong(sourceMetaData.getCommitUserData().get(SequenceNumbers.MAX_SEQ_NO))
|| indexShard.indexSettings().getIndexVersionCreated().before(Version.V_7_1_0) :
"invalid global checkpoint[" + globalCheckpoint + "] source_meta_data [" + sourceMetaData.getCommitUserData() + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ public static PluginInfo readFromProperties(final Path path) throws IOException
}
}

if (esVersion.before(Version.V_6_3_0) && esVersion.onOrAfter(Version.V_6_0_0_beta2)) {
propsMap.remove("requires.keystore");
}

if (propsMap.isEmpty() == false) {
throw new IllegalArgumentException("Unknown properties in plugin descriptor: " + propsMap.keySet());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ public void testElasticsearchRemoteException() throws IOException {
public void testShardLockObtainFailedException() throws IOException {
ShardId shardId = new ShardId("foo", "_na_", 1);
ShardLockObtainFailedException orig = new ShardLockObtainFailedException(shardId, "boom");
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT);
Version version = VersionUtils.randomIndexCompatibleVersion(random());
ShardLockObtainFailedException ex = serialize(orig, version);
assertEquals(orig.getMessage(), ex.getMessage());
assertEquals(orig.getShardId(), ex.getShardId());
Expand Down
5 changes: 2 additions & 3 deletions server/src/test/java/org/elasticsearch/VersionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ public void testMax() {
}

public void testMinimumIndexCompatibilityVersion() {
assertEquals(Version.fromId(5000099), Version.V_6_0_0_beta1.minimumIndexCompatibilityVersion());
assertEquals(Version.fromId(2000099), Version.fromId(5000099).minimumIndexCompatibilityVersion());
assertEquals(Version.fromId(5000099), Version.fromId(6000099).minimumIndexCompatibilityVersion());
assertEquals(Version.fromId(2000099),
Version.fromId(5010000).minimumIndexCompatibilityVersion());
assertEquals(Version.fromId(2000099),
Expand Down Expand Up @@ -161,7 +160,7 @@ public void testVersionNoPresentInSettings() {

public void testIndexCreatedVersion() {
// an actual index has a IndexMetaData.SETTING_INDEX_UUID
final Version version = Version.V_6_0_0_beta1;
final Version version = VersionUtils.randomVersion(random());
assertEquals(version, Version.indexCreated(
Settings.builder()
.put(IndexMetaData.SETTING_INDEX_UUID, "foo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testSerialization() throws Exception {
request.routing(routings);
}

Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT);
Version version = VersionUtils.randomIndexCompatibleVersion(random());
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
request.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void testSerialization() throws Exception {
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
entries.addAll(searchModule.getNamedWriteables());
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries);
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT);
Version version = VersionUtils.randomIndexCompatibleVersion(random());
try(BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(version);
clusterSearchShardsResponse.writeTo(out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void testParse3DPolygon() throws IOException {
shellCoordinates.add(new Coordinate(100, 0, 10));
Coordinate[] coordinates = shellCoordinates.toArray(new Coordinate[shellCoordinates.size()]);

Version randomVersion = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT);
Version randomVersion = VersionUtils.randomIndexCompatibleVersion(random());
Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, randomVersion)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ protected boolean forbidPrivateIndexSettings() {
}

public void testExternalValues() throws Exception {
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0,
Version.CURRENT);
Version version = VersionUtils.randomIndexCompatibleVersion(random());
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build();
IndexService indexService = createIndex("test", settings);
MapperRegistry mapperRegistry = new MapperRegistry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected MappedFieldType createDefaultFieldType() {

public void testTermsQuery() throws Exception {
QueryShardContext context = Mockito.mock(QueryShardContext.class);
Version indexVersionCreated = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT);
Version indexVersionCreated = VersionUtils.randomIndexCompatibleVersion(random());
Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public void testStatsByShardDoesNotDieFromExpectedExceptions() {

public void testIsMetaDataField() {
IndicesService indicesService = getIndicesService();
final Version randVersion = VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT);
final Version randVersion = VersionUtils.randomIndexCompatibleVersion(random());
assertFalse(indicesService.isMetaDataField(randVersion, randomAlphaOfLengthBetween(10, 15)));
for (String builtIn : IndicesModule.getBuiltInMetaDataFields()) {
assertTrue(indicesService.isMetaDataField(randVersion, builtIn));
Expand Down
Loading