Skip to content

Commit

Permalink
Remove error path for ancient compression detection (#7932) (#7939)
Browse files Browse the repository at this point in the history
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 4592d7c)

Signed-off-by: Andrew Ross <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 2d289a4 commit 55af919
Showing 1 changed file with 1 addition and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)}.
*/
Expand Down

0 comments on commit 55af919

Please sign in to comment.