summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Kocoloski <adam@cloudant.com>2010-07-13 19:48:07 -0400
committerAdam Kocoloski <adam@cloudant.com>2010-07-13 19:48:32 -0400
commit0df44a1122d7fd99f96992946692737361941b64 (patch)
tree03fce95961c7729120fe831f04725add30baeaa8 /src
parent3dd9e521192458002efc7ddaaa7455bcc549afd6 (diff)
return an informative error if user tries unsupported all_or_nothing option
Diffstat (limited to 'src')
-rw-r--r--src/fabric.erl5
-rw-r--r--src/fabric_doc_update.erl16
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}).