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 2009/06/09 02:56:35 UTC

svn commit: r782854 - in /couchdb/trunk: THANKS src/couchdb/couch_db_update_notifier.erl src/couchdb/couch_os_process.erl

Author: davisp
Date: Tue Jun  9 00:56:34 2009
New Revision: 782854

URL: http://svn.apache.org/viewvc?rev=782854&view=rev
Log:
Fixes COUCHDB-372

New couchspawnkillable requires update notifiers to expect a line of input to
be read back. Undeleting the couch_os_process:write/2 method that got
ixnayed. Now named send/2 and uses a gen_server:cast/2 to make it more
apparent on what's going on.

Thanks rnewson.


Modified:
    couchdb/trunk/THANKS
    couchdb/trunk/src/couchdb/couch_db_update_notifier.erl
    couchdb/trunk/src/couchdb/couch_os_process.erl

Modified: couchdb/trunk/THANKS
URL: http://svn.apache.org/viewvc/couchdb/trunk/THANKS?rev=782854&r1=782853&r2=782854&view=diff
==============================================================================
--- couchdb/trunk/THANKS (original)
+++ couchdb/trunk/THANKS Tue Jun  9 00:56:34 2009
@@ -29,5 +29,6 @@
  * Brian Candler <B....@pobox.com>
  * Brad Anderson <br...@sankatygroup.com>
  * Nick Gerakines <ni...@gerakines.net>
+ * Robert Newson <ro...@gmail.com>
 
 For a list of authors see the `AUTHORS` file.

Modified: couchdb/trunk/src/couchdb/couch_db_update_notifier.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_db_update_notifier.erl?rev=782854&r1=782853&r2=782854&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_db_update_notifier.erl (original)
+++ couchdb/trunk/src/couchdb/couch_db_update_notifier.erl Tue Jun  9 00:56:34 2009
@@ -37,7 +37,7 @@
     couch_event_sup:stop(Pid).
 
 init(Exec) when is_list(Exec) -> % an exe
-    couch_os_process:start_link(Exec, [], [stream, exit_status, hide]);
+    couch_os_process:start_link(Exec, []);
 init(Else) ->
     {ok, Else}.
 
@@ -55,7 +55,7 @@
     {ok, {Fun, FunAcc2}};
 handle_event({EventAtom, DbName}, Pid) ->
     Obj = {[{type, list_to_binary(atom_to_list(EventAtom))}, {db, DbName}]},
-    true = couch_os_process:write(Pid, Obj),
+    ok = couch_os_process:send(Pid, Obj),
     {ok, Pid}.
 
 handle_call(_Request, State) ->

Modified: couchdb/trunk/src/couchdb/couch_os_process.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_os_process.erl?rev=782854&r1=782853&r2=782854&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_os_process.erl (original)
+++ couchdb/trunk/src/couchdb/couch_os_process.erl Tue Jun  9 00:56:34 2009
@@ -15,7 +15,7 @@
 
 -export([start_link/1, start_link/2, start_link/3, stop/1]).
 -export([set_timeout/2, prompt/2]).
--export([writeline/2, readline/1, writejson/2, readjson/1]).
+-export([send/2, writeline/2, readline/1, writejson/2, readjson/1]).
 -export([init/1, terminate/2, handle_call/3, handle_cast/2, handle_info/2, code_change/3]).
 
 -include("couch_db.hrl").
@@ -44,6 +44,10 @@
 set_timeout(Pid, TimeOut) when is_integer(TimeOut) ->
     ok = gen_server:call(Pid, {set_timeout, TimeOut}).
 
+% Used by couch_db_update_notifier.erl
+send(Pid, Data) ->
+    gen_server:cast(Pid, {send, Data}).
+
 prompt(Pid, Data) ->
     case gen_server:call(Pid, {prompt, Data}, infinity) of
         {ok, Result} ->
@@ -148,6 +152,15 @@
             {stop, normal, OsError, OsProc}
     end.
 
+handle_cast({send, Data}, #os_proc{writer=Writer}=OsProc) ->
+    try
+        Writer(OsProc, Data),
+        {noreply, OsProc}
+    catch
+        throw:OsError ->
+            ?LOG_ERROR("Failed sending data: ~p -> ~p", [Data, OsError]),
+            {stop, normal, OsProc}
+    end;
 handle_cast(stop, OsProc) ->
     {stop, normal, OsProc};
 handle_cast(Msg, OsProc) ->