From abbf94cfbd29dc434319c0d79a9c048053417c26 Mon Sep 17 00:00:00 2001 From: varuntumbe Date: Tue, 31 Jan 2023 21:53:28 +0530 Subject: [PATCH 1/3] Added EngineExtension Interface Signed-off-by: varuntumbe --- .../org/opensearch/sdk/EngineExtension.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/main/java/org/opensearch/sdk/EngineExtension.java diff --git a/src/main/java/org/opensearch/sdk/EngineExtension.java b/src/main/java/org/opensearch/sdk/EngineExtension.java new file mode 100644 index 00000000..81dbc5de --- /dev/null +++ b/src/main/java/org/opensearch/sdk/EngineExtension.java @@ -0,0 +1,79 @@ +/* + * Copyright OpenSearch Contributors + * 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.sdk; + +import org.opensearch.index.IndexSettings; +import org.opensearch.index.codec.CodecService; +import org.opensearch.index.codec.CodecServiceFactory; +import org.opensearch.index.engine.EngineFactory; +import org.opensearch.index.seqno.RetentionLeases; +import org.opensearch.index.translog.TranslogDeletionPolicy; +import org.opensearch.index.translog.TranslogDeletionPolicyFactory; + +import java.util.Optional; +import java.util.function.Supplier; + +/** + * A Extension that provides alternative engine implementations. + * + */ +public interface EngineExtension { + + /** + * When an index is created this method is invoked for each engine Extension. Engine Extensions can inspect the index settings to determine + * whether or not to provide an engine factory for the given index. A Extension that is not overriding the default engine should return + * {@link Optional#empty()}. If multiple Extensions return an engine factory for a given index the index will not be created and an + * {@link IllegalStateException} will be thrown during index creation. + * + * @return an optional engine factory + */ + default Optional getEngineFactory(IndexSettings indexSettings) { + return Optional.empty(); + } + + /** + * EXPERT: + * When an index is created this method is invoked for each engine Extension. Engine Extensions can inspect the index settings + * to determine if a custom {@link CodecService} should be provided for the given index. A Extension that is not overriding + * the {@link CodecService} through the Extension can ignore this method and the Codec specified in the {@link IndexSettings} + * will be used. + * + * @deprecated Please use {@code getCustomCodecServiceFactory()} instead as it provides more context for {@link CodecService} + * instance construction. + */ + @Deprecated + default Optional getCustomCodecService(IndexSettings indexSettings) { + return Optional.empty(); + } + + /** + * EXPERT: + * When an index is created this method is invoked for each engine Extension. Engine Extensions can inspect the index settings + * to determine if a custom {@link CodecServiceFactory} should be provided for the given index. A Extension that is not overriding + * the {@link CodecServiceFactory} through the Extension can ignore this method and the default Codec specified in the + * {@link IndexSettings} will be used. + */ + default Optional getCustomCodecServiceFactory(IndexSettings indexSettings) { + return Optional.empty(); + } + + /** + * When an index is created this method is invoked for each engine Extension. Engine Extensions that need to provide a + * custom {@link TranslogDeletionPolicy} can override this method to return a function that takes the {@link IndexSettings} + * and a {@link Supplier} for {@link RetentionLeases} and returns a custom {@link TranslogDeletionPolicy}. + * + * Only one of the installed Engine Extensions can override this otherwise {@link IllegalStateException} will be thrown. + * + * @return a function that returns an instance of {@link TranslogDeletionPolicy} + */ + default Optional getCustomTranslogDeletionPolicyFactory() { + return Optional.empty(); + } +} From 943df508d46024d17c7ba957f8e2986a5c13ea8c Mon Sep 17 00:00:00 2001 From: varuntumbe Date: Tue, 31 Jan 2023 23:47:40 +0530 Subject: [PATCH 2/3] deleting the depreciated method Signed-off-by: varuntumbe --- .../java/org/opensearch/sdk/EngineExtension.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/main/java/org/opensearch/sdk/EngineExtension.java b/src/main/java/org/opensearch/sdk/EngineExtension.java index 81dbc5de..906bd36e 100644 --- a/src/main/java/org/opensearch/sdk/EngineExtension.java +++ b/src/main/java/org/opensearch/sdk/EngineExtension.java @@ -10,7 +10,6 @@ package org.opensearch.sdk; import org.opensearch.index.IndexSettings; -import org.opensearch.index.codec.CodecService; import org.opensearch.index.codec.CodecServiceFactory; import org.opensearch.index.engine.EngineFactory; import org.opensearch.index.seqno.RetentionLeases; @@ -38,20 +37,6 @@ default Optional getEngineFactory(IndexSettings indexSettings) { return Optional.empty(); } - /** - * EXPERT: - * When an index is created this method is invoked for each engine Extension. Engine Extensions can inspect the index settings - * to determine if a custom {@link CodecService} should be provided for the given index. A Extension that is not overriding - * the {@link CodecService} through the Extension can ignore this method and the Codec specified in the {@link IndexSettings} - * will be used. - * - * @deprecated Please use {@code getCustomCodecServiceFactory()} instead as it provides more context for {@link CodecService} - * instance construction. - */ - @Deprecated - default Optional getCustomCodecService(IndexSettings indexSettings) { - return Optional.empty(); - } /** * EXPERT: From 2976812bfd0faf2ec3771d3f23c95630d0c6d1d8 Mon Sep 17 00:00:00 2001 From: varuntumbe Date: Tue, 31 Jan 2023 23:52:30 +0530 Subject: [PATCH 3/3] spotlessApply has been done Signed-off-by: varuntumbe --- src/main/java/org/opensearch/sdk/EngineExtension.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/opensearch/sdk/EngineExtension.java b/src/main/java/org/opensearch/sdk/EngineExtension.java index 906bd36e..c44834ee 100644 --- a/src/main/java/org/opensearch/sdk/EngineExtension.java +++ b/src/main/java/org/opensearch/sdk/EngineExtension.java @@ -37,7 +37,6 @@ default Optional getEngineFactory(IndexSettings indexSettings) { return Optional.empty(); } - /** * EXPERT: * When an index is created this method is invoked for each engine Extension. Engine Extensions can inspect the index settings