forked from opensearch-project/custom-codecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomCodecPlugin.java
74 lines (66 loc) · 2.62 KB
/
CustomCodecPlugin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.index.codec.customcodecs;
import org.opensearch.common.settings.Setting;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.codec.CodecServiceFactory;
import org.opensearch.index.codec.customcodecs.backward_codecs.lucene99.Lucene99QatCodec;
import org.opensearch.index.engine.EngineConfig;
import org.opensearch.plugins.EnginePlugin;
import org.opensearch.plugins.Plugin;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
/**
* A plugin that implements custom codecs. Supports these codecs:
*
* <ul>
* <li>ZSTD_CODEC
* <li>ZSTD_NO_DICT_CODEC
* <li>QAT_LZ4
* <li>QAT_DEFLATE
* </ul>
*
* @opensearch.internal
*/
public final class CustomCodecPlugin extends Plugin implements EnginePlugin {
/** Creates a new instance */
public CustomCodecPlugin() {}
/**
* @param indexSettings is the default indexSettings
* @return the engine factory
*/
@Override
public Optional<CodecServiceFactory> getCustomCodecServiceFactory(final IndexSettings indexSettings) {
String codecName = indexSettings.getValue(EngineConfig.INDEX_CODEC_SETTING);
if (codecName.equals(CustomCodecService.ZSTD_NO_DICT_CODEC)
|| codecName.equals(CustomCodecService.ZSTD_CODEC)
|| codecName.equals(CustomCodecService.QAT_LZ4_CODEC)
|| codecName.equals(CustomCodecService.QAT_DEFLATE_CODEC)) {
return Optional.of(new CustomCodecServiceFactory());
} else {
if (codecName.equals(Lucene99QatCodec.Mode.QAT_LZ4.getCodec())
|| codecName.equals(Lucene99QatCodec.Mode.QAT_DEFLATE.getCodec())) {
if (!QatZipperFactory.isQatAvailable()) {
throw new IllegalArgumentException("QAT codecs are not supported. Please create indices with a different codec.");
}
}
if (codecName.equals(Lucene912QatCodec.Mode.QAT_LZ4.getCodec())
|| codecName.equals(Lucene912QatCodec.Mode.QAT_DEFLATE.getCodec())) {
if (!QatZipperFactory.isQatAvailable()) {
throw new IllegalArgumentException("QAT codecs are not supported. Please create indices with a different codec.");
}
}
}
return Optional.empty();
}
@Override
public List<Setting<?>> getSettings() {
return Arrays.asList(Lucene99QatCodec.INDEX_CODEC_QAT_MODE_SETTING);
}
}