You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2023/03/22 14:31:19 UTC

[couchdb] branch couch_index_fixes created (now c81c5c5a9)

This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a change to branch couch_index_fixes
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at c81c5c5a9 don't crash if index crashes during open or if event listener crashes

This branch includes the following new commits:

     new 506eaf3d8 Revert "catch and log any error from mem3:local_shards"
     new f3823c8e4 restart event listener if it crashes, instead of crashing ourselves
     new c81c5c5a9 don't crash if index crashes during open or if event listener crashes

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/03: Revert "catch and log any error from mem3:local_shards"

Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch couch_index_fixes
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 506eaf3d8dd7fa785b8a623453464734ba8f8784
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Mar 22 14:05:22 2023 +0000

    Revert "catch and log any error from mem3:local_shards"
    
    This reverts commit 937ccb6ef84b773882c967a6fa6f4d71df42e4cf.
    
    The original code already catches the only error we actually get.
    revert this to remove log noise.
---
 src/couch_index/src/couch_index_server.erl | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/couch_index/src/couch_index_server.erl b/src/couch_index/src/couch_index_server.erl
index c3440024e..2e368bfc2 100644
--- a/src/couch_index/src/couch_index_server.erl
+++ b/src/couch_index/src/couch_index_server.erl
@@ -312,11 +312,7 @@ handle_db_event(<<"shards/", _/binary>> = DbName, {ddoc_updated, DDocId}, St) ->
         try
             mem3:local_shards(mem3:dbname(DbName))
         catch
-            Class:Msg ->
-                couch_log:warning(
-                    "~p got ~p:~p when fetching local shards for ~p",
-                    [?MODULE, Class, Msg, DbName]
-                ),
+            error:database_does_not_exist ->
                 []
         end,
     DbShards = [mem3:name(Sh) || Sh <- LocalShards],


[couchdb] 03/03: don't crash if index crashes during open or if event listener crashes

Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch couch_index_fixes
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit c81c5c5a990ff4b3536f82af69cb9f9aa10dd955
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Mar 22 14:31:01 2023 +0000

    don't crash if index crashes during open or if event listener crashes
---
 src/couch_index/src/couch_index_server.erl | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/couch_index/src/couch_index_server.erl b/src/couch_index/src/couch_index_server.erl
index 2e368bfc2..0a2af85a1 100644
--- a/src/couch_index/src/couch_index_server.erl
+++ b/src/couch_index/src/couch_index_server.erl
@@ -41,7 +41,8 @@
     server_name,
     by_sig,
     by_pid,
-    by_db
+    by_db,
+    event_listener
 }).
 
 start_link(N) ->
@@ -143,8 +144,8 @@ init([N]) ->
         by_db = by_db(N)
     },
     ok = config:listen_for_changes(?MODULE, St),
-    couch_event:link_listener(?MODULE, handle_db_event, St, [all_dbs]),
-    {ok, St}.
+    {ok, Pid} = couch_event:link_listener(?MODULE, handle_db_event, St, [all_dbs]),
+    {ok, St#st{event_listener = Pid}}.
 
 terminate(_Reason, State) ->
     Pids = [Pid || {Pid, _} <- ets:tab2list(State#st.by_pid)],
@@ -154,7 +155,8 @@ terminate(_Reason, State) ->
 handle_call({get_index, {_Mod, _IdxState, DbName, Sig} = Args}, From, State) ->
     case ets:lookup(State#st.by_sig, {DbName, Sig}) of
         [] ->
-            spawn_link(fun() -> new_index(Args) end),
+            Pid = spawn_link(fun() -> new_index(Args) end),
+            ets:insert(State#st.by_pid, {Pid, opening, {DbName, Sig}}),
             ets:insert(State#st.by_sig, {{DbName, Sig}, [From]}),
             {noreply, State};
         [{_, Waiters}] when is_list(Waiters) ->
@@ -169,9 +171,10 @@ handle_call({async_open, {DbName, DDocId, Sig}, {ok, Pid}}, _From, State) ->
     link(Pid),
     add_to_ets(DbName, Sig, DDocId, Pid, State),
     {reply, ok, State};
-handle_call({async_error, {DbName, _DDocId, Sig}, Error}, _From, State) ->
+handle_call({async_error, {DbName, _DDocId, Sig}, Error}, {OpenerPid, _}, State) ->
     [{_, Waiters}] = ets:lookup(State#st.by_sig, {DbName, Sig}),
     [gen_server:reply(From, Error) || From <- Waiters],
+    ets:delete(State#st.by_pid, OpenerPid),
     ets:delete(State#st.by_sig, {DbName, Sig}),
     {reply, ok, State};
 handle_call({reset_indexes, DbName}, _From, State) ->
@@ -194,6 +197,10 @@ handle_cast({rem_from_ets, [DbName, DDocId, Sig]}, State) ->
     ets:delete_object(State#st.by_db, {DbName, {DDocId, Sig}}),
     {noreply, State}.
 
+handle_info({'EXIT', Pid, Reason}, #st{event_listener = Pid} = State) ->
+    couch_log:warning("~p: update notifier died ~p", [?MODULE, Reason]),
+    {ok, Pid1} = start_event_listener(),
+    {noreply, State#st{event_listener = Pid1}};
 handle_info({'EXIT', Pid, Reason}, Server) ->
     case ets:lookup(Server#st.by_pid, Pid) of
         [{Pid, {DbName, Sig}}] ->
@@ -203,6 +210,9 @@ handle_info({'EXIT', Pid, Reason}, Server) ->
                     ets:match_object(Server#st.by_db, {DbName, {'$1', Sig}})
             ],
             rem_from_ets(DbName, Sig, DDocIds, Pid, Server);
+        [{_, opening, {DbName, Sig}}] when Reason /= normal ->
+            Msg = {async_error, {DbName, nil, Sig}, Reason},
+            {reply, ok, _} = handle_call(Msg, {Pid, nil}, Server);
         [] when Reason /= normal ->
             exit(Reason);
         _Else ->
@@ -394,3 +404,6 @@ aggregate_queue_len() ->
      || Name <- Names
     ],
     lists:sum([X || {_, X} <- MQs]).
+
+start_event_listener() ->
+    couch_event:link_listener(?MODULE, handle_db_event, nil, [all_dbs]).


[couchdb] 02/03: restart event listener if it crashes, instead of crashing ourselves

Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch couch_index_fixes
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit f3823c8e40223e649aa1f6d418db6e839f9cbde3
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Mar 22 14:30:34 2023 +0000

    restart event listener if it crashes, instead of crashing ourselves
---
 src/dreyfus/src/dreyfus_index_manager.erl | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/dreyfus/src/dreyfus_index_manager.erl b/src/dreyfus/src/dreyfus_index_manager.erl
index f0dbbec64..ad2c4b90f 100644
--- a/src/dreyfus/src/dreyfus_index_manager.erl
+++ b/src/dreyfus/src/dreyfus_index_manager.erl
@@ -36,6 +36,10 @@
 
 -export([handle_db_event/3]).
 
+-record(st, {
+    event_listener
+}).
+
 % public functions.
 start_link() ->
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
@@ -53,9 +57,9 @@ init([]) ->
     couch_util:set_mqd_off_heap(?MODULE),
     ets:new(?BY_SIG, [set, private, named_table]),
     ets:new(?BY_PID, [set, private, named_table]),
-    couch_event:link_listener(?MODULE, handle_db_event, nil, [all_dbs]),
+    {ok, Pid} = start_event_listener(),
     process_flag(trap_exit, true),
-    {ok, nil}.
+    {ok, #st{event_listener = Pid}}.
 
 handle_call({get_index, DbName, #index{sig = Sig} = Index}, From, State) ->
     case ets:lookup(?BY_SIG, {DbName, Sig}) of
@@ -91,6 +95,10 @@ handle_cast({rename, DbName}, State) ->
     clouseau_rpc:rename(DbName),
     {noreply, State}.
 
+handle_info({'EXIT', Pid, Reason}, #st{event_listener = Pid} = State) ->
+    couch_log:warning("~p: update notifier died ~p", [?MODULE, Reason]),
+    {ok, Pid1} = start_event_listener(),
+    {noreply, State#st{event_listener = Pid1}};
 handle_info({'EXIT', FromPid, Reason}, State) ->
     case ets:lookup(?BY_PID, FromPid) of
         [] ->
@@ -158,3 +166,6 @@ add_to_ets(Pid, DbName, Sig) ->
 delete_from_ets(Pid, DbName, Sig) ->
     true = ets:delete(?BY_PID, Pid),
     true = ets:delete(?BY_SIG, {DbName, Sig}).
+
+start_event_listener() ->
+    couch_event:link_listener(?MODULE, handle_db_event, nil, [all_dbs]).