Skip to content

Commit

Permalink
Fix minimum index compatibility error message (#3159) (#3172)
Browse files Browse the repository at this point in the history
This is a very simple fix that adds a special case for the backward
compatibility message for OS 1.x/ES 7.x. This basically mirrors a
special case already codified in [Version][1]. I think this is a
reasonable fix because it allows the message to be quite verbose. It
should also only need to exist on the 2.x branch of OpenSearch since it
is a special case that will no longer exist in 3.x when the entire
LegacyESVersion concept can be removed from the code base.

[1]: https://github.com/opensearch-project/OpenSearch/blob/cb238aae616d6a0fd8f82e128a1f94c8e4e8b1f7/server/src/main/java/org/opensearch/Version.java#L398

Signed-off-by: Andrew Ross <andrross@amazon.com>
(cherry picked from commit 300620e)

Co-authored-by: Andrew Ross <andrross@amazon.com>
  • Loading branch information
opensearch-trigger-bot[bot] and andrross authored May 3, 2022
1 parent 4e7cd2a commit 18d1d27
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.similarities.BM25Similarity;
import org.apache.lucene.search.similarities.Similarity;
import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.common.TriFunction;
import org.opensearch.common.settings.IndexScopedSettings;
Expand Down Expand Up @@ -134,20 +135,35 @@ boolean isUpgraded(IndexMetadata indexMetadata) {
private void checkSupportedVersion(IndexMetadata indexMetadata, Version minimumIndexCompatibilityVersion) {
if (indexMetadata.getState() == IndexMetadata.State.OPEN
&& isSupportedVersion(indexMetadata, minimumIndexCompatibilityVersion) == false) {
throw new IllegalStateException(
"The index ["
+ indexMetadata.getIndex()
+ "] was created with version ["
+ indexMetadata.getCreationVersion()
+ "] but the minimum compatible version is ["

+ minimumIndexCompatibilityVersion
+ "]. It should be re-indexed in OpenSearch "
+ minimumIndexCompatibilityVersion.major
+ ".x before upgrading to "
+ Version.CURRENT
+ "."
);
if (minimumIndexCompatibilityVersion.equals(LegacyESVersion.V_7_0_0)) {
// This branch can be removed when LegacyESVersion is removed
throw new IllegalStateException(
"The index ["
+ indexMetadata.getIndex()
+ "] was created with version ["
+ indexMetadata.getCreationVersion()
+ "] but the minimum compatible version is "
+ "OpenSearch 1.0.0 (or Elasticsearch 7.0.0). "
+ "It should be re-indexed in OpenSearch 1.x "
+ "(or Elasticsearch 7.x) before upgrading to "
+ Version.CURRENT
+ "."
);
} else {
throw new IllegalStateException(
"The index ["
+ indexMetadata.getIndex()
+ "] was created with version ["
+ indexMetadata.getCreationVersion()
+ "] but the minimum compatible version is ["
+ minimumIndexCompatibilityVersion
+ "]. It should be re-indexed in OpenSearch "
+ minimumIndexCompatibilityVersion.major
+ ".x before upgrading to "
+ Version.CURRENT
+ "."
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,21 @@ public void testFailUpgrade() {
.put(IndexMetadata.SETTING_VERSION_CREATED, indexCreated)
.build()
);
String message = expectThrows(
String actualMessage = expectThrows(
IllegalStateException.class,
() -> service.upgradeIndexMetadata(metadata, Version.CURRENT.minimumIndexCompatibilityVersion())
).getMessage();
assertEquals(
message,
"The index [[foo/BOOM]] was created with version ["
+ indexCreated
+ "] "
+ "but the minimum compatible version is ["
+ minCompat
+ "]."
+ " It should be re-indexed in OpenSearch "
+ minCompat.major
+ ".x before upgrading to "
+ Version.CURRENT.toString()
+ "."
);

String expectedMessage = "The index [[foo/BOOM]] was created with version ["
+ indexCreated
+ "] but the minimum compatible version is "
+ "OpenSearch 1.0.0 (or Elasticsearch 7.0.0). "
+ "It should be re-indexed in OpenSearch 1.x "
+ "(or Elasticsearch 7.x) before upgrading to "
+ Version.CURRENT
+ ".";

assertEquals(expectedMessage, actualMessage);

indexCreated = VersionUtils.randomVersionBetween(random(), minCompat, Version.CURRENT);
indexUpgraded = VersionUtils.randomVersionBetween(random(), indexCreated, Version.CURRENT);
Expand Down

0 comments on commit 18d1d27

Please sign in to comment.