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] Add support to ignore updates on autofollow pattern #1447

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
chown -R 1000:1000 `pwd`
su `id -un 1000` -c 'whoami && java -version && ./gradlew --refresh-dependencies clean release -D"build.snapshot=true"'
- name: Upload failed logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: logs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bwc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
./gradlew mixedClusterTask --stacktrace
./gradlew fullRestartClusterTask --stacktrace
- name: Upload failed logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: logs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/security-knn-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
ls -al src/test/resources/security/plugin
su `id -un 1000` -c "whoami && java -version && ./gradlew --refresh-dependencies clean release -Dbuild.snapshot=true -Psecurity=true"
- name: Upload failed logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: logs
Expand Down Expand Up @@ -122,7 +122,7 @@ jobs:
chown -R 1000:1000 `pwd`
su `id -un 1000` -c 'whoami && java -version && ./gradlew --refresh-dependencies clean release -Dbuild.snapshot=true -PnumNodes=1 -Dtests.class=org.opensearch.replication.BasicReplicationIT -Dtests.method="test knn index replication" -Pknn=true'
- name: Upload failed logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: logs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
ls -al src/test/resources/security/plugin
./gradlew clean release -Dbuild.snapshot=true -PnumNodes=1 -Psecurity=true
- name: Upload failed logs
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: logs
Expand Down
15 changes: 11 additions & 4 deletions src/test/kotlin/org/opensearch/replication/ReplicationHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.opensearch.action.support.master.AcknowledgedResponse
import org.opensearch.client.Request
import org.opensearch.client.RequestOptions
import org.opensearch.client.Response
import org.opensearch.client.ResponseException
import org.opensearch.client.RestHighLevelClient
import org.opensearch.common.settings.Settings
import org.opensearch.common.unit.TimeValue
Expand Down Expand Up @@ -325,7 +326,8 @@ fun RestHighLevelClient.waitForReplicationStop(index: String, waitFor : TimeValu
fun RestHighLevelClient.updateAutoFollowPattern(connection: String, patternName: String, pattern: String,
settings: Settings = Settings.EMPTY,
useRoles: UseRoles = UseRoles(),
requestOptions: RequestOptions = RequestOptions.DEFAULT) {
requestOptions: RequestOptions = RequestOptions.DEFAULT,
ignoreIfExists: Boolean = false) {
val lowLevelRequest = Request("POST", REST_AUTO_FOLLOW_PATTERN)
if (settings == Settings.EMPTY) {
lowLevelRequest.setJsonEntity("""{
Expand All @@ -350,9 +352,14 @@ fun RestHighLevelClient.updateAutoFollowPattern(connection: String, patternName:
}""")
}
lowLevelRequest.setOptions(requestOptions)
val lowLevelResponse = lowLevelClient.performRequest(lowLevelRequest)
val response = getAckResponse(lowLevelResponse)
assertThat(response.isAcknowledged).isTrue()
try {
val lowLevelResponse = lowLevelClient.performRequest(lowLevelRequest)
val response = getAckResponse(lowLevelResponse)
assertThat(response.isAcknowledged).isTrue()
} catch (e: ResponseException) {
// Skip if ignoreIfExists is true and exception contains resource_already_exists_exception
if ((ignoreIfExists == true && e.message?.contains("resource_already_exists_exception")!!) == false) throw e
}
}

fun RestHighLevelClient.AutoFollowStats() : Map<String, Any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() {
// Add replication start block
followerClient.updateReplicationStartBlockSetting(true)
createRandomIndex(leaderClient)
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern)
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, indexPattern, ignoreIfExists=true)
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 Expand Up @@ -525,7 +525,11 @@ class UpdateAutoFollowPatternIT: MultiClusterRestTestCase() {

private fun assertValidPatternValidation(followerClient: RestHighLevelClient, pattern: String) {
Assertions.assertThatCode {
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, pattern)
try {
followerClient.updateAutoFollowPattern(connectionAlias, indexPatternName, pattern)
} finally {
followerClient.deleteAutoFollowPattern(connectionAlias, indexPatternName)
}
}.doesNotThrowAnyException()
}

Expand Down
Loading