From 5d9aad079c54b07212516fb1ff9bcf2f5ee6e045 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 28 Oct 2022 17:04:34 +0530 Subject: [PATCH] Include default index settings during leader setting validation (#601) (#609) (#610) Signed-off-by: Ankit Kala Signed-off-by: Ankit Kala (cherry picked from commit 67a7073e77d62e1d4b5cb75fc44ff00d06b2a6cc) (cherry picked from commit 198e38b9067e8d9dbc0e672c41a6fffb62706a50) Co-authored-by: Ankit Kala --- .../index/TransportReplicateIndexAction.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/org/opensearch/replication/action/index/TransportReplicateIndexAction.kt b/src/main/kotlin/org/opensearch/replication/action/index/TransportReplicateIndexAction.kt index 11a60aa1..d31024d8 100644 --- a/src/main/kotlin/org/opensearch/replication/action/index/TransportReplicateIndexAction.kt +++ b/src/main/kotlin/org/opensearch/replication/action/index/TransportReplicateIndexAction.kt @@ -91,7 +91,9 @@ class TransportReplicateIndexAction @Inject constructor(transportService: Transp !leaderSettings.get(ReplicationPlugin.REPLICATED_INDEX_SETTING.key).isNullOrBlank()) { throw IllegalArgumentException("Cannot Replicate a Replicated Index ${request.leaderIndex}") } - if (!leaderSettings.getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.key, true)) { + + // Soft deletes should be enabled for replication to work. + if (!leaderSettings.getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.key, false)) { throw IllegalArgumentException("Cannot Replicate an index where the setting ${IndexSettings.INDEX_SOFT_DELETES_SETTING.key} is disabled") } @@ -127,9 +129,19 @@ class TransportReplicateIndexAction @Inject constructor(transportService: Transp private suspend fun getLeaderIndexSettings(leaderAlias: String, leaderIndex: String): Settings { val remoteClient = client.getRemoteClusterClient(leaderAlias) - val getSettingsRequest = GetSettingsRequest().includeDefaults(false).indices(leaderIndex) - val settingsResponse = remoteClient.suspending(remoteClient.admin().indices()::getSettings, - injectSecurityContext = true)(getSettingsRequest) - return settingsResponse.indexToSettings.get(leaderIndex) ?: throw IndexNotFoundException("${leaderAlias}:${leaderIndex}") + val getSettingsRequest = GetSettingsRequest().includeDefaults(true).indices(leaderIndex) + val settingsResponse = remoteClient.suspending( + remoteClient.admin().indices()::getSettings, + injectSecurityContext = true + )(getSettingsRequest) + + val leaderSettings = settingsResponse.indexToSettings.get(leaderIndex) + ?: throw IndexNotFoundException("${leaderAlias}:${leaderIndex}") + val leaderDefaultSettings = settingsResponse.indexToDefaultSettings.get(leaderIndex) + ?: throw IndexNotFoundException("${leaderAlias}:${leaderIndex}") + + // Since we want user configured as well as default settings, we combine both by putting default settings + // and then the explicitly set ones to override the default settings. + return Settings.builder().put(leaderDefaultSettings).put(leaderSettings).build() } }