Skip to content

Commit

Permalink
Updating filters as well during Alias update (#491) (#500)
Browse files Browse the repository at this point in the history
Testing : Integ Test, Local
Signed-off-by: Gaurav Bafna <gbbafna@amazon.com>
  • Loading branch information
gbbafna authored Aug 26, 2022
1 parent 3c81c0e commit 101467c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,18 @@ open class IndexReplicationTask(id: Long, type: String, action: String, descript
for (alias in toAdd) {
log.info("Adding alias ${alias.alias} from $followerIndexName")
// Copying writeIndex from leader doesn't cause any issue as writes will be blocked anyways
request.addAliasAction(AliasActions.add().index(followerIndexName)
.alias(alias.alias)
.indexRouting(alias.indexRouting)
.searchRouting(alias.searchRouting)
.writeIndex(alias.writeIndex())
.isHidden(alias.isHidden)
)
var aliasAction = AliasActions.add().index(followerIndexName)
.alias(alias.alias)
.indexRouting(alias.indexRouting)
.searchRouting(alias.searchRouting)
.writeIndex(alias.writeIndex())
.isHidden(alias.isHidden)

if (alias.filteringRequired()) {
aliasAction = aliasAction.filter(alias.filter.string())
}

request.addAliasAction(aliasAction)
}

var toRemove = followerAliases - leaderAliases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import org.opensearch.index.mapper.MapperService
import org.opensearch.repositories.fs.FsRepository
import org.opensearch.test.OpenSearchTestCase.assertBusy
import org.junit.Assert
import org.opensearch.cluster.metadata.AliasMetadata
import org.opensearch.common.xcontent.DeprecationHandler
import org.opensearch.common.xcontent.NamedXContentRegistry
import org.opensearch.replication.ReplicationPlugin.Companion.REPLICATION_INDEX_TRANSLOG_PRUNING_ENABLED_SETTING
Expand Down Expand Up @@ -344,8 +345,10 @@ class StartReplicationIT: MultiClusterRestTestCase() {

createConnectionBetweenClusters(FOLLOWER, LEADER)

val createIndexResponse = leaderClient.indices().create(CreateIndexRequest(leaderIndexName).alias(Alias("leaderAlias")), RequestOptions.DEFAULT)
assertThat(createIndexResponse.isAcknowledged).isTrue()
val createIndexResponse = leaderClient.indices().create(CreateIndexRequest(leaderIndexName)
.alias(Alias("leaderAlias").filter("{\"term\":{\"year\":2016}}").routing("1"))
, RequestOptions.DEFAULT)
assertThat(createIndexResponse.isAcknowledged).isTrue
try {
followerClient.startReplication(StartReplicationRequest("source", leaderIndexName, followerIndexName),
waitForRestore = true)
Expand All @@ -361,6 +364,7 @@ class StartReplicationIT: MultiClusterRestTestCase() {
followerClient.indices().getAlias(GetAliasesRequest().indices(followerIndexName),
RequestOptions.DEFAULT).aliases[followerIndexName]
)

}, 30L, TimeUnit.SECONDS)
} finally {
followerClient.stopReplication(followerIndexName)
Expand Down Expand Up @@ -541,7 +545,7 @@ class StartReplicationIT: MultiClusterRestTestCase() {
var indicesAliasesRequest = IndicesAliasesRequest()
var aliasAction = IndicesAliasesRequest.AliasActions.add()
.index(leaderIndexName)
.alias("alias1")
.alias("alias1").filter("{\"term\":{\"year\":2016}}").routing("1")
indicesAliasesRequest.addAliasAction(aliasAction)
leaderClient.indices().updateAliases(indicesAliasesRequest, RequestOptions.DEFAULT)

Expand Down

0 comments on commit 101467c

Please sign in to comment.