Skip to content

Commit c130e18

Browse files
nknizekkmr
authored andcommitted
Refactor Compressors from CompressorFactory to CompressorRegistry for extensibility (opensearch-project#9262)
* Refactor Compressors from CompressorFactory to CompressorRegistry for extensibility This commit refactors the CompressorFactory static singleton class and CompressorType enum to a formal CompressorRegistry and enables downstream implementations to register their own compression implementations for use in compressing Blob stores and MediaType data. This is different from Lucene's Codec compression extension points which expose different compression implementations for Lucene's Stored Fields. Signed-off-by: Nicholas Walter Knize <nknize@apache.org> * fix missing javadoc and relocate the common compress to compress package Signed-off-by: Nicholas Walter Knize <nknize@apache.org> * fix deprecated case Signed-off-by: Nicholas Walter Knize <nknize@apache.org> * fix typo in compress build.gradle Signed-off-by: Nicholas Walter Knize <nknize@apache.org> * PR cleanup Signed-off-by: Nicholas Walter Knize <nknize@apache.org> * PR changes Signed-off-by: Nicholas Walter Knize <nknize@apache.org> * update with initial annotations Signed-off-by: Nicholas Walter Knize <nknize@apache.org> * remove NONE singleton in CompressorRegistry and remove static block init Signed-off-by: Nicholas Walter Knize <nknize@apache.org> --------- Signed-off-by: Nicholas Walter Knize <nknize@apache.org> Signed-off-by: Kiran Reddy <kkreddy@amazon.com>
1 parent 88e2d50 commit c130e18

File tree

51 files changed

+542
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+542
-261
lines changed

gradle/missing-javadoc.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ configure([
166166
configure([
167167
project(":libs:opensearch-common"),
168168
project(":libs:opensearch-core"),
169+
project(":libs:opensearch-compress"),
169170
project(":plugins:events-correlation-engine"),
170171
project(":server")
171172
]) {

libs/compress/build.gradle

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
apply plugin: 'opensearch.build'
13+
apply plugin: 'opensearch.publish'
14+
15+
base {
16+
archivesName = 'opensearch-compress'
17+
}
18+
19+
dependencies {
20+
api project(':libs:opensearch-common')
21+
api project(':libs:opensearch-core')
22+
23+
//zstd
24+
api "com.github.luben:zstd-jni:${versions.zstd}"
25+
26+
testImplementation(project(":test:framework")) {
27+
// tests use the locally compiled version of server
28+
exclude group: 'org.opensearch', module: 'opensearch-compress'
29+
}
30+
}
31+
32+
tasks.named('forbiddenApisMain').configure {
33+
// :libs:opensearch-compress does not depend on server
34+
// TODO: Need to decide how we want to handle for forbidden signatures with the changes to server
35+
replaceSignatureFiles 'jdk-signatures'
36+
}
37+
38+
jarHell.enabled = false

server/src/main/java/org/opensearch/common/compress/ZstdCompressor.java renamed to libs/compress/src/main/java/org/opensearch/compress/ZstdCompressor.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
* compatible open source license.
77
*/
88

9-
package org.opensearch.common.compress;
9+
package org.opensearch.compress;
1010

1111
import com.github.luben.zstd.RecyclingBufferPool;
1212
import com.github.luben.zstd.ZstdInputStreamNoFinalizer;
1313
import com.github.luben.zstd.ZstdOutputStreamNoFinalizer;
14+
import org.opensearch.common.annotation.PublicApi;
1415
import org.opensearch.core.common.bytes.BytesReference;
15-
import org.opensearch.core.common.compress.Compressor;
16+
import org.opensearch.core.compress.Compressor;
1617

1718
import java.io.BufferedInputStream;
1819
import java.io.BufferedOutputStream;
@@ -24,7 +25,8 @@
2425
/**
2526
* {@link Compressor} implementation based on the ZSTD compression algorithm.
2627
*
27-
* @opensearch.internal
28+
* @opensearch.api - registered name requires BWC support
29+
* @opensearch.experimental - class methods might change
2830
*/
2931
public class ZstdCompressor implements Compressor {
3032
// An arbitrary header that we use to identify compressed streams
@@ -33,6 +35,14 @@ public class ZstdCompressor implements Compressor {
3335
// a XContent
3436
private static final byte[] HEADER = new byte[] { 'Z', 'S', 'T', 'D', '\0' };
3537

38+
/**
39+
* The name to register the compressor by
40+
*
41+
* @opensearch.api - requires BWC support
42+
*/
43+
@PublicApi(since = "2.10.0")
44+
public static final String NAME = "ZSTD";
45+
3646
private static final int LEVEL = 3;
3747

3848
private static final int BUFFER_SIZE = 4096;

libs/core/src/main/java/org/opensearch/core/common/compress/package-info.java renamed to libs/compress/src/main/java/org/opensearch/compress/package-info.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66
* compatible open source license.
77
*/
88

9-
/** Classes for core compress module */
10-
package org.opensearch.core.common.compress;
9+
/**
10+
* Concrete {@link org.opensearch.core.compress.Compressor} implementations
11+
*/
12+
package org.opensearch.compress;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.compress.spi;
10+
11+
import org.opensearch.compress.ZstdCompressor;
12+
import org.opensearch.core.compress.Compressor;
13+
import org.opensearch.core.compress.spi.CompressorProvider;
14+
15+
import java.util.AbstractMap.SimpleEntry;
16+
import java.util.Map.Entry;
17+
import java.util.List;
18+
19+
/**
20+
* Additional "optional" compressor implementations provided by the opensearch compress library
21+
*
22+
* @opensearch.internal
23+
*/
24+
public class CompressionProvider implements CompressorProvider {
25+
26+
/** Returns the concrete {@link Compressor}s provided by the compress library */
27+
@SuppressWarnings({ "unchecked", "rawtypes" })
28+
@Override
29+
public List<Entry<String, Compressor>> getCompressors() {
30+
return List.of(new SimpleEntry<>(ZstdCompressor.NAME, new ZstdCompressor()));
31+
}
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
/**
10+
* Service Provider Interface for registering concrete {@link org.opensearch.core.compress.Compressor}
11+
* implementations.
12+
*
13+
* See {@link org.opensearch.compress.ZstdCompressor}
14+
*/
15+
package org.opensearch.compress.spi;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
/**
10+
* This is the compress library for registering optional
11+
* {@link org.opensearch.core.compress.Compressor} implementations
12+
*/
13+
package org.opensearch;

0 commit comments

Comments
 (0)