summaryrefslogtreecommitdiff
path: root/src/couchdb
diff options
context:
space:
mode:
authorPaul Joseph Davis <davisp@apache.org>2009-10-03 19:53:03 +0000
committerPaul Joseph Davis <davisp@apache.org>2009-10-03 19:53:03 +0000
commitd6c411269c1159016c80ff6d244f1f9124f19329 (patch)
treea4c21d1efc57e0fc1c6188582893e7064bfe0739 /src/couchdb
parent7ccab9b164b008c32b4a35cd9524241c66069020 (diff)
Fixes COUCHDB-517 UUID server restarts.
Patch by Robert Newson to avoid restarting the UUID gen_server on configuration changes which leads to OTP supervisor shutdowns when exceeding the restart frequency. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@821402 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r--src/couchdb/couch_uuids.erl31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/couchdb/couch_uuids.erl b/src/couchdb/couch_uuids.erl
index 24d81aad..e1851e1d 100644
--- a/src/couchdb/couch_uuids.erl
+++ b/src/couchdb/couch_uuids.erl
@@ -41,18 +41,10 @@ utc_random() ->
list_to_binary(Prefix ++ couch_util:to_hex(crypto:rand_bytes(9))).
init([]) ->
- ok = couch_config:register(fun("uuids", _) -> ?MODULE:stop() end),
- AlgoStr = couch_config:get("uuids", "algorithm", "random"),
- case couch_util:to_existing_atom(AlgoStr) of
- random ->
- {ok, random};
- utc_random ->
- {ok, utc_random};
- sequential ->
- {ok, {sequential, new_prefix(), inc()}};
- Unknown ->
- throw({unknown_uuid_algorithm, Unknown})
- end.
+ ok = couch_config:register(
+ fun("uuids", _) -> gen_server:cast(?MODULE, change) end
+ ),
+ {ok, state()}.
terminate(_Reason, _State) ->
ok.
@@ -70,6 +62,8 @@ handle_call(create, _From, {sequential, Pref, Seq}) ->
{reply, Result, {sequential, Pref, Seq + inc()}}
end.
+handle_cast(change, _State) ->
+ {noreply, state()};
handle_cast(stop, State) ->
{stop, normal, State};
handle_cast(_Msg, State) ->
@@ -86,3 +80,16 @@ new_prefix() ->
inc() ->
crypto:rand_uniform(1, 16#ffe).
+
+state() ->
+ AlgoStr = couch_config:get("uuids", "algorithm", "random"),
+ case couch_util:to_existing_atom(AlgoStr) of
+ random ->
+ random;
+ utc_random ->
+ utc_random;
+ sequential ->
+ {sequential, new_prefix(), inc()};
+ Unknown ->
+ throw({unknown_uuid_algorithm, Unknown})
+ end.