From e77934418082facf6c4b3566100b108b26e4119d Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Tue, 13 Oct 2015 17:02:59 +0200 Subject: Move timeouts to separate include file --- src/db.erl | 3 ++- src/fsdb.erl | 4 +++- src/ht.erl | 3 ++- src/plop.erl | 3 ++- src/sign.erl | 4 +++- src/timeouts.hrl | 9 +++++++++ src/util.erl | 4 +++- 7 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 src/timeouts.hrl diff --git a/src/db.erl b/src/db.erl index 5ad49ec..25d2fc0 100644 --- a/src/db.erl +++ b/src/db.erl @@ -22,6 +22,7 @@ -import(stacktrace, [call/2]). -include_lib("stdlib/include/qlc.hrl"). -include("db.hrl"). +-include("timeouts.hrl"). -define(DB_SIZE_TABLE, db_size). @@ -239,7 +240,7 @@ indexforhash_nosync(LeafHash, Index) -> ok. indexforhash_dosync() -> - perm:commit(indexforhash_db, 300000), + perm:commit(indexforhash_db, ?SYNC_INDEXFORHASH_TIMEOUT), ok. index_sync() -> diff --git a/src/fsdb.erl b/src/fsdb.erl index 3e1b9b9..4a85cdc 100644 --- a/src/fsdb.erl +++ b/src/fsdb.erl @@ -13,6 +13,8 @@ -record(state, {name, dirtylistname}). +-include("timeouts.hrl"). + -define(DIRECTORY_TABLE, perm_directory). init_module() -> @@ -75,7 +77,7 @@ addvalue(Name, Key, Value) -> Result. commit(Name) -> - commit(Name, 5000). + commit(Name, ?FSDB_COMMIT_DEFAULT_TIMEOUT). commit(Name, Timeout) -> gen_server:call(Name, {commit, Timeout}, Timeout). diff --git a/src/ht.erl b/src/ht.erl index 5d56bad..87090f0 100644 --- a/src/ht.erl +++ b/src/ht.erl @@ -38,6 +38,7 @@ -import(stacktrace, [call/2, call/3]). -include_lib("eunit/include/eunit.hrl"). -import(lists, [foreach/2, foldl/3, reverse/1]). +-include("timeouts.hrl"). -define(MAX_READ_ENTRIES, 10000). -define(MAX_CALC_ENTRIES, 10000). @@ -57,7 +58,7 @@ start_link(NEntries) -> reset_tree(Arg) -> call(?MODULE, {reset_tree, Arg}, infinity). load_tree(Version) -> - case call(?MODULE, {load_tree, Version}, 30000) of + case call(?MODULE, {load_tree, Version}, ?HT_LOAD_TREE_TIMEOUT) of eagain -> load_tree(Version); Result -> diff --git a/src/plop.erl b/src/plop.erl index b812e4a..8bde3db 100644 --- a/src/plop.erl +++ b/src/plop.erl @@ -34,6 +34,7 @@ -import(stacktrace, [call/2]). -include("plop.hrl"). %%-include("db.hrl"). +-include("timeouts.hrl"). -include_lib("public_key/include/public_key.hrl"). %%%%% moved from plop.hrl, maybe remove @@ -279,7 +280,7 @@ store_loop(TreeLeafHash, Requests, RepliesUntilQuorum) -> end end after - 2000 -> + ?PLOP_STORAGE_QUORUM_TIMEOUT -> lager:error("leafhash ~s: storage failed: " ++ "~p replies until quorum, nodes left: ~p", [mochihex:to_hex(TreeLeafHash), RepliesUntilQuorum, diff --git a/src/sign.erl b/src/sign.erl index 5949ad1..ced218a 100644 --- a/src/sign.erl +++ b/src/sign.erl @@ -16,6 +16,8 @@ -export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2, code_change/3]). +-include("timeouts.hrl"). + -define(CERTIFICATE_TIMESTAMP, 0). -define(TREE_HASH, 1). @@ -241,7 +243,7 @@ handle_call({sign, Data}, _From, State) -> [Port, ExitStatus]), {stop, portexit, State} after - 10000 -> + ?SIGN_HSM_PORT_TIMEOUT -> lager:error("HSM timeout"), {stop, timeout, State} end diff --git a/src/timeouts.hrl b/src/timeouts.hrl new file mode 100644 index 0000000..41ee008 --- /dev/null +++ b/src/timeouts.hrl @@ -0,0 +1,9 @@ +%%% Copyright (c) 2014, NORDUnet A/S. +%%% See LICENSE for licensing information. + +-define(SYNC_INDEXFORHASH_TIMEOUT, 300000). +-define(FSDB_COMMIT_DEFAULT_TIMEOUT, 5000). +-define(HT_LOAD_TREE_TIMEOUT, 30000). +-define(PLOP_STORAGE_QUORUM_TIMEOUT, 2000). +-define(SIGN_HSM_PORT_TIMEOUT, 10000). +-define(UTIL_FSYNC_DEFAULT_TIMEOUT, 5000). diff --git a/src/util.erl b/src/util.erl index af78b93..8a8152a 100644 --- a/src/util.erl +++ b/src/util.erl @@ -6,6 +6,8 @@ check_error/3, write_tempfile_and_rename/3, spawn_and_wait/1, parallel_map/3]). +-include("timeouts.hrl"). + -spec tempfilename(string()) -> string(). tempfilename(Base) -> {MegaSecs, Secs, MicroSecs} = now(), @@ -23,7 +25,7 @@ fsync(Paths, Timeout) -> end. fsync(Paths) -> - fsync(Paths, 5000). + fsync(Paths, ?UTIL_FSYNC_DEFAULT_TIMEOUT). -spec exit_with_error(atom(), atom(), string()) -> no_return(). exit_with_error(Operation, Error, ErrorMessage) -> -- cgit v1.1