forked from opensearch-project/custom-codecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomCodecPlugin.java
74 lines (65 loc) · 2.4 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.common.settings.Setting.Property;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.codec.CodecServiceFactory;
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;
import com.intel.qat.QatZipper;
/**
* A plugin that implements custom codecs. Supports these codecs:
*
* <ul>
* <li>ZSTD_CODEC
* <li>ZSTD_NO_DICT_CODEC
* <li>QAT_DEFLATE
* <li>QAT_LZ4
* </ul>
*
* @opensearch.internal
*/
public final class CustomCodecPlugin extends Plugin implements EnginePlugin {
/** A setting to specifiy the QAT acceleration mode. */
public static final Setting<QatZipper.Mode> INDEX_CODEC_QAT_MODE_SETTING = new Setting<>("index.codec.qatmode", "hardware", s -> {
switch (s) {
case "auto":
return QatZipper.Mode.AUTO;
case "hardware":
return QatZipper.Mode.HARDWARE;
default:
throw new IllegalArgumentException("Unknown value for [index.codec.qatmode] must be one of [auto, hardware] but was: " + s);
}
}, Property.IndexScope, Property.Dynamic);
/** 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_DEFLATE_CODEC)
|| codecName.equals(CustomCodecService.QAT_LZ4_CODEC)) {
return Optional.of(new CustomCodecServiceFactory());
}
return Optional.empty();
}
@Override
public List<Setting<?>> getSettings() {
return Arrays.asList(INDEX_CODEC_QAT_MODE_SETTING);
}
}