From c2bd1ba15f619a4c0fcd7105cb68ae628a29b488 Mon Sep 17 00:00:00 2001 From: Suraj Singh Date: Mon, 29 Aug 2022 04:23:08 -0700 Subject: [PATCH] For segrep enabled indices, use NRTReplicationEngine for replica shards (#486) * Update engine factory to return NRTReplicationEngine for replica shards Signed-off-by: Suraj Singh * Address review comments Signed-off-by: Suraj Singh Signed-off-by: Suraj Singh (cherry picked from commit 81c2002c889094ae4071e403e76393c00c9b567c) --- .../org/opensearch/replication/ReplicationPlugin.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/opensearch/replication/ReplicationPlugin.kt b/src/main/kotlin/org/opensearch/replication/ReplicationPlugin.kt index 3fa602b0..53c77866 100644 --- a/src/main/kotlin/org/opensearch/replication/ReplicationPlugin.kt +++ b/src/main/kotlin/org/opensearch/replication/ReplicationPlugin.kt @@ -143,6 +143,9 @@ import org.opensearch.watcher.ResourceWatcherService import java.util.Optional import java.util.function.Supplier +import org.opensearch.index.engine.NRTReplicationEngine + + @OpenForTesting internal class ReplicationPlugin : Plugin(), ActionPlugin, PersistentTaskPlugin, RepositoryPlugin, EnginePlugin { @@ -359,7 +362,14 @@ internal class ReplicationPlugin : Plugin(), ActionPlugin, PersistentTaskPlugin, override fun getEngineFactory(indexSettings: IndexSettings): Optional { return if (indexSettings.settings.get(REPLICATED_INDEX_SETTING.key) != null) { - Optional.of(EngineFactory { config -> ReplicationEngine(config) }) + Optional.of(EngineFactory { config -> + // Use NRTSegmentReplicationEngine for SEGMENT replication type indices replica shards + if (config.isReadOnlyReplica) { + NRTReplicationEngine(config) + } else { + ReplicationEngine(config) + } + }) } else { Optional.empty() }