diff options
author | Peng Hui Jiang <jiangphcn@apache.org> | 2019-02-21 21:07:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-21 21:07:29 +0800 |
commit | b7577b2d947aaf7616e38944926f219b14ec341f (patch) | |
tree | 6b915e8aaf07d9c36edd687e80ea2d449673da38 | |
parent | c3d67179b7a53cad4e2f83da20844ba8de3c04bd (diff) | |
parent | dbdddb2d3b54a03b049d793f38b27d565254aec6 (diff) | |
download | couchdb-b7577b2d947aaf7616e38944926f219b14ec341f.tar.gz |
Merge pull request #1925 from apache/allow-list-for-purge-docid
Support list for docid when using couch_db:purge_docs/3
-rw-r--r-- | src/couch/src/couch_db.erl | 8 | ||||
-rw-r--r-- | src/couch_mrview/test/couch_mrview_purge_docs_tests.erl | 69 |
2 files changed, 74 insertions, 3 deletions
diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl index 74f4a099d..bdb9dfeca 100644 --- a/src/couch/src/couch_db.erl +++ b/src/couch/src/couch_db.erl @@ -407,16 +407,18 @@ purge_docs(Db, IdRevs) -> -spec purge_docs(#db{}, [{UUId, Id, [Rev]}], [PurgeOption]) -> {ok, [Reply]} when UUId :: binary(), - Id :: binary(), + Id :: binary() | list(), Rev :: {non_neg_integer(), binary()}, PurgeOption :: interactive_edit | replicated_changes, Reply :: {ok, []} | {ok, [Rev]}. purge_docs(#db{main_pid = Pid} = Db, UUIDsIdsRevs, Options) -> + UUIDsIdsRevs2 = [{UUID, couch_util:to_binary(Id), Revs} + || {UUID, Id, Revs} <- UUIDsIdsRevs], % Check here if any UUIDs already exist when % we're not replicating purge infos IsRepl = lists:member(replicated_changes, Options), if IsRepl -> ok; true -> - UUIDs = [UUID || {UUID, _, _} <- UUIDsIdsRevs], + UUIDs = [UUID || {UUID, _, _} <- UUIDsIdsRevs2], lists:foreach(fun(Resp) -> if Resp == not_found -> ok; true -> Fmt = "Duplicate purge info UIUD: ~s", @@ -426,7 +428,7 @@ purge_docs(#db{main_pid = Pid} = Db, UUIDsIdsRevs, Options) -> end, get_purge_infos(Db, UUIDs)) end, increment_stat(Db, [couchdb, database_purges]), - gen_server:call(Pid, {purge_docs, UUIDsIdsRevs, Options}). + gen_server:call(Pid, {purge_docs, UUIDsIdsRevs2, Options}). -spec get_purge_infos(#db{}, [UUId]) -> [PurgeInfo] when UUId :: binary(), diff --git a/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl b/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl index eb180b005..1020607a4 100644 --- a/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl +++ b/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl @@ -48,6 +48,8 @@ view_purge_test_() -> fun test_purge_nochange/1, fun test_purge_index_reset/1, fun test_purge_compact_size_check/1, + fun test_purge_single_for_docid_with_list/1, + fun test_purge_complete_for_docid_with_list/1, fun test_purge_compact_for_stale_purge_cp_without_client/1, fun test_purge_compact_for_stale_purge_cp_with_client/1 ] @@ -89,6 +91,38 @@ test_purge_single(Db) -> end). +test_purge_single_for_docid_with_list(Db) -> + ?_test(begin + Result = run_query(Db, []), + Expect = {ok, [ + {meta, [{total, 5}, {offset, 0}]}, + {row, [{id, <<"1">>}, {key, 1}, {value, 1}]}, + {row, [{id, <<"2">>}, {key, 2}, {value, 2}]}, + {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}, + {row, [{id, <<"4">>}, {key, 4}, {value, 4}]}, + {row, [{id, <<"5">>}, {key, 5}, {value, 5}]} + ]}, + ?assertEqual(Expect, Result), + + FDI = couch_db:get_full_doc_info(Db, <<"1">>), + Rev = get_rev(FDI), + {ok, [{ok, _PRevs}]} = couch_db:purge_docs( + Db, + [{<<"UUID1">>, "1", [Rev]}] + ), + {ok, Db2} = couch_db:reopen(Db), + + Result2 = run_query(Db2, []), + Expect2 = {ok, [ + {meta, [{total, 4}, {offset, 0}]}, + {row, [{id, <<"2">>}, {key, 2}, {value, 2}]}, + {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}, + {row, [{id, <<"4">>}, {key, 4}, {value, 4}]}, + {row, [{id, <<"5">>}, {key, 5}, {value, 5}]} + ]}, + ?assertEqual(Expect2, Result2) + end). + test_purge_partial(Db) -> ?_test(begin Result = run_query(Db, []), @@ -163,6 +197,41 @@ test_purge_complete(Db) -> end). +test_purge_complete_for_docid_with_list(Db) -> + ?_test(begin + Result = run_query(Db, []), + Expect = {ok, [ + {meta, [{total, 5}, {offset, 0}]}, + {row, [{id, <<"1">>}, {key, 1}, {value, 1}]}, + {row, [{id, <<"2">>}, {key, 2}, {value, 2}]}, + {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}, + {row, [{id, <<"4">>}, {key, 4}, {value, 4}]}, + {row, [{id, <<"5">>}, {key, 5}, {value, 5}]} + ]}, + ?assertEqual(Expect, Result), + + FDI1 = couch_db:get_full_doc_info(Db, <<"1">>), Rev1 = get_rev(FDI1), + FDI2 = couch_db:get_full_doc_info(Db, <<"2">>), Rev2 = get_rev(FDI2), + FDI5 = couch_db:get_full_doc_info(Db, <<"5">>), Rev5 = get_rev(FDI5), + + PurgeInfos = [ + {<<"UUID1">>, "1", [Rev1]}, + {<<"UUID2">>, "2", [Rev2]}, + {<<"UUID5">>, "5", [Rev5]} + ], + {ok, _} = couch_db:purge_docs(Db, PurgeInfos), + {ok, Db2} = couch_db:reopen(Db), + + Result2 = run_query(Db2, []), + Expect2 = {ok, [ + {meta, [{total, 2}, {offset, 0}]}, + {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}, + {row, [{id, <<"4">>}, {key, 4}, {value, 4}]} + ]}, + ?assertEqual(Expect2, Result2) + end). + + test_purge_nochange(Db) -> ?_test(begin Result = run_query(Db, []), |