Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Include default index settings during leader setting validation (#601) #609

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}