Skip to content

Commit

Permalink
Remove LegacyESVersion.V_6_7_x constants (opensearch-project#1807)
Browse files Browse the repository at this point in the history
This commit removes all usages of the `LegacyESVersion.V_6_7_x` constants from the codebase.

Signed-off-by: Rabi Panda <adnapibar@gmail.com>
  • Loading branch information
adnapibar authored Jan 2, 2022
1 parent 5ccb22f commit 06cbc47
Show file tree
Hide file tree
Showing 28 changed files with 57 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
package org.opensearch.index.reindex;

import org.apache.logging.log4j.Logger;
import org.opensearch.LegacyESVersion;
import org.opensearch.action.ActionListener;
import org.opensearch.action.index.IndexRequest;
import org.opensearch.action.support.ActionFilters;
Expand Down Expand Up @@ -113,8 +112,6 @@ protected void doExecute(Task task, UpdateByQueryRequest request, ActionListener
*/
static class AsyncIndexBySearchAction extends AbstractAsyncBulkByScrollAction<UpdateByQueryRequest, TransportUpdateByQueryAction> {

private final boolean useSeqNoForCAS;

AsyncIndexBySearchAction(
BulkByScrollTask task,
Logger logger,
Expand All @@ -125,21 +122,7 @@ static class AsyncIndexBySearchAction extends AbstractAsyncBulkByScrollAction<Up
ClusterState clusterState,
ActionListener<BulkByScrollResponse> listener
) {
super(
task,
// not all nodes support sequence number powered optimistic concurrency control, we fall back to version
clusterState.nodes().getMinNodeVersion().onOrAfter(LegacyESVersion.V_6_7_0) == false,
// all nodes support sequence number powered optimistic concurrency control and we can use it
clusterState.nodes().getMinNodeVersion().onOrAfter(LegacyESVersion.V_6_7_0),
logger,
client,
threadPool,
request,
listener,
scriptService,
null
);
useSeqNoForCAS = clusterState.nodes().getMinNodeVersion().onOrAfter(LegacyESVersion.V_6_7_0);
super(task, false, true, logger, client, threadPool, request, listener, scriptService, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.opensearch.common.xcontent.support.XContentMapValues;
import org.opensearch.index.IndexSettings;
import org.opensearch.rest.action.document.RestBulkAction;
import org.opensearch.rest.action.document.RestGetAction;
import org.opensearch.rest.action.document.RestIndexAction;
import org.opensearch.rest.action.document.RestUpdateAction;
import org.opensearch.rest.action.search.RestExplainAction;
Expand Down Expand Up @@ -109,7 +108,7 @@ public void setIndex() {

@Before
public void setType() {
type = getOldClusterVersion().before(LegacyESVersion.V_6_7_0) ? "doc" : "_doc";
type = "_doc";
}

public void testSearch() throws Exception {
Expand Down Expand Up @@ -633,9 +632,6 @@ void assertRealtimeGetWorks(final String typeName) throws IOException {
client().performRequest(updateRequest);

Request getRequest = new Request("GET", "/" + index + "/" + typeName + "/" + docId);
if (getOldClusterVersion().before(LegacyESVersion.V_6_7_0)) {
getRequest.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE));
}
Map<String, Object> getRsp = entityAsMap(client().performRequest(getRequest));
Map<?, ?> source = (Map<?, ?>) getRsp.get("_source");
assertTrue("doc does not contain 'foo' key: " + source, source.containsKey("foo"));
Expand Down Expand Up @@ -682,9 +678,6 @@ public void testSingleDoc() throws IOException {


Request request = new Request("GET", docLocation);
if (getOldClusterVersion().before(LegacyESVersion.V_6_7_0)) {
request.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE));
}
assertThat(toStr(client().performRequest(request)), containsString(doc));
}

Expand Down Expand Up @@ -1269,9 +1262,6 @@ private void saveInfoDocument(String type, String value) throws IOException {
private String loadInfoDocument(String type) throws IOException {
Request request = new Request("GET", "/info/" + this.type + "/" + index + "_" + type);
request.addParameter("filter_path", "_source");
if (getOldClusterVersion().before(LegacyESVersion.V_6_7_0)) {
request.setOptions(expectWarnings(RestGetAction.TYPES_DEPRECATION_MESSAGE));
}
String doc = toStr(client().performRequest(request));
Matcher m = Pattern.compile("\"value\":\"(.+)\"").matcher(doc);
assertTrue(doc, m.find());
Expand Down Expand Up @@ -1352,9 +1342,7 @@ public void testOperationBasedRecovery() throws Exception {
final Settings.Builder settings = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1);
if (getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
}
settings.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), randomBoolean());
createIndex(index, settings.build());
ensureGreen(index);
int committedDocs = randomIntBetween(100, 200);
Expand Down Expand Up @@ -1383,7 +1371,6 @@ public void testOperationBasedRecovery() throws Exception {
* Verifies that once all shard copies on the new version, we should turn off the translog retention for indices with soft-deletes.
*/
public void testTurnOffTranslogRetentionAfterUpgraded() throws Exception {
assumeTrue("requires soft-deletes and retention leases", getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_7_0));
if (isRunningAgainstOldCluster()) {
createIndex(index, Settings.builder()
.put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1)
Expand Down Expand Up @@ -1484,7 +1471,7 @@ public void testSystemIndexMetadataIsUpgraded() throws Exception {
// make sure .tasks index exists
Request getTasksIndex = new Request("GET", "/.tasks");
getTasksIndex.addParameter("allow_no_indices", "false");
if (getOldClusterVersion().onOrAfter(LegacyESVersion.V_6_7_0) && getOldClusterVersion().before(LegacyESVersion.V_7_0_0)) {
if (getOldClusterVersion().before(LegacyESVersion.V_7_0_0)) {
getTasksIndex.addParameter("include_type_name", "false");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setIndex() {

@Before
public void setType() {
type = getOldClusterVersion().before(LegacyESVersion.V_6_7_0) ? "doc" : "_doc";
type = "_doc";
}

public void testEmptyIndex() throws Exception {
Expand Down
7 changes: 1 addition & 6 deletions server/src/main/java/org/opensearch/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,7 @@ public static void writeBuild(Build build, StreamOutput out) throws IOException
if (out.getVersion().before(Version.V_2_0_0)) {
out.writeString("oss");
}
final Type buildType;
if (out.getVersion().before(LegacyESVersion.V_6_7_0) && build.type() == Type.DOCKER) {
buildType = Type.TAR;
} else {
buildType = build.type();
}
final Type buildType = build.type();
out.writeString(buildType.displayName());
out.writeString(build.hash());
out.writeString(build.date());
Expand Down
3 changes: 0 additions & 3 deletions server/src/main/java/org/opensearch/LegacyESVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
*/
public class LegacyESVersion extends Version {

public static final LegacyESVersion V_6_7_0 = new LegacyESVersion(6070099, org.apache.lucene.util.Version.LUCENE_7_7_0);
public static final LegacyESVersion V_6_7_1 = new LegacyESVersion(6070199, org.apache.lucene.util.Version.LUCENE_7_7_0);
public static final LegacyESVersion V_6_7_2 = new LegacyESVersion(6070299, org.apache.lucene.util.Version.LUCENE_7_7_0);
public static final LegacyESVersion V_6_8_0 = new LegacyESVersion(6080099, org.apache.lucene.util.Version.LUCENE_7_7_0);
public static final LegacyESVersion V_6_8_1 = new LegacyESVersion(6080199, org.apache.lucene.util.Version.LUCENE_7_7_0);
public static final LegacyESVersion V_6_8_2 = new LegacyESVersion(6080299, org.apache.lucene.util.Version.LUCENE_7_7_0);
Expand Down
8 changes: 4 additions & 4 deletions server/src/main/java/org/opensearch/OpenSearchException.java
Original file line number Diff line number Diff line change
Expand Up @@ -1537,25 +1537,25 @@ private enum OpenSearchExceptionHandle {
org.opensearch.snapshots.SnapshotInProgressException.class,
org.opensearch.snapshots.SnapshotInProgressException::new,
151,
LegacyESVersion.V_6_7_0
UNKNOWN_VERSION_ADDED
),
NO_SUCH_REMOTE_CLUSTER_EXCEPTION(
org.opensearch.transport.NoSuchRemoteClusterException.class,
org.opensearch.transport.NoSuchRemoteClusterException::new,
152,
LegacyESVersion.V_6_7_0
UNKNOWN_VERSION_ADDED
),
RETENTION_LEASE_ALREADY_EXISTS_EXCEPTION(
org.opensearch.index.seqno.RetentionLeaseAlreadyExistsException.class,
org.opensearch.index.seqno.RetentionLeaseAlreadyExistsException::new,
153,
LegacyESVersion.V_6_7_0
UNKNOWN_VERSION_ADDED
),
RETENTION_LEASE_NOT_FOUND_EXCEPTION(
org.opensearch.index.seqno.RetentionLeaseNotFoundException.class,
org.opensearch.index.seqno.RetentionLeaseNotFoundException::new,
154,
LegacyESVersion.V_6_7_0
UNKNOWN_VERSION_ADDED
),
SHARD_NOT_IN_PRIMARY_MODE_EXCEPTION(
org.opensearch.index.shard.ShardNotInPrimaryModeException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ public PutMappingRequest(StreamInput in) throws IOException {
in.readBoolean(); // updateAllTypes
}
concreteIndex = in.readOptionalWriteable(Index::new);
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
origin = in.readOptionalString();
} else {
origin = null;
}
origin = in.readOptionalString();
if (in.getVersion().onOrAfter(LegacyESVersion.V_7_9_0)) {
writeIndexOnly = in.readBoolean();
}
Expand Down Expand Up @@ -376,9 +372,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(true); // updateAllTypes
}
out.writeOptionalWriteable(concreteIndex);
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
out.writeOptionalString(origin);
}
out.writeOptionalString(origin);
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_9_0)) {
out.writeBoolean(writeIndexOnly);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

package org.opensearch.action.admin.indices.stats;

import org.opensearch.LegacyESVersion;
import org.opensearch.cluster.routing.ShardRouting;
import org.opensearch.common.Nullable;
import org.opensearch.common.io.stream.StreamInput;
Expand Down Expand Up @@ -80,9 +79,7 @@ public ShardStats(StreamInput in) throws IOException {
dataPath = in.readString();
isCustomDataPath = in.readBoolean();
seqNoStats = in.readOptionalWriteable(SeqNoStats::new);
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
retentionLeaseStats = in.readOptionalWriteable(RetentionLeaseStats::new);
}
retentionLeaseStats = in.readOptionalWriteable(RetentionLeaseStats::new);
}

public ShardStats(
Expand Down Expand Up @@ -145,9 +142,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(dataPath);
out.writeBoolean(isCustomDataPath);
out.writeOptionalWriteable(seqNoStats);
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
out.writeOptionalWriteable(retentionLeaseStats);
}
out.writeOptionalWriteable(retentionLeaseStats);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,11 @@ public SearchRequest(StreamInput in) throws IOException {
preFilterShardSize = in.readVInt();
}
allowPartialSearchResults = in.readOptionalBoolean();
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
localClusterAlias = in.readOptionalString();
if (localClusterAlias != null) {
absoluteStartMillis = in.readVLong();
finalReduce = in.readBoolean();
} else {
absoluteStartMillis = DEFAULT_ABSOLUTE_START_MILLIS;
finalReduce = true;
}
localClusterAlias = in.readOptionalString();
if (localClusterAlias != null) {
absoluteStartMillis = in.readVLong();
finalReduce = in.readBoolean();
} else {
localClusterAlias = null;
absoluteStartMillis = DEFAULT_ABSOLUTE_START_MILLIS;
finalReduce = true;
}
Expand Down Expand Up @@ -279,12 +273,10 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(preFilterShardSize == null ? DEFAULT_BATCHED_REDUCE_SIZE : preFilterShardSize);
}
out.writeOptionalBoolean(allowPartialSearchResults);
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
out.writeOptionalString(localClusterAlias);
if (localClusterAlias != null) {
out.writeVLong(absoluteStartMillis);
out.writeBoolean(finalReduce);
}
out.writeOptionalString(localClusterAlias);
if (localClusterAlias != null) {
out.writeVLong(absoluteStartMillis);
out.writeBoolean(finalReduce);
}
if (out.getVersion().onOrAfter(LegacyESVersion.V_7_0_0)) {
out.writeBoolean(ccsMinimizeRoundtrips);
Expand Down
13 changes: 4 additions & 9 deletions server/src/main/java/org/opensearch/cluster/ClusterState.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import com.carrotsearch.hppc.cursors.ObjectCursor;
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import org.opensearch.LegacyESVersion;
import org.opensearch.cluster.block.ClusterBlock;
import org.opensearch.cluster.block.ClusterBlocks;
import org.opensearch.cluster.coordination.CoordinationMetadata;
Expand Down Expand Up @@ -736,7 +735,7 @@ public static ClusterState readFrom(StreamInput in, DiscoveryNode localNode) thr
Custom customIndexMetadata = in.readNamedWriteable(Custom.class);
builder.putCustom(customIndexMetadata.getWriteableName(), customIndexMetadata);
}
builder.minimumMasterNodesOnPublishingMaster = in.getVersion().onOrAfter(LegacyESVersion.V_6_7_0) ? in.readVInt() : -1;
builder.minimumMasterNodesOnPublishingMaster = in.readVInt();
return builder.build();
}

Expand All @@ -762,9 +761,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeNamedWriteable(cursor.value);
}
}
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
out.writeVInt(minimumMasterNodesOnPublishingMaster);
}
out.writeVInt(minimumMasterNodesOnPublishingMaster);
}

private static class ClusterStateDiff implements Diff<ClusterState> {
Expand Down Expand Up @@ -812,7 +809,7 @@ private static class ClusterStateDiff implements Diff<ClusterState> {
metadata = Metadata.readDiffFrom(in);
blocks = ClusterBlocks.readDiffFrom(in);
customs = DiffableUtils.readImmutableOpenMapDiff(in, DiffableUtils.getStringKeySerializer(), CUSTOM_VALUE_SERIALIZER);
minimumMasterNodesOnPublishingMaster = in.getVersion().onOrAfter(LegacyESVersion.V_6_7_0) ? in.readVInt() : -1;
minimumMasterNodesOnPublishingMaster = in.readVInt();
}

@Override
Expand All @@ -826,9 +823,7 @@ public void writeTo(StreamOutput out) throws IOException {
metadata.writeTo(out);
blocks.writeTo(out);
customs.writeTo(out);
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
out.writeVInt(minimumMasterNodesOnPublishingMaster);
}
out.writeVInt(minimumMasterNodesOnPublishingMaster);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.opensearch.LegacyESVersion;
import org.opensearch.OpenSearchException;
import org.opensearch.ExceptionsHelper;
import org.opensearch.action.ActionListener;
Expand Down Expand Up @@ -88,8 +87,6 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import static org.opensearch.index.seqno.SequenceNumbers.UNASSIGNED_PRIMARY_TERM;

public class ShardStateAction {

private static final Logger logger = LogManager.getLogger(ShardStateAction.class);
Expand Down Expand Up @@ -819,11 +816,7 @@ public static class StartedShardEntry extends TransportRequest {
super(in);
shardId = new ShardId(in);
allocationId = in.readString();
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
primaryTerm = in.readVLong();
} else {
primaryTerm = UNASSIGNED_PRIMARY_TERM;
}
primaryTerm = in.readVLong();
this.message = in.readString();
}

Expand All @@ -839,9 +832,7 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
shardId.writeTo(out);
out.writeString(allocationId);
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
out.writeVLong(primaryTerm);
}
out.writeVLong(primaryTerm);
out.writeString(message);
}

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

package org.opensearch.cluster.block;

import org.opensearch.LegacyESVersion;
import org.opensearch.common.Nullable;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
Expand Down Expand Up @@ -60,11 +59,7 @@ public class ClusterBlock implements Writeable, ToXContentFragment {

public ClusterBlock(StreamInput in) throws IOException {
id = in.readVInt();
if (in.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
uuid = in.readOptionalString();
} else {
uuid = null;
}
uuid = in.readOptionalString();
description = in.readString();
this.levels = in.readEnumSet(ClusterBlockLevel.class);
retryable = in.readBoolean();
Expand Down Expand Up @@ -173,9 +168,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(id);
if (out.getVersion().onOrAfter(LegacyESVersion.V_6_7_0)) {
out.writeOptionalString(uuid);
}
out.writeOptionalString(uuid);
out.writeString(description);
out.writeEnumSet(levels);
out.writeBoolean(retryable);
Expand Down
Loading

0 comments on commit 06cbc47

Please sign in to comment.