On no objection, I would apply this to the branches 1.0.x and 1.1.x as well. Please review.
On Thu, May 12, 2011 at 12:39 AM, <[email protected]> wrote: > Author: fdmanana > Date: Wed May 11 23:39:19 2011 > New Revision: 1102137 > > URL: http://svn.apache.org/viewvc?rev=1102137&view=rev > Log: > Make sure view group shutdowns when database is deleted or dies > > Added more assertions to test 200-view-group-no-db-leaks.t to ensure > this doesn't happen anymore. > > > Modified: > couchdb/trunk/src/couchdb/couch_view_group.erl > couchdb/trunk/test/etap/200-view-group-no-db-leaks.t > > Modified: couchdb/trunk/src/couchdb/couch_view_group.erl > URL: > http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_view_group.erl?rev=1102137&r1=1102136&r2=1102137&view=diff > ============================================================================== > --- couchdb/trunk/src/couchdb/couch_view_group.erl (original) > +++ couchdb/trunk/src/couchdb/couch_view_group.erl Wed May 11 23:39:19 2011 > @@ -84,6 +84,7 @@ init({{_, DbName, _} = InitArgs, ReturnP > ReturnPid ! {Ref, self(), {error, invalid_view_seq}}, > ignore; > _ -> > + couch_db:monitor(Db), > couch_db:close(Db), > {ok, RefCounter} = couch_ref_counter:start([Fd]), > {ok, #group_state{ > @@ -339,7 +340,11 @@ handle_info({'EXIT', FromPid, {{nocatch, > > handle_info({'EXIT', FromPid, Reason}, State) -> > ?LOG_DEBUG("Exit from linked pid: ~p", [{FromPid, Reason}]), > - {stop, Reason, State}. > + {stop, Reason, State}; > + > +handle_info({'DOWN',_,_,_,_}, State) -> > + ?LOG_INFO("Shutting down view group server, monitored db is closing.", > []), > + {stop, normal, reply_all(State, shutdown)}. > > > terminate(Reason, #group_state{updater_pid=Update, compactor_pid=Compact}=S) > -> > > Modified: couchdb/trunk/test/etap/200-view-group-no-db-leaks.t > URL: > http://svn.apache.org/viewvc/couchdb/trunk/test/etap/200-view-group-no-db-leaks.t?rev=1102137&r1=1102136&r2=1102137&view=diff > ============================================================================== > --- couchdb/trunk/test/etap/200-view-group-no-db-leaks.t (original) > +++ couchdb/trunk/test/etap/200-view-group-no-db-leaks.t Wed May 11 23:39:19 > 2011 > @@ -67,7 +67,7 @@ ddoc_name() -> <<"foo">>. > main(_) -> > test_util:init_code_path(), > > - etap:plan(11), > + etap:plan(18), > case (catch test()) of > ok -> > etap:end_tests(); > @@ -89,12 +89,20 @@ test() -> > > create_docs(), > create_design_doc(), > + > + ViewGroup = couch_view:get_group_server( > + test_db_name(), <<"_design/", (ddoc_name())/binary>>), > + etap:is(is_pid(ViewGroup), true, "got view group pid"), > + etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"), > + > query_view(), > check_db_ref_count(), > + etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"), > > create_new_doc(<<"doc1000">>), > query_view(), > check_db_ref_count(), > + etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"), > > Ref1 = get_db_ref_counter(), > compact_db(), > @@ -102,15 +110,27 @@ test() -> > Ref2 = get_db_ref_counter(), > etap:isnt(Ref1, Ref2, "DB ref counter changed"), > etap:is(false, is_process_alive(Ref1), "old DB ref counter is not alive"), > + etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"), > > compact_view_group(), > check_db_ref_count(), > Ref3 = get_db_ref_counter(), > etap:is(Ref3, Ref2, "DB ref counter didn't change"), > + etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"), > > create_new_doc(<<"doc1001">>), > query_view(), > check_db_ref_count(), > + etap:is(is_process_alive(ViewGroup), true, "view group pid is alive"), > + > + MonRef = erlang:monitor(process, ViewGroup), > + ok = couch_server:delete(test_db_name(), []), > + receive > + {'DOWN', MonRef, _, _, _} -> > + etap:diag("view group is dead after DB deletion") > + after 5000 -> > + etap:bail("view group did not die after DB deletion") > + end, > > ok = timer:sleep(1000), > delete_db(), > > > -- Filipe David Manana, [email protected], [email protected] "Reasonable men adapt themselves to the world. Unreasonable men adapt the world to themselves. That's why all progress depends on unreasonable men."
