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

Fix to handle the exception for deletion of non-existing autofollow replication rule #1371

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

skumarp7
Copy link
Contributor

Description

This PR handles the exception for deletion of any non-existing replication rule.

Earlier behaviour:

If any replication rule is tried to be deleted before creation of the first replication rule, it throws ResourceNotFoundException.

ex:

Directly delete the autofollow replication rule before creation of any autofollow rule.

curl -Method DELETE -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-Type' = 'application/json'} -body '{"leader_alias":"leader", "name": "dummy"}'

curl : { "error" : { "root_cause" : [ { "type" : "resource_not_found_exception", "reason" : "Metadata for leader:dummy doesn't exist" } ],     
"type" : "resource_not_found_exception", "reason" : "Metadata for leader:dummy doesn't exist" }, "status" : 404 } 

Now, create a new replication rule 'A' and try to delete replication rule 'B'. Here we could see that there is a successful response in deleting a non-existing replication rule.

curl -Method POST -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-Typ
e' = 'application/json'} -body '{"leader_alias":"leader", "name": "test", "pattern": "test-*"}'                   

StatusCode        : 200
StatusDescription : OK
Content           : {
                      "acknowledged" : true
                    }

curl -Method DELETE -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-T
ype' = 'application/json'} -body '{"leader_alias":"leader", "name": "dummy"}'                             


StatusCode        : 200
StatusDescription : OK
Content           : {
                      "acknowledged" : true
                    }

Behaviour now:

Deletion of any non existing replication rule.

curl -Method DELETE -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-T
ype' = 'application/json'} -body '{"leader_alias":"leader", "name": "test"}'       
curl : { "error" : { "root_cause" : [ { "type" : "exception", "reason" : "Autofollow replication rule :leader:test does not exist" } ], "type" : "exception", 
"reason" : "Autofollow replication rule :leader:test does not exist" }, "status" : 500 }

Issues Resolved

#1370

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Collaborator

@monusingh-1 monusingh-1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl -Method DELETE -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-T
ype' = 'application/json'} -body '{"leader_alias":"leader", "name": "dummy"}'                             


StatusCode        : 200
StatusDescription : OK
Content           : {
                      "acknowledged" : true
                    }
  • From description

Can you confirm if you are getting 200 and not ResourceNotFoundException ?

@skumarp7
Copy link
Contributor Author

Hi @monusingh-1 ,

Yes, the current behaviour as of now is as below:

  • Delete a non existing replication rule before the creation of any autofollow rule, then it returns 404
 curl -Method DELETE -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-T
ype' = 'application/json'} -body '{"leader_alias":"leader", "name": "test1"}'       
curl : { "error" : { "root_cause" : [ { "type" : "resource_not_found_exception", "reason" : "Metadata for leader:test1 doesn't exist" } ], "type" : 
"resource_not_found_exception", "reason" : "Metadata for leader:test1 doesn't exist" }, "status" : 404 }

But if there is any replication rule already there :

a) Create a replication rule "leader:test1"

curl -Method POST -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-Typ
e' = 'application/json'} -body '{"leader_alias":"leader", "name": "test1", "pattern": "test1"}'


StatusCode        : 200
StatusDescription : OK
Content           : {
                      "acknowledged" : true
                    }

b) Delete a non existing rule (say "leader:test2"), then the deletion of that replication rule returns 200.

  curl -Method DELETE -Uri "http://localhost:9201/_plugins/_replication/_autofollow?pretty"  -H @{'Content-T
ype' = 'application/json'} -body '{"leader_alias":"leader", "name": "test2"}'                                  


StatusCode        : 200
StatusDescription : OK
Content           : {
                      "acknowledged" : true
                    }

@monusingh-1 monusingh-1 enabled auto-merge (squash) April 22, 2024 16:31
Copy link
Member

@ankitkala ankitkala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! LGTM.

@monusingh-1 monusingh-1 merged commit d404742 into opensearch-project:main Apr 23, 2024
14 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 23, 2024
…le (#1371)

Signed-off-by: Sanjay Kumar <[email protected]>
(cherry picked from commit d404742)
@skumarp7 skumarp7 deleted the deleteApiPatch branch April 23, 2024 06:21
monusingh-1 pushed a commit that referenced this pull request Apr 25, 2024
…le (#1371) (#1372)

Signed-off-by: Sanjay Kumar <[email protected]>
(cherry picked from commit d404742)

Co-authored-by: Sanjay Kumar <[email protected]>
skumarp7 added a commit to nokia/opensearch-project-cross-cluster-replication that referenced this pull request Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants