Skip to content

Commit

Permalink
Include default index settings during leader setting validation (#601) (
Browse files Browse the repository at this point in the history
#609) (#610)

Signed-off-by: Ankit Kala <[email protected]>

Signed-off-by: Ankit Kala <[email protected]>
(cherry picked from commit 67a7073)
(cherry picked from commit 198e38b)

Co-authored-by: Ankit Kala <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and ankitkala authored Oct 28, 2022
1 parent c57092e commit 5d9aad0
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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()
}
}

0 comments on commit 5d9aad0

Please sign in to comment.