diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2018-04-27 13:22:38 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2018-04-27 13:22:38 -0500 |
commit | afc0aebb9024758d76f670087b4ace8d44e4bf98 (patch) | |
tree | 3316b0b714ab46609c475991ccb34d4de58420e9 | |
parent | e666e7c8efe48497209bd67c7b0bffeb6f3b7550 (diff) | |
download | couchdb-afc0aebb9024758d76f670087b4ace8d44e4bf98.tar.gz |
[SQUERGE] Throw error on duplicate UUIDs
Unless we're replicating purge infos its an error to repeat a UUID.
Squerge to implement APIs
-rw-r--r-- | src/couch/src/couch_db.erl | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl index 07feab001..cefe993f3 100644 --- a/src/couch/src/couch_db.erl +++ b/src/couch/src/couch_db.erl @@ -389,9 +389,22 @@ purge_docs(Db, IdRevs) -> Rev :: {non_neg_integer(), binary()}, PurgeOption :: interactive_edit | replicated_changes, Reply :: {ok, []} | {ok, [Rev]}. -purge_docs(#db{main_pid = Pid} = Db, UUIdsIdsRevs, Options) -> +purge_docs(#db{main_pid = Pid} = Db, UUIDsIdsRevs, Options) -> + % 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], + lists:foreach(fun(Resp) -> + if Resp == not_found -> ok; true -> + Fmt = "Duplicate purge info UIUD: ~s", + Reason = io_lib:format(Fmt, [element(2, Resp)]), + throw({badreq, Reason}) + end + 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, UUIDsIdsRevs, Options}). -spec get_purge_infos(#db{}, [UUId]) -> [PurgeInfo] when UUId :: binary(), |