summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2014-11-04 12:45:39 +0100
committerLinus Nordberg <linus@nordberg.se>2014-11-04 12:45:39 +0100
commit90754940d8d86c34d7a0039a6e798e22e43fdc81 (patch)
tree3bec890e196a2ee23631cdfe7996503f55b54972
parentbbcb238f5232fc29da7d4cb215d2316bd4421b8c (diff)
Invoke gen_server:call/2 via stacktrace:call/2.
stacktrace:call() logs an error if the gen_server:call() throws timeout.
-rw-r--r--src/db.erl21
-rw-r--r--src/ht.erl25
-rw-r--r--src/plop.erl23
-rw-r--r--src/stacktrace.erl18
4 files changed, 54 insertions, 33 deletions
diff --git a/src/db.erl b/src/db.erl
index 60c4d30..943c70e 100644
--- a/src/db.erl
+++ b/src/db.erl
@@ -14,6 +14,7 @@
-export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2,
code_change/3]).
+-import(stacktrace, [call/2]).
-include_lib("stdlib/include/qlc.hrl").
-include("db.hrl").
@@ -30,50 +31,50 @@ start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
stop() ->
- gen_server:call(?MODULE, stop).
+ call(?MODULE, stop).
%%%%%%%%%%%%%%%%%%%%
%% Public API.
-spec add(binary(), binary(), binary(), non_neg_integer()) -> ok.
add(LeafHash, EntryHash, Data, Index) ->
- gen_server:call(?MODULE, {add, {LeafHash, EntryHash, Data, Index}}).
+ call(?MODULE, {add, {LeafHash, EntryHash, Data, Index}}).
-spec add(binary(), binary()) -> ok.
add(LeafHash, Data) ->
- gen_server:call(?MODULE, {add, {LeafHash, Data}}).
+ call(?MODULE, {add, {LeafHash, Data}}).
-spec add_entryhash(binary(), binary()) -> ok.
add_entryhash(LeafHash, EntryHash) ->
- gen_server:call(?MODULE, {add_entryhash, {LeafHash, EntryHash}}).
+ call(?MODULE, {add_entryhash, {LeafHash, EntryHash}}).
-spec add_index(binary(), non_neg_integer()) -> ok.
add_index(LeafHash, Index) ->
- gen_server:call(?MODULE, {add_index, {LeafHash, Index}}).
+ call(?MODULE, {add_index, {LeafHash, Index}}).
-spec set_treesize(non_neg_integer()) -> ok.
set_treesize(Size) ->
- gen_server:call(?MODULE, {set_treesize, Size}).
+ call(?MODULE, {set_treesize, Size}).
-spec get_by_indices(integer(), integer(), {sorted, true|false}) ->
[{non_neg_integer(), binary(), binary()}].
get_by_indices(Start, End, {sorted, Sorted}) ->
- gen_server:call(?MODULE, {get_by_indices, {Start, End, Sorted}}).
+ call(?MODULE, {get_by_indices, {Start, End, Sorted}}).
-spec get_by_index(binary()) -> notfound |
{non_neg_integer(), binary(), binary()}.
get_by_index(Index) ->
- gen_server:call(?MODULE, {get_by_index, Index}).
+ call(?MODULE, {get_by_index, Index}).
-spec get_by_leaf_hash(binary()) -> notfound |
{non_neg_integer(), binary(), binary()}.
get_by_leaf_hash(LeafHash) ->
- gen_server:call(?MODULE, {get_by_leaf_hash, LeafHash}).
+ call(?MODULE, {get_by_leaf_hash, LeafHash}).
-spec get_by_entry_hash(binary()) -> notfound |
{non_neg_integer(), binary(), binary()}.
get_by_entry_hash(EntryHash) ->
- gen_server:call(?MODULE, {get_by_entry_hash, EntryHash}).
+ call(?MODULE, {get_by_entry_hash, EntryHash}).
%%%%%%%%%%%%%%%%%%%%
%% gen_server callbacks.
diff --git a/src/ht.erl b/src/ht.erl
index 12ce4e3..b4c7401 100644
--- a/src/ht.erl
+++ b/src/ht.erl
@@ -35,6 +35,7 @@
code_change/3]).
-export([testing_get_state/0, print_tree/0, print_tree/1]).
+-import(stacktrace, [call/2]).
-include_lib("eunit/include/eunit.hrl").
-import(lists, [foreach/2, foldl/3, reverse/1]).
@@ -51,30 +52,30 @@ start_link() ->
start_link(NEntries) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [NEntries], []).
reset_tree(Arg) ->
- gen_server:call(?MODULE, {reset_tree, Arg}).
+ call(?MODULE, {reset_tree, Arg}).
stop() ->
- gen_server:call(?MODULE, stop).
+ call(?MODULE, stop).
size() ->
- gen_server:call(?MODULE, size).
+ call(?MODULE, size).
add(Hash) ->
- gen_server:call(?MODULE, {add, Hash}).
+ call(?MODULE, {add, Hash}).
root() ->
- gen_server:call(?MODULE, root).
+ call(?MODULE, root).
root(Version) ->
- gen_server:call(?MODULE, {root, Version}).
+ call(?MODULE, {root, Version}).
path(I, V) ->
- gen_server:call(?MODULE, {path, I, V}).
+ call(?MODULE, {path, I, V}).
consistency(V1, V2) ->
- gen_server:call(?MODULE, {consistency, V1, V2}).
+ call(?MODULE, {consistency, V1, V2}).
leaf_hash(Data) ->
- gen_server:call(?MODULE, {leaf_hash, Data}).
+ call(?MODULE, {leaf_hash, Data}).
%% Testing and debugging.
testing_get_state() ->
- gen_server:call(?MODULE, testing_get_state).
+ call(?MODULE, testing_get_state).
print_tree() ->
- gen_server:call(?MODULE, {print_tree, 4}).
+ call(?MODULE, {print_tree, 4}).
print_tree(HashOutputLen) ->
- gen_server:call(?MODULE, {print_tree, HashOutputLen}).
+ call(?MODULE, {print_tree, HashOutputLen}).
%% gen_server callbacks
init(Args) ->
diff --git a/src/plop.erl b/src/plop.erl
index 0c85b21..d363582 100644
--- a/src/plop.erl
+++ b/src/plop.erl
@@ -35,6 +35,7 @@
-export([init/1, handle_call/3, terminate/2,
handle_cast/2, handle_info/2, code_change/3]).
+-import(stacktrace, [call/2]).
-include("plop.hrl").
%%-include("db.hrl").
-include_lib("public_key/include/public_key.hrl").
@@ -71,7 +72,7 @@ start_link(Keyfile, Passphrase) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [Keyfile, Passphrase], []).
stop() ->
- gen_server:call(?MODULE, stop).
+ call(?MODULE, stop).
add_http_request(Plop, RequestId, Data) ->
Plop#state{http_requests = dict:store(RequestId, Data,
@@ -156,38 +157,38 @@ terminate(_Reason, _State) ->
%%%%%%%%%%%%%%%%%%%%
-spec add(binary(), binary(), binary()) -> ok.
add(LogEntry, TreeLeafHash, EntryHash) ->
- gen_server:call(?MODULE,
+ call(?MODULE,
{add, {LogEntry, TreeLeafHash, EntryHash}}).
sth() ->
- gen_server:call(?MODULE, {sth, []}).
+ call(?MODULE, {sth, []}).
-spec get(non_neg_integer(), non_neg_integer()) ->
[{non_neg_integer(), binary(), binary()}].
get(Start, End) ->
- gen_server:call(?MODULE, {get, {index, Start, End}}).
+ call(?MODULE, {get, {index, Start, End}}).
get(Hash) ->
- gen_server:call(?MODULE, {get, {hash, Hash}}).
+ call(?MODULE, {get, {hash, Hash}}).
spt(Data) ->
- gen_server:call(?MODULE, {spt, Data}).
+ call(?MODULE, {spt, Data}).
consistency(TreeSizeFirst, TreeSizeSecond) ->
- gen_server:call(?MODULE, {consistency, {TreeSizeFirst, TreeSizeSecond}}).
+ call(?MODULE, {consistency, {TreeSizeFirst, TreeSizeSecond}}).
-spec inclusion(binary(), non_neg_integer()) ->
{ok, {binary(), binary()}} | {notfound, string()}.
inclusion(Hash, TreeSize) ->
- gen_server:call(?MODULE, {inclusion, {Hash, TreeSize}}).
+ call(?MODULE, {inclusion, {Hash, TreeSize}}).
-spec inclusion_and_entry(non_neg_integer(), non_neg_integer()) ->
{ok, {binary(), binary()}} |
{notfound, string()}.
inclusion_and_entry(Index, TreeSize) ->
- gen_server:call(?MODULE, {inclusion_and_entry, {Index, TreeSize}}).
+ call(?MODULE, {inclusion_and_entry, {Index, TreeSize}}).
get_logid() ->
- gen_server:call(?MODULE, {get, logid}).
+ call(?MODULE, {get, logid}).
testing_get_pubkey() ->
- gen_server:call(?MODULE, {test, pubkey}).
+ call(?MODULE, {test, pubkey}).
storage_nodes() ->
application:get_env(plop, storage_nodes, []).
diff --git a/src/stacktrace.erl b/src/stacktrace.erl
new file mode 100644
index 0000000..3de4772
--- /dev/null
+++ b/src/stacktrace.erl
@@ -0,0 +1,18 @@
+%%% Copyright (c) 2014, NORDUnet A/S.
+%%% See LICENSE for licensing information.
+
+-module(stacktrace).
+-export([call/2]).
+
+call(Name, Request) ->
+ Result = (catch gen_server:call(Name, Request)),
+ case Result of
+ {'EXIT', {timeout, Details}} ->
+ {current_stacktrace, Stacktrace} =
+ erlang:process_info(whereis(Name), current_stacktrace),
+ lager:error("~p: timeout ~p: ~p", [Name, Details, Stacktrace]),
+ throw(Result);
+ _ ->
+ none
+ end,
+ Result.