Skip to content

Commit

Permalink
Fix: avoid ZSTD codec from overriding service codec factory. (#7037)
Browse files Browse the repository at this point in the history
* Fix: enable ZSTD codec only if index.codec is set to ZSTD.

  - addresses #7012

Signed-off-by: Mulugeta Mammo <[email protected]>

* Removed custom CodecService and CodecServiceFactory classes.

  - Removed custom classes for CodecService and CodecServiceFactory.
  - Also removed PerFieldMappingPostingFormatCodec -- not required.
  - Added documentation.

Signed-off-by: Mulugeta Mammo <[email protected]>

* Bump zstd-jni version from 1.5.4-1 to 1.5.5-1.

  - Zstandard version 1.5.5 contains a bug fix for a rare corruption error
    described here: https://github.com/facebook/zstd/releases/tag/v1.5.5. The
    zstd-jni version we use here, 1.5.5-1, uses Zstandard v1.5.5.

Signed-off-by: Mulugeta Mammo <[email protected]>

---------

Signed-off-by: Mulugeta Mammo <[email protected]>
  • Loading branch information
mulugetam authored Apr 13, 2023
1 parent a9b4c45 commit 569e90c
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 137 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Bump `net.minidev:json-smart` from 2.4.7 to 2.4.10
- Bump `org.apache.maven:maven-model` from 3.6.2 to 3.9.1
- Bump `org.codehaus.jettison:jettison` from 1.5.3 to 1.5.4 ([#6878](https://github.com/opensearch-project/OpenSearch/pull/6878))
- Add `com.github.luben:zstd-jni:1.5.4-1` ([#3577](https://github.com/opensearch-project/OpenSearch/pull/3577))
- Add `com.github.luben:zstd-jni:1.5.5-1` ([#3577](https://github.com/opensearch-project/OpenSearch/pull/3577))
- Bump: Netty from 4.1.90.Final to 4.1.91.Final , ASM 9.4 to ASM 9.5, ByteBuddy 1.14.2 to 1.14.3 ([#6981](https://github.com/opensearch-project/OpenSearch/pull/6981))
- Bump `com.azure:azure-storage-blob` from 12.15.0 to 12.21.1

Expand Down
2 changes: 1 addition & 1 deletion sandbox/plugins/custom-codecs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ opensearchplugin {
}

dependencies {
api "com.github.luben:zstd-jni:1.5.4-1"
api "com.github.luben:zstd-jni:1.5.5-1"
}

yamlRestTest.enabled = false;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fda1d6278299af27484e1cc3c79a060e41b7ef7e
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

import org.opensearch.plugins.Plugin;
import org.opensearch.plugins.EnginePlugin;
import org.opensearch.index.codec.CodecServiceFactory;
import org.opensearch.index.IndexSettings;

import java.util.Optional;

/**
* A plugin that implements custom codecs. Supports these codecs:
Expand All @@ -25,16 +21,6 @@
* @opensearch.internal
*/
public final class CustomCodecPlugin extends Plugin implements EnginePlugin {

/** Creates a new instance */
/** Creates a new instance. */
public CustomCodecPlugin() {}

/**
* @param indexSettings is the default indexSettings
* @return the engine factory
*/
@Override
public Optional<CodecServiceFactory> getCustomCodecServiceFactory(final IndexSettings indexSettings) {
return Optional.of(new CustomCodecServiceFactory());
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public Lucene95CustomStoredFieldsFormat(Lucene95CustomCodec.Mode mode, int compr
zstdNoDictCompressionMode = new ZstdNoDictCompressionMode(compressionLevel);
}

/**
* Returns a {@link StoredFieldsReader} to load stored fields.
* @param directory The index directory.
* @param si The SegmentInfo that stores segment information.
* @param fn The fieldInfos.
* @param context The IOContext that holds additional details on the merge/search context.
*/
@Override
public StoredFieldsReader fieldsReader(Directory directory, SegmentInfo si, FieldInfos fn, IOContext context) throws IOException {
String value = si.getAttribute(MODE_KEY);
Expand All @@ -71,6 +78,12 @@ public StoredFieldsReader fieldsReader(Directory directory, SegmentInfo si, Fiel
return impl(mode).fieldsReader(directory, si, fn, context);
}

/**
* Returns a {@link StoredFieldsReader} to write stored fields.
* @param directory The index directory.
* @param si The SegmentInfo that stores segment information.
* @param context The IOContext that holds additional details on the merge/search context.
*/
@Override
public StoredFieldsWriter fieldsWriter(Directory directory, SegmentInfo si, IOContext context) throws IOException {
String previous = si.putAttribute(MODE_KEY, mode.name());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public ZstdCodec(int compressionLevel) {
super(Mode.ZSTD, compressionLevel);
}

/** The name for this codec. */
@Override
public String toString() {
return getClass().getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ protected ZstdCompressionMode(int compressionLevel) {
this.compressionLevel = compressionLevel;
}

/** Creates a new compressor instance.*/
@Override
public Compressor newCompressor() {
return new ZstdCompressor(compressionLevel);
}

/** Creates a new decompressor instance. */
@Override
public Decompressor newDecompressor() {
return new ZstdDecompressor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public ZstdNoDictCodec(int compressionLevel) {
super(Mode.ZSTDNODICT, compressionLevel);
}

/** The name for this codec. */
@Override
public String toString() {
return getClass().getSimpleName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ protected ZstdNoDictCompressionMode(int compressionLevel) {
this.compressionLevel = compressionLevel;
}

/** Creates a new compressor instance.*/
@Override
public Compressor newCompressor() {
return new ZstdCompressor(compressionLevel);
}

/** Creates a new decompressor instance. */
@Override
public Decompressor newDecompressor() {
return new ZstdDecompressor();
Expand Down

0 comments on commit 569e90c

Please sign in to comment.