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

[Version] Increment main to 2.0 #1192

Merged
merged 5 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion buildSrc/src/main/java/org/opensearch/gradle/BwcVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,17 @@ public List<Version> getIndexCompatible() {
if (currentMajor == 1) {
// add 6.x compatible for OpenSearch 1.0.0
return unmodifiableList(Stream.concat(groupByMajor.get(prevMajor - 1).stream(), result.stream()).collect(Collectors.toList()));
} else if (currentMajor == 2) {
// add 7.x compatible for OpenSearch 2.0.0
return unmodifiableList(Stream.concat(groupByMajor.get(7).stream(), result.stream()).collect(Collectors.toList()));
}
return unmodifiableList(result);
}

public List<Version> getWireCompatible() {
List<Version> wireCompat = new ArrayList<>();
int currentMajor = currentVersion.getMajor();
int lastMajor = currentMajor == 1 ? 6 : currentMajor - 1;
int lastMajor = currentMajor == 1 ? 6 : currentMajor == 2 ? 7 : currentMajor - 1;
List<Version> lastMajorList = groupByMajor.get(lastMajor);
if (lastMajorList == null) {
throw new IllegalStateException("Expected to find a list of versions for version: " + lastMajor);
Expand All @@ -402,7 +405,14 @@ public List<Version> getWireCompatible() {
for (Version v : previousMajor) {
wireCompat.add(v);
}
} else if (currentMajor == 2) {
// add all of the 1.x line:
List<Version> previousMajor = groupByMajor.get(1);
for (Version v : previousMajor) {
wireCompat.add(v);
}
}

wireCompat.addAll(groupByMajor.get(currentMajor));
wireCompat.remove(currentVersion);
wireCompat.sort(Version::compareTo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Version(int major, int minor, int revision) {
// currently snapshot is not taken into account
int id = major * 10000000 + minor * 100000 + revision * 1000;
// identify if new OpenSearch version 1
this.id = major == 1 ? id ^ MASK : id;
this.id = major == 1 || major == 2 ? id ^ MASK : id;
}

private static int parseSuffixNumber(String substring) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class BwcOpenSearchVersionsTests extends GradleUnitTestCase {
static {
sampleVersions.put("1.0.0", asList("5_6_13", "6_6_1", "6_8_15", "7_0_0", "7_9_1", "7_10_0", "7_10_1", "7_10_2", "1_0_0"));
sampleVersions.put("1.1.0", asList("5_6_13", "6_6_1", "6_8_15", "7_0_0", "7_9_1", "7_10_0", "7_10_1", "7_10_2", "1_0_0", "1_1_0"));
sampleVersions.put(
"2.0.0",
asList("5_6_13", "6_6_1", "6_8_15", "7_0_0", "7_9_1", "7_10_0", "7_10_1", "7_10_2", "1_0_0", "1_1_0", "2_0_0")
);
}

public void testWireCompatible() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public class DistributionDownloadPluginTests extends GradleUnitTestCase {
private static Project packagesProject;
private static Project bwcProject;

private static final Version BWC_MAJOR_VERSION = Version.fromString("4.0.0");
private static final Version BWC_MINOR_VERSION = Version.fromString("3.1.0");
private static final Version BWC_STAGED_VERSION = Version.fromString("3.0.0");
private static final Version BWC_BUGFIX_VERSION = Version.fromString("3.0.1");
private static final Version BWC_MAINTENANCE_VERSION = Version.fromString("2.90.1");
private static final Version BWC_MAJOR_VERSION = Version.fromString("5.0.0");
private static final Version BWC_MINOR_VERSION = Version.fromString("4.1.0");
private static final Version BWC_STAGED_VERSION = Version.fromString("4.0.0");
private static final Version BWC_BUGFIX_VERSION = Version.fromString("4.0.1");
private static final Version BWC_MAINTENANCE_VERSION = Version.fromString("3.90.1");
private static final BwcVersions BWC_MINOR = new BwcVersions(
new TreeSet<>(Arrays.asList(BWC_BUGFIX_VERSION, BWC_MINOR_VERSION, BWC_MAJOR_VERSION)),
BWC_MAJOR_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testRelaxedVersionParsing() {

public void testCompareWithStringVersions() {
// 1.10.2 is now rebased to OpenSearch version; so this needs to report
assertTrue("OpenSearch 1.10.20 is not interpreted as after Legacy 2.0.0", Version.fromString("1.10.20").after("2.0.0"));
assertTrue("OpenSearch 1.10.20 is not interpreted as after Legacy 3.0.0", Version.fromString("1.10.20").after("3.0.0"));
assertTrue(
"7.0.0-alpha1 should be equal to 7.0.0-alpha1",
Version.fromString("7.0.0-alpha1").equals(Version.fromString("7.0.0-alpha1"))
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/version.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
opensearch = 1.1.0
opensearch = 2.0.0
lucene = 8.9.0

bundled_jdk_vendor = adoptopenjdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,16 @@
import org.opensearch.client.ResponseException;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.common.Booleans;
import org.opensearch.common.Strings;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.rest.action.document.RestBulkAction;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.opensearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;

/**
* Basic test that indexed documents survive the rolling restart. See
Expand Down Expand Up @@ -89,25 +85,6 @@ public void testIndexing() throws IOException {
}

if (CLUSTER_TYPE == ClusterType.OLD) {
{
Version minimumIndexCompatibilityVersion = Version.CURRENT.minimumIndexCompatibilityVersion();
assertThat("this branch is not needed if we aren't compatible with 6.0",
minimumIndexCompatibilityVersion.onOrBefore(LegacyESVersion.V_6_0_0), equalTo(true));
if (minimumIndexCompatibilityVersion.before(LegacyESVersion.V_7_0_0)) {
XContentBuilder template = jsonBuilder();
template.startObject();
{
template.array("index_patterns", "test_index", "index_with_replicas", "empty_index");
template.startObject("settings");
template.field("number_of_shards", 5);
template.endObject();
}
template.endObject();
Request createTemplate = new Request("PUT", "/_template/prevent-bwc-deprecation-template");
createTemplate.setJsonEntity(Strings.toString(template));
client().performRequest(createTemplate);
}
}
Request createTestIndex = new Request("PUT", "/test_index");
createTestIndex.setJsonEntity("{\"settings\": {\"index.number_of_replicas\": 0}}");
useIgnoreMultipleMatchingTemplatesWarningsHandler(createTestIndex);
Expand Down
11 changes: 6 additions & 5 deletions server/src/main/java/org/opensearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public class Version implements Comparable<Version>, ToXContentFragment {
public static final Version V_1_0_0 = new Version(1000099, org.apache.lucene.util.Version.LUCENE_8_8_2);
public static final Version V_1_0_1 = new Version(1000199, org.apache.lucene.util.Version.LUCENE_8_8_2);
public static final Version V_1_1_0 = new Version(1010099, org.apache.lucene.util.Version.LUCENE_8_9_0);
public static final Version CURRENT = V_1_1_0;
public static final Version V_2_0_0 = new Version(2000099, org.apache.lucene.util.Version.LUCENE_8_9_0);
public static final Version CURRENT = V_2_0_0;

public static Version readVersion(StreamInput in) throws IOException {
return fromId(in.readVInt());
Expand Down Expand Up @@ -185,7 +186,7 @@ private static Version fromStringSlow(String version) {
try {
final int rawMajor = Integer.parseInt(parts[0]);
final int betaOffset = 25; // 0 - 24 is taking by alpha builds

//we reverse the version id calculation based on some assumption as we can't reliably reverse the modulo
final int major = rawMajor * 1000000;
final int minor = Integer.parseInt(parts[1]) * 10000;
Expand All @@ -205,7 +206,7 @@ private static Version fromStringSlow(String version) {
throw new IllegalArgumentException("unable to parse version " + version);
}
}

return fromId((major + minor + revision + build) ^ MASK);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("unable to parse version " + version, e);
Expand Down Expand Up @@ -306,11 +307,11 @@ public Version minimumCompatibilityVersion() {
protected Version computeMinCompatVersion() {
if (major == 1) {
return LegacyESVersion.V_6_8_0;
} else if (major == 2) {
return LegacyESVersion.V_7_10_0;
} else if (major == 6) {
// force the minimum compatibility for version 6 to 5.6 since we don't reference version 5 anymore
return Version.fromId(5060099);
} else if (major == 2) {
return LegacyESVersion.V_7_10_0;
} else if (major >= 7) {
// all major versions from 7 onwards are compatible with last minor series of the previous major
Version bwcVersion = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public DiscoveryUpgradeService(Settings settings, TransportService transportServ
BooleanSupplier isBootstrappedSupplier, JoinHelper joinHelper,
Supplier<Iterable<DiscoveryNode>> peersSupplier,
Consumer<VotingConfiguration> initialConfigurationConsumer) {
assert Version.CURRENT.major == 1 : "remove this service once unsafe upgrades are no longer needed";
assert Version.CURRENT.major == 1 || Version.CURRENT.major == 2 : "remove this service once unsafe upgrades are no longer needed";
this.transportService = transportService;
this.isBootstrappedSupplier = isBootstrappedSupplier;
this.joinHelper = joinHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ public static void validateStoreTypeSettings(Settings settings) {

static int getNumberOfShards(final Settings.Builder indexSettingsBuilder) {
// TODO: this logic can be removed when the current major version is 8
assert Version.CURRENT.major == 1;
assert Version.CURRENT.major == 1 || Version.CURRENT.major == 2;
final int numberOfShards;
final Version indexVersionCreated =
Version.fromId(Integer.parseInt(indexSettingsBuilder.get(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ static IllegalStateException ensureVersionCompatibility(Version remoteVersion, V
// handshake. This looks odd but it's required to establish the connection correctly we check for real compatibility
// once the connection is established
final Version compatibilityVersion = isHandshake ? currentVersion.minimumCompatibilityVersion() : currentVersion;
if (remoteVersion.isCompatible(compatibilityVersion) == false) {
if ((currentVersion.equals(Version.V_2_0_0) && remoteVersion.equals(Version.fromId(6079999))) == false
&& remoteVersion.isCompatible(compatibilityVersion) == false) {
final Version minCompatibilityVersion = isHandshake ? compatibilityVersion : compatibilityVersion.minimumCompatibilityVersion();
String msg = "Received " + (isHandshake ? "handshake " : "") + "message from unsupported version: [";
return new IllegalStateException(msg + remoteVersion + "] minimal compatible version is: [" + minCompatibilityVersion + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void sendHandshake(long requestId, DiscoveryNode node, TcpChannel channel, TimeV
// we also have no payload on the request but the response will contain the actual version of the node we talk
// to as the payload.
Version minCompatVersion = version.minimumCompatibilityVersion();
if(version.onOrAfter(Version.V_1_0_0)) {
if(version.onOrAfter(Version.V_1_0_0) && version.before(Version.V_2_0_0)) {
// the minCompatibleVersion for OpenSearch 1.x is sent as 6.7.99 instead of 6.8.0
// as this helps in (indirectly) identifying the remote node version during handle HandshakeRequest itself
// and then send appropriate version (7.10.2/ OpenSearch 1.x version) in response.
Expand All @@ -91,6 +91,8 @@ void sendHandshake(long requestId, DiscoveryNode node, TcpChannel channel, TimeV
// Sending only BC version to ElasticSearch node provide easy deprecation path for this BC version logic
// in OpenSearch 2.0.0.
minCompatVersion = Version.fromId(6079999);
} else if (version.onOrAfter(Version.V_2_0_0)) {
minCompatVersion = Version.fromId(7099999);
}
handshakeRequestSender.sendRequest(node, channel, requestId, minCompatVersion);

Expand Down Expand Up @@ -120,7 +122,7 @@ void handleHandshake(TransportChannel channel, long requestId, StreamInput strea
// 1. if remote node is 7.x, then StreamInput version would be 6.8.0
// 2. if remote node is 6.8 then it would be 5.6.0
// 3. if remote node is OpenSearch 1.x then it would be 6.7.99
if(this.version.onOrAfter(Version.V_1_0_0) &&
if((this.version.onOrAfter(Version.V_1_0_0) && this.version.before(Version.V_2_0_0)) &&
(stream.getVersion().equals(LegacyESVersion.V_6_8_0)
|| stream.getVersion().equals(Version.fromId(5060099)))) {
channel.sendResponse(new HandshakeResponse(LegacyESVersion.V_7_10_2));
Expand Down
4 changes: 2 additions & 2 deletions server/src/test/java/org/opensearch/VersionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public void testIsCompatible() {
}
final Version lastMinorFromPreviousMajor =
VersionUtils
.allVersions()
.allReleasedVersions()
.stream()
.filter(v -> v.major == (currentOrNextMajorVersion.major == 1 ? 7 : currentOrNextMajorVersion.major - 1))
.max(Version::compareTo)
Expand All @@ -464,7 +464,7 @@ public void testIsCompatible() {
Locale.ROOT,
"[%s] should %s be compatible with [%s]",
previousMinorVersion,
isCompatible ? "" : " not",
isCompatible ? "" : "not",
currentOrNextMajorVersion);
assertThat(
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.OptionalInt;

import static org.opensearch.test.VersionUtils.randomVersionBetween;
import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -98,38 +97,6 @@ public void testSerialization() throws Exception {
}
}

public void testSerializationPre70() throws Exception {
int iterations = randomIntBetween(5, 20);
List<Version> declaredVersions = Version.getDeclaredVersions(LegacyESVersion.class);
OptionalInt maxV6Id = declaredVersions.stream().filter(v -> v.major == 6).mapToInt(v -> v.id).max();
assertTrue(maxV6Id.isPresent());
final Version maxVersion = Version.fromId(maxV6Id.getAsInt());
for (int i = 0; i < iterations; i++) {
Version version = randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), maxVersion);
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());

BytesStreamOutput output = new BytesStreamOutput();
output.setVersion(version);
indicesOptions.writeIndicesOptions(output);

StreamInput streamInput = output.bytes().streamInput();
streamInput.setVersion(version);
IndicesOptions indicesOptions2 = IndicesOptions.readIndicesOptions(streamInput);

assertThat(indicesOptions2.ignoreUnavailable(), equalTo(indicesOptions.ignoreUnavailable()));
assertThat(indicesOptions2.allowNoIndices(), equalTo(indicesOptions.allowNoIndices()));
assertThat(indicesOptions2.expandWildcardsOpen(), equalTo(indicesOptions.expandWildcardsOpen()));
assertThat(indicesOptions2.expandWildcardsClosed(), equalTo(indicesOptions.expandWildcardsClosed()));

assertThat(indicesOptions2.forbidClosedIndices(), equalTo(indicesOptions.forbidClosedIndices()));
assertThat(indicesOptions2.allowAliasesToMultipleIndices(), equalTo(indicesOptions.allowAliasesToMultipleIndices()));

assertEquals(indicesOptions2.ignoreAliases(), indicesOptions.ignoreAliases());
assertEquals(indicesOptions2.ignoreThrottled(), indicesOptions.ignoreThrottled());
}
}

public void testFromOptions() {
final boolean ignoreUnavailable = randomBoolean();
final boolean allowNoIndices = randomBoolean();
Expand Down
Loading