diff options
author | jiangph <jiangph@cn.ibm.com> | 2018-10-24 08:52:54 +0800 |
---|---|---|
committer | jiangph <jiangph@cn.ibm.com> | 2018-10-24 14:43:36 +0800 |
commit | 3ac1aca98737b7f986b7efb9ed10f474821fa01f (patch) | |
tree | 0ddbfd960ead7194aeb8b144776a21d5f43ab250 | |
parent | c3069d17f1e90c7b020d9bbe1f15f5af5408fb8b (diff) | |
download | couchdb-COUCHDB-3326-mixed-cluster.tar.gz |
Allow to return with accepted for mixed nodes in clusterCOUCHDB-3326-mixed-cluster
- for mixed nodes in cluster, i.e. nodes with different releases,
it is possible that "accepted" result is returned instead of ok when
purge request is sent. This commit is used to address badmatch error
where "accepted" returned result is not considered.
COUCHDB-3326
-rw-r--r-- | src/chttpd/src/chttpd_db.erl | 7 | ||||
-rw-r--r-- | src/chttpd/test/chttpd_purge_tests.erl | 33 |
2 files changed, 38 insertions, 2 deletions
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl index bd01b93bd..f95c3e794 100644 --- a/src/chttpd/src/chttpd_db.erl +++ b/src/chttpd/src/chttpd_db.erl @@ -524,8 +524,11 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_purge">>]}=Req, Db) -> true -> ok end, couch_stats:increment_counter([couchdb, document_purges, total], length(IdsRevs2)), - {ok, Results} = fabric:purge_docs(Db, IdsRevs2, Options), - {Code, Json} = purge_results_to_json(IdsRevs2, Results), + Results2 = case fabric:purge_docs(Db, IdsRevs2, Options) of + {ok, Results} -> Results; + {accepted, Results} -> Results + end, + {Code, Json} = purge_results_to_json(IdsRevs2, Results2), send_json(Req, Code, {[{<<"purge_seq">>, null}, {<<"purged">>, {Json}}]}); db_req(#httpd{path_parts=[_,<<"_purge">>]}=Req, _Db) -> diff --git a/src/chttpd/test/chttpd_purge_tests.erl b/src/chttpd/test/chttpd_purge_tests.erl index 686552590..af1bd0b1c 100644 --- a/src/chttpd/test/chttpd_purge_tests.erl +++ b/src/chttpd/test/chttpd_purge_tests.erl @@ -70,6 +70,7 @@ purge_test_() -> [ fun test_empty_purge_request/1, fun test_ok_purge_request/1, + fun test_accepted_purge_request/1, fun test_partial_purge_request/1, fun test_mixed_purge_request/1, fun test_overmany_ids_or_revs_purge_request/1, @@ -135,6 +136,38 @@ test_ok_purge_request(Url) -> end). +test_accepted_purge_request(Url) -> + ?_test(begin + {ok, _, _, Body} = create_doc(Url, "doc1"), + {Json} = ?JSON_DECODE(Body), + Rev1 = couch_util:get_value(<<"rev">>, Json, undefined), + IdsRevsEJson = {[ + {<<"doc1">>, [Rev1]} + ]}, + IdsRevs = binary_to_list(?JSON_ENCODE(IdsRevsEJson)), + meck:new(fabric, [passthrough]), + meck:expect(fabric, purge_docs, + fun(_, _, _) -> {accepted,[{accepted,[{1, + <<57,27,64,134,152,18,73,243,40,1,141,214,135,104,79,188>>}]}]} + end + ), + {ok, Status, _, ResultBody} = test_request:post(Url ++ "/_purge/", + [?CONTENT_JSON, ?AUTH], IdsRevs), + ResultJson = ?JSON_DECODE(ResultBody), + meck:unload(fabric), + ?assert(Status =:= 202), + ?assertEqual( + {[ + {<<"purge_seq">>, null}, + {<<"purged">>, {[ + {<<"doc1">>, [Rev1]} + ]}} + ]}, + ResultJson + ) + end). + + test_partial_purge_request(Url) -> ?_test(begin {ok, _, _, Body} = create_doc(Url, "doc1"), |