You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 22:41:38 UTC
[12/18] git commit: Pass through responses and errors directly
Pass through responses and errors directly
There was a bit of a mismatch in the behavior of ddoc_cache:open/2 and
fabric:open_doc/3. This just makes sure that return values are returned
and any exceptions are reraised with the same semantics of
throw/error/exit as they were generated.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/cb9906ca
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/cb9906ca
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/cb9906ca
Branch: refs/heads/import
Commit: cb9906ca577347150037021a9d410ba2839b26ba
Parents: 8bd9ba6
Author: Paul J. Davis <pa...@gmail.com>
Authored: Tue Jan 29 17:09:52 2013 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Tue Jan 29 17:12:19 2013 -0600
----------------------------------------------------------------------
src/ddoc_cache.erl | 10 +++++++---
src/ddoc_cache_opener.erl | 20 ++++++++++----------
2 files changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/cb9906ca/src/ddoc_cache.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache.erl b/src/ddoc_cache.erl
index 48cfcdc..35aa610 100644
--- a/src/ddoc_cache.erl
+++ b/src/ddoc_cache.erl
@@ -40,10 +40,14 @@ open(Key) ->
_ ->
margaret_counter:increment([ddoc_cache, miss]),
case gen_server:call(?OPENER, {open, Key}, infinity) of
- {ok, _} = Resp ->
+ {open_ok, Resp} ->
Resp;
- Else ->
- throw(Else)
+ {open_error, throw, Error} ->
+ throw(Error);
+ {open_error, error, Error} ->
+ erlang:error(Error);
+ {open_error, exit, Error} ->
+ exit(Error)
end
catch
error:badarg ->
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/cb9906ca/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index 5a899b0..4f8eb65 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -120,12 +120,12 @@ handle_info({'EXIT', Pid, Reason}, #st{evictor=Pid}=St) ->
{ok, Evictor} = couch_db_update_notifier:start_link(fun ?MODULE:evictor/1),
{noreply, St#st{evictor=Evictor}};
-handle_info({'EXIT', _Pid, {ddoc_ok, Key, Doc}}, St) ->
- respond(Key, {ok, Doc}),
+handle_info({'EXIT', _Pid, {open_ok, Key, Resp}}, St) ->
+ respond(Key, {open_ok, Resp}),
{noreply, St};
-handle_info({'EXIT', _Pid, {ddoc_error, Key, Error}}, St) ->
- respond(Key, Error),
+handle_info({'EXIT', _Pid, {open_error, Key, Type, Error}}, St) ->
+ respond(Key, {open_error, Type, Error}),
{noreply, St};
handle_info({'EXIT', Pid, Reason}, St) ->
@@ -166,17 +166,17 @@ open_ddoc({DbName, validation_funs}=Key) ->
end
end, DDocs),
ok = ets_lru:insert(ddoc_cache_lru, {DbName, validation_funs}, Funs),
- exit({ddoc_ok, Key, Funs});
+ exit({open_ok, Key, Funs});
open_ddoc({DbName, DDocId}=Key) ->
try fabric:open_doc(DbName, DDocId, []) of
{ok, Doc} ->
ok = ets_lru:insert(ddoc_cache_lru, {DbName, DDocId}, Doc),
- exit({ddoc_ok, Key, Doc})
+ exit({open_ok, Key, {ok, Doc}});
+ Else ->
+ exit({open_ok, Key, Else})
catch
- error:database_not_found ->
- exit({ddoc_error, Key, database_not_found});
- _Type:Reason ->
- exit({ddoc_error, Key, Reason})
+ Type:Reason ->
+ exit({open_error, Key, Type, Reason})
end.