Skip to content

Commit

Permalink
Updating filters as well during Alias update (#491) (#512)
Browse files Browse the repository at this point in the history
Testing : Integ Test, Local
Signed-off-by: Gaurav Bafna <[email protected]>
  • Loading branch information
gbbafna authored Aug 26, 2022
1 parent 8d0d7f5 commit b9fc659
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,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 @@ -330,7 +331,9 @@ class StartReplicationIT: MultiClusterRestTestCase() {

createConnectionBetweenClusters(FOLLOWER, LEADER)

val createIndexResponse = leaderClient.indices().create(CreateIndexRequest(leaderIndexName).alias(Alias("leaderAlias")), RequestOptions.DEFAULT)
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))
Expand All @@ -339,12 +342,15 @@ class StartReplicationIT: MultiClusterRestTestCase() {
.exists(GetIndexRequest(followerIndexName), RequestOptions.DEFAULT))
.isEqualTo(true)
}
Assert.assertEquals(
leaderClient.indices().getAlias(GetAliasesRequest().indices(leaderIndexName),
RequestOptions.DEFAULT).aliases[leaderIndexName],
followerClient.indices().getAlias(GetAliasesRequest().indices(followerIndexName),
RequestOptions.DEFAULT).aliases[followerIndexName]
)
assertBusy({
Assert.assertEquals(
leaderClient.indices().getAlias(GetAliasesRequest().indices(leaderIndexName),
RequestOptions.DEFAULT).aliases[leaderIndexName],
followerClient.indices().getAlias(GetAliasesRequest().indices(followerIndexName),
RequestOptions.DEFAULT).aliases[followerIndexName]
)

}, 30L, TimeUnit.SECONDS)
} finally {
followerClient.stopReplication(followerIndexName)
}
Expand Down Expand Up @@ -521,7 +527,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 b9fc659

Please sign in to comment.