Skip to content

Commit

Permalink
[Versioning] Rebase to OpenSearch version 1.0.0 (opensearch-project#555)
Browse files Browse the repository at this point in the history
This commit rebases the versioning to OpenSearch 1.0.0

Co-authored-by: Rabi Panda <adnapibar@gmail.com>

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize authored Apr 15, 2021
1 parent 4dde0f2 commit 0ba0e7c
Show file tree
Hide file tree
Showing 439 changed files with 1,979 additions and 1,731 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class PluginBuildPlugin implements Plugin<Project> {
'name' : extension1.name,
'description' : extension1.description,
'version' : extension1.version,
'opensearchVersion': Version.fromString(VersionProperties.getOpenSearch()).toString(),
'opensearchVersion' : Version.fromString(VersionProperties.getOpenSearch()).toString(),
'javaVersion' : project.targetCompatibility as String,
'classname' : extension1.classname,
'extendedPlugins' : extension1.extendedPlugins.join(','),
Expand Down
77 changes: 52 additions & 25 deletions buildSrc/src/main/java/org/opensearch/gradle/BwcVersions.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
public class BwcVersions {

private static final Pattern LINE_PATTERN = Pattern.compile(
"\\W+public static final Version V_(\\d+)_(\\d+)_(\\d+)(_alpha\\d+|_beta\\d+|_rc\\d+)? .*"
"\\W+public static final (LegacyES)?Version V_(\\d+)_(\\d+)_(\\d+)(_alpha\\d+|_beta\\d+|_rc\\d+)? .*"
);

private final Version currentVersion;
Expand Down Expand Up @@ -128,9 +128,9 @@ protected BwcVersions(List<String> versionLines, Version currentVersionProperty)
.filter(Matcher::matches)
.map(
match -> new Version(
Integer.parseInt(match.group(1)),
Integer.parseInt(match.group(2)),
Integer.parseInt(match.group(3))
Integer.parseInt(match.group(3)),
Integer.parseInt(match.group(4))
)
)
.collect(Collectors.toCollection(TreeSet::new)),
Expand All @@ -144,12 +144,18 @@ public BwcVersions(SortedSet<Version> allVersions, Version currentVersionPropert
throw new IllegalArgumentException("Could not parse any versions");
}

// hack: this is horribly volatile like this entire logic; fix
currentVersion = allVersions.last();

groupByMajor = allVersions.stream()
// We only care about the last 2 majors when it comes to BWC.
// It might take us time to remove the older ones from versionLines, so we allow them to exist.
.filter(version -> version.getMajor() > currentVersion.getMajor() - 2)
// Adjust the major number since OpenSearch 1.x is released after predecessor version 7.x
.filter(
version -> (version.getMajor() == 1 ? 7 : version.getMajor()) > (currentVersion.getMajor() == 1
? 7
: currentVersion.getMajor()) - 2
)
.collect(Collectors.groupingBy(Version::getMajor, Collectors.toList()));

assertCurrentVersionMatchesParsed(currentVersionProperty);
Expand Down Expand Up @@ -262,14 +268,17 @@ public List<Version> getUnreleased() {
// The current version is being worked, is always unreleased
unreleased.add(currentVersion);

// the tip of the previous major is unreleased for sure, be it a minor or a bugfix
final Version latestOfPreviousMajor = getLatestVersionByKey(this.groupByMajor, currentVersion.getMajor() - 1);
unreleased.add(latestOfPreviousMajor);
if (latestOfPreviousMajor.getRevision() == 0) {
// if the previous major is a x.y.0 release, then the tip of the minor before that (y-1) is also unreleased
final Version previousMinor = getLatestInMinor(latestOfPreviousMajor.getMajor(), latestOfPreviousMajor.getMinor() - 1);
if (previousMinor != null) {
unreleased.add(previousMinor);
// version 1 is the first release, there is no previous "unreleased version":
if (currentVersion.getMajor() != 1) {
// the tip of the previous major is unreleased for sure, be it a minor or a bugfix
final Version latestOfPreviousMajor = getLatestVersionByKey(this.groupByMajor, currentVersion.getMajor() - 1);
unreleased.add(latestOfPreviousMajor);
if (latestOfPreviousMajor.getRevision() == 0) {
// if the previous major is a x.y.0 release, then the tip of the minor before that (y-1) is also unreleased
final Version previousMinor = getLatestInMinor(latestOfPreviousMajor.getMajor(), latestOfPreviousMajor.getMinor() - 1);
if (previousMinor != null) {
unreleased.add(previousMinor);
}
}
}

Expand Down Expand Up @@ -306,8 +315,9 @@ private Version getLatestVersionByKey(Map<Integer, List<Version>> groupByMajor,
}

private Map<Integer, List<Version>> getReleasedMajorGroupedByMinor() {
List<Version> currentMajorVersions = groupByMajor.get(currentVersion.getMajor());
List<Version> previousMajorVersions = groupByMajor.get(currentVersion.getMajor() - 1);
int currentMajor = currentVersion.getMajor();
List<Version> currentMajorVersions = groupByMajor.get(currentMajor);
List<Version> previousMajorVersions = groupByMajor.get(getPreviousMajor(currentMajor));

final Map<Integer, List<Version>> groupByMinor;
if (currentMajorVersions.size() == 1) {
Expand Down Expand Up @@ -353,23 +363,36 @@ private List<Version> getReleased() {
}

public List<Version> getIndexCompatible() {
return unmodifiableList(
Stream.concat(groupByMajor.get(currentVersion.getMajor() - 1).stream(), groupByMajor.get(currentVersion.getMajor()).stream())
.filter(version -> version.equals(currentVersion) == false)
.collect(Collectors.toList())
);

int currentMajor = currentVersion.getMajor();
int prevMajor = getPreviousMajor(currentMajor);
List<Version> result = Stream.concat(groupByMajor.get(prevMajor).stream(), groupByMajor.get(currentMajor).stream())
.filter(version -> version.equals(currentVersion) == false)
.collect(Collectors.toList());
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()));
}
return unmodifiableList(result);
}

public List<Version> getWireCompatible() {
List<Version> wireCompat = new ArrayList<>();
int currentMajor = currentVersion.getMajor();
int lastMajor = currentMajor == 1 ? 6 : currentMajor - 1;
List<Version> lastMajorList = groupByMajor.get(lastMajor);
int minor = lastMajorList.get(lastMajorList.size() - 1).getMinor();
for (int i = lastMajorList.size() - 1; i > 0 && lastMajorList.get(i).getMinor() == minor; --i) {
wireCompat.add(lastMajorList.get(i));
}

List<Version> prevMajors = groupByMajor.get(currentVersion.getMajor() - 1);
int minor = prevMajors.get(prevMajors.size() - 1).getMinor();
for (int i = prevMajors.size() - 1; i > 0 && prevMajors.get(i).getMinor() == minor; i--) {
wireCompat.add(prevMajors.get(i));
// if current is OpenSearch 1.0.0 add all of the 7.x line:
if (currentMajor == 1) {
List<Version> previousMajor = groupByMajor.get(7);
for (Version v : previousMajor) {
wireCompat.add(v);
}
}
wireCompat.addAll(groupByMajor.get(currentVersion.getMajor()));
wireCompat.addAll(groupByMajor.get(currentMajor));
wireCompat.remove(currentVersion);
wireCompat.sort(Version::compareTo);

Expand All @@ -388,4 +411,8 @@ public List<Version> getUnreleasedWireCompatible() {
return unmodifiableList(unreleasedWireCompatible);
}

private int getPreviousMajor(int currentMajor) {
return currentMajor == 1 ? 7 : currentMajor - 1;
}

}
6 changes: 5 additions & 1 deletion buildSrc/src/main/java/org/opensearch/gradle/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public final class Version implements Comparable<Version> {
private final int minor;
private final int revision;
private final int id;
// used to identify rebase to OpenSearch 1.0.0
public static final int MASK = 0x08000000;

/**
* Specifies how a version string should be parsed.
Expand Down Expand Up @@ -73,7 +75,9 @@ public Version(int major, int minor, int revision) {
this.revision = revision;

// currently snapshot is not taken into account
this.id = major * 10000000 + minor * 100000 + revision * 1000;
int id = major * 10000000 + minor * 100000 + revision * 1000;
// identify if new OpenSearch version 1
this.id = major == 1 ? id ^ MASK : id;
}

private static int parseSuffixNumber(String substring) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

public class GlobalBuildInfoPlugin implements Plugin<Project> {
private static final Logger LOGGER = Logging.getLogger(GlobalBuildInfoPlugin.class);
private static final String DEFAULT_LEGACY_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/opensearch/LegacyESVersion.java";
private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/opensearch/Version.java";
private static Integer _defaultParallel = null;
private static Boolean _isBundledJdkSupported = null;
Expand Down Expand Up @@ -140,9 +141,13 @@ public void apply(Project project) {
* compatibility. It is *super* important that this logic is the same as the
* logic in VersionUtils.java. */
private static BwcVersions resolveBwcVersions(File root) {
// todo redesign this terrible unreliable hack; should NEVER rely on parsing a source file
// for now, we hack the hack
File versionsFile = new File(root, DEFAULT_VERSION_JAVA_FILE_PATH);
try {
List<String> versionLines = IOUtils.readLines(new FileInputStream(versionsFile), "UTF-8");
File legacyVersionsFile = new File(root, DEFAULT_LEGACY_VERSION_JAVA_FILE_PATH);
try (FileInputStream fis = new FileInputStream(versionsFile); FileInputStream fis2 = new FileInputStream(legacyVersionsFile)) {
List<String> versionLines = IOUtils.readLines(fis, "UTF-8");
versionLines.addAll(IOUtils.readLines(fis2, "UTF-8"));
return new BwcVersions(versionLines);
} catch (IOException e) {
throw new IllegalStateException("Unable to resolve to resolve bwc versions from versionsFile.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1151,13 +1151,13 @@ private void createConfiguration() {
} else {
baseConfig.put("script.max_compilations_rate", "2048/1m");
}
if (getVersion().getMajor() >= 6) {
if (getVersion().onOrAfter("6.0.0")) {
baseConfig.put("cluster.routing.allocation.disk.watermark.flood_stage", "1b");
}
// Temporarily disable the real memory usage circuit breaker. It depends on real memory usage which we have no full control
// over and the REST client will not retry on circuit breaking exceptions yet (see #31986 for details). Once the REST client
// can retry on circuit breaking exceptions, we can revert again to the default configuration.
if (getVersion().getMajor() >= 7) {
if (getVersion().onOrAfter("7.0.0")) {
baseConfig.put("indices.breaker.total.use_real_memory", "false");
}
// Don't wait for state, just start up quickly. This will also allow new and old nodes in the BWC case to become the master
Expand Down Expand Up @@ -1236,7 +1236,7 @@ private Map<String, String> jvmOptionExpansions() {
if (version.onOrAfter("6.2.0")) {
expansions.put("logs/gc.log", relativeLogPath.resolve("gc.log").toString());
}
if (getVersion().getMajor() >= 7) {
if (getVersion().onOrAfter("7.0.0")) {
expansions.put(
"-XX:ErrorFile=logs/hs_err_pid%p.log",
"-XX:ErrorFile=" + relativeLogPath.resolve("hs_err_pid%p.log").toString()
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("2.0.0");
private static final Version BWC_MINOR_VERSION = Version.fromString("1.1.0");
private static final Version BWC_STAGED_VERSION = Version.fromString("1.0.0");
private static final Version BWC_BUGFIX_VERSION = Version.fromString("1.0.1");
private static final Version BWC_MAINTENANCE_VERSION = Version.fromString("0.90.1");
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 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 @@ -64,7 +64,8 @@ public void testRelaxedVersionParsing() {
}

public void testCompareWithStringVersions() {
assertTrue("1.10.20 is not interpreted as before 2.0.0", Version.fromString("1.10.20").before("2.0.0"));
// 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(
"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 = 7.10.3
opensearch = 1.0.0
lucene = 8.7.0

bundled_jdk_vendor = adoptopenjdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
package org.opensearch.client.core;

import org.opensearch.Build;
import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.client.AbstractResponseTestCase;
import org.opensearch.cluster.ClusterName;
Expand All @@ -52,7 +53,7 @@ protected org.opensearch.action.main.MainResponse createServerTestInstance(XCont
ClusterName clusterName = new ClusterName(randomAlphaOfLength(10));
String nodeName = randomAlphaOfLength(10);
final String date = new Date(randomNonNegativeLong()).toString();
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_0_1, Version.CURRENT);
Version version = VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_6_0_1, Version.CURRENT);
Build build = new Build(
Build.Type.UNKNOWN, randomAlphaOfLength(8), date, randomBoolean(),
version.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.stream.Collectors;

import org.apache.lucene.util.LuceneTestCase;
import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.cli.ExitCodes;
import org.opensearch.cli.MockTerminal;
Expand Down Expand Up @@ -262,7 +263,7 @@ public void testExistingIncompatiblePlugin() throws Exception {
"version",
"1.0",
"opensearch.version",
Version.fromString("1.0.0").toString(),
LegacyESVersion.fromString("5.0.0").toString(),
"java.version",
System.getProperty("java.specification.version"),
"classname",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.cjk.CJKBigramFilter;
import org.apache.lucene.analysis.miscellaneous.DisableGraphAttribute;
import org.opensearch.Version;
import org.opensearch.LegacyESVersion;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.settings.Settings;
import org.opensearch.env.Environment;
Expand Down Expand Up @@ -110,7 +110,7 @@ public TokenStream create(TokenStream tokenStream) {
@Override
public TokenFilterFactory getSynonymFilter() {
if (outputUnigrams) {
if (indexSettings.getIndexVersionCreated().onOrAfter(Version.V_7_0_0)) {
if (indexSettings.getIndexVersionCreated().onOrAfter(LegacyESVersion.V_7_0_0)) {
throw new IllegalArgumentException("Token filter [" + name() +
"] cannot be used to parse synonyms");
}
Expand Down
Loading

0 comments on commit 0ba0e7c

Please sign in to comment.