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

Handle exception for the updation of a replication rule #1405

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
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 @@ -111,6 +111,7 @@ class TransportAutoFollowClusterManagerNodeAction @Inject constructor(transportS
} catch(e: ResourceAlreadyExistsException) {
// Log and bail as task is already running
log.warn("Task already started for '$clusterAlias:$patternName'", e)
throw OpenSearchException("Exisiting autofollow replication rule cannot be recreated/updated", e)
} catch (e: Exception) {
log.error("Failed to start auto follow task for cluster '$clusterAlias:$patternName'", e)
throw OpenSearchException(AUTOFOLLOW_EXCEPTION_GENERIC_STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() {
followerClient.deleteAutoFollowPattern(connectionAlias, indexPatternName)
}
}

fun `test auto follow stats`() {
val indexPatternName2 = "test_pattern2"
val indexPattern2 = "lead_index*"
Expand Down Expand Up @@ -308,6 +308,32 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() {
followerClient.deleteAutoFollowPattern(connectionAlias, indexPatternName)
}.doesNotThrowAnyException()

}
fun `test updation of auto follow pattern`() {
val followerClient = getClientForCluster(FOLLOWER)
createConnectionBetweenClusters(FOLLOWER, LEADER, connectionAlias)
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern)
val indexPattern1 = "log*"
//Re-create the same replication rule
Assertions.assertThatThrownBy {
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern)
}.isInstanceOf(ResponseException::class.java)
.hasMessageContaining("autofollow replication rule cannot be recreated/updated")

//Update the replication rule with different indexpattern
Assertions.assertThatThrownBy {
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern1)
}.isInstanceOf(ResponseException::class.java)
.hasMessageContaining("autofollow replication rule cannot be recreated/updated")

//Create a new replication rule with same indexpattern but unique rule name
Assertions.assertThatCode {
followerClient.updateAutoFollowPattern(connectionAlias, "unique-rule", indexPattern1)
}.doesNotThrowAnyException()

followerClient.deleteAutoFollowPattern(connectionAlias, indexPatternName)
followerClient.deleteAutoFollowPattern(connectionAlias, "unique-rule")

}

fun `test removing autofollow pattern stop autofollow task`() {
Expand Down Expand Up @@ -344,12 +370,12 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() {
try {
//modify retry duration to account for autofollow trigger in next retry
followerClient.updateAutofollowRetrySetting("1m")
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern)
for (repeat in 1..2) {
log.info("Current Iteration $repeat")
// Add replication start block
followerClient.updateReplicationStartBlockSetting(true)
createRandomIndex(leaderClient)
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern)
sleep(95000) // wait for auto follow trigger in the worst case
// verify both index replication tasks and autofollow tasks
// Replication shouldn't have been started - (repeat-1) tasks as for current loop index shouldn't be
Expand Down
Loading