From 0df44a1122d7fd99f96992946692737361941b64 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Tue, 13 Jul 2010 19:48:07 -0400 Subject: return an informative error if user tries unsupported all_or_nothing option --- src/fabric.erl | 5 ++++- src/fabric_doc_update.erl | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/fabric.erl b/src/fabric.erl index 9b74b691..5d03c5fa 100644 --- a/src/fabric.erl +++ b/src/fabric.erl @@ -82,7 +82,10 @@ update_doc(DbName, Doc, Options) -> end. update_docs(DbName, Docs, Options) -> - fabric_doc_update:go(dbname(DbName), docs(Docs), opts(Options)). + try fabric_doc_update:go(dbname(DbName), docs(Docs), opts(Options)) + catch {aborted, PreCommitFailures} -> + {aborted, PreCommitFailures} + end. att_receiver(Req, Length) -> fabric_doc_attachments:receiver(Req, Length). diff --git a/src/fabric_doc_update.erl b/src/fabric_doc_update.erl index f7a91d48..0898d96c 100644 --- a/src/fabric_doc_update.erl +++ b/src/fabric_doc_update.erl @@ -6,7 +6,9 @@ -include_lib("mem3/include/mem3.hrl"). -include_lib("couch/include/couch_db.hrl"). -go(DbName, AllDocs, Options) -> +go(DbName, AllDocs, Opts) -> + validate_atomic_update(DbName, AllDocs, lists:member(all_or_nothing, Opts)), + Options = lists:delete(all_or_nothing, Opts), GroupedDocs = lists:map(fun({#shard{name=Name, node=Node} = Shard, Docs}) -> Ref = rexi:cast(Node, {fabric_rpc, update_docs, [Name, Docs, Options]}), {Shard#shard{ref=Ref}, Docs} @@ -107,3 +109,15 @@ skip_message(Acc0) -> % TODO fix this {ok, Acc0}. +validate_atomic_update(_, _, false) -> + ok; +validate_atomic_update(_DbName, AllDocs, true) -> + % TODO actually perform the validation. This requires some hackery, we need + % to basically extract the prep_and_validate_updates function from couch_db + % and only run that, without actually writing in case of a success. + Error = {not_implemented, <<"all_or_nothing is not supported yet">>}, + PreCommitFailures = lists:map(fun(#doc{id=Id, revs = {Pos,Revs}}) -> + case Revs of [] -> RevId = <<>>; [RevId|_] -> ok end, + {{Id, {Pos, RevId}}, Error} + end, AllDocs), + throw({aborted, PreCommitFailures}). -- cgit v1.2.3