couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r821402 - /couchdb/trunk/src/couchdb/couch_uuids.erl
Date Sat, 03 Oct 2009 19:53:04 GMT
Author: davisp
Date: Sat Oct  3 19:53:03 2009
New Revision: 821402

URL: http://svn.apache.org/viewvc?rev=821402&view=rev
Log:
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.


Modified:
    couchdb/trunk/src/couchdb/couch_uuids.erl

Modified: couchdb/trunk/src/couchdb/couch_uuids.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_uuids.erl?rev=821402&r1=821401&r2=821402&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_uuids.erl (original)
+++ couchdb/trunk/src/couchdb/couch_uuids.erl Sat Oct  3 19:53:03 2009
@@ -41,18 +41,10 @@
     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 @@
             {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 @@
 
 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.



Mime
View raw message