opensearch-project / cross-cluster-replication

Synchronize your data across multiple clusters for lower latencies and higher availability
https://opensearch.org/docs/latest/replication-plugin/index/
Apache License 2.0
47 stars 57 forks source link

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

Closed skumarp7 closed 4 months ago

skumarp7 commented 4 months ago

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

https://github.com/opensearch-project/cross-cluster-replication/issues/1370

Check List

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.

skumarp7 commented 4 months ago

Hi @monusingh-1 ,

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

 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
                    }