From 55af919ea6d65da4263d799863a1bced54768ac1 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 7 Jun 2023 11:47:51 -0500 Subject: [PATCH] Remove error path for ancient compression detection (#7932) (#7939) The error message generated by this code path refers to Elasticsearch version 2.0.0.beta1, which is likely to cause confusion with the OpenSearch 2.x line if it were ever to be encountered. The ES2 version is so old that I don't think we need any special handling here and can just fall back to the default "not xcontent" error message. (cherry picked from commit 4592d7c6cfb9a06ff9800ea9573eb72f735c2138) Signed-off-by: Andrew Ross Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../common/compress/CompressorFactory.java | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/server/src/main/java/org/opensearch/common/compress/CompressorFactory.java b/server/src/main/java/org/opensearch/common/compress/CompressorFactory.java index 1d8f2dcec709a..23a8cac349bd2 100644 --- a/server/src/main/java/org/opensearch/common/compress/CompressorFactory.java +++ b/server/src/main/java/org/opensearch/common/compress/CompressorFactory.java @@ -35,7 +35,6 @@ import org.opensearch.common.Nullable; import org.opensearch.common.bytes.BytesReference; import org.opensearch.common.xcontent.XContentHelper; -import org.opensearch.common.xcontent.XContentType; import java.io.IOException; import java.util.Objects; @@ -73,22 +72,13 @@ public static Compressor compressor(BytesReference bytes) { return ZSTD_COMPRESSOR; } - XContentType contentType = XContentHelper.xContentType(bytes); - if (contentType == null) { - if (isAncient(bytes)) { - throw new IllegalStateException("unsupported compression: index was created before v2.0.0.beta1 and wasn't upgraded?"); - } + if (XContentHelper.xContentType(bytes) == null) { throw new NotXContentException("Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"); } return null; } - /** true if the bytes were compressed with LZF*/ - private static boolean isAncient(BytesReference bytes) { - return bytes.length() >= 3 && bytes.get(0) == 'Z' && bytes.get(1) == 'V' && (bytes.get(2) == 0 || bytes.get(2) == 1); - } - /** * Uncompress the provided data, data can be detected as compressed using {@link #isCompressed(BytesReference)}. */