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 2014/01/17 23:08:32 UTC
[18/32] git commit: COUCHDB-1444 Fix missing_named_view errors
COUCHDB-1444 Fix missing_named_view errors
Relying on exit signals we were accidentally replacing view state
incorrectly when an exit signal accidentally spidered between various
processes related to couch_os_processes. This changes the state updates
to be a '$gen_cast' instead.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/commit/d56d3cf0
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/d56d3cf0
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/d56d3cf0
Branch: refs/heads/import
Commit: d56d3cf089eb4ba5b8aa14c0b89cc977547a9f2d
Parents: 3ff74b2
Author: Paul Joseph Davis <da...@apache.org>
Authored: Fri Aug 10 10:45:03 2012 -0500
Committer: Paul Joseph Davis <da...@apache.org>
Committed: Tue Aug 14 16:29:57 2012 -0500
----------------------------------------------------------------------
src/couch_index_updater.erl | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/d56d3cf0/src/couch_index_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_updater.erl b/src/couch_index_updater.erl
index 853f3d1..0d4c18d 100644
--- a/src/couch_index_updater.erl
+++ b/src/couch_index_updater.erl
@@ -15,7 +15,7 @@
%% API
--export([start_link/2, run/2, is_running/1, update/2, restart/2]).
+-export([start_link/2, run/2, is_running/1, update/3, restart/2]).
%% gen_server callbacks
-export([init/1, terminate/2, code_change/3]).
@@ -42,8 +42,8 @@ is_running(Pid) ->
gen_server:call(Pid, is_running).
-update(Mod, State) ->
- update(nil, Mod, State).
+update(Parent, Mod, State) ->
+ update(Parent, nil, Mod, State).
restart(Pid, IdxState) ->
@@ -65,7 +65,8 @@ handle_call({update, _IdxState}, _From, #st{pid=Pid}=State) when is_pid(Pid) ->
handle_call({update, IdxState}, _From, #st{idx=Idx, mod=Mod}=State) ->
Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
?LOG_INFO("Starting index update for db: ~s idx: ~s", Args),
- Pid = spawn_link(fun() -> update(Idx, Mod, IdxState) end),
+ Self = self(),
+ Pid = spawn_link(fun() -> update(Self, Idx, Mod, IdxState) end),
{reply, ok, State#st{pid=Pid}};
handle_call({restart, IdxState}, _From, #st{idx=Idx, mod=Mod}=State) ->
Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
@@ -74,7 +75,8 @@ handle_call({restart, IdxState}, _From, #st{idx=Idx, mod=Mod}=State) ->
true -> couch_util:shutdown_sync(State#st.pid);
_ -> ok
end,
- Pid = spawn_link(fun() -> update(Idx, State#st.mod, IdxState) end),
+ Self = self(),
+ Pid = spawn_link(fun() -> update(Self, Idx, State#st.mod, IdxState) end),
{reply, ok, State#st{pid=Pid}};
handle_call(is_running, _From, #st{pid=Pid}=State) when is_pid(Pid) ->
{reply, true, State};
@@ -82,18 +84,20 @@ handle_call(is_running, _From, State) ->
{reply, false, State}.
-handle_cast(_Mesg, State) ->
- {stop, unknown_cast, State}.
-
-
-handle_info({'EXIT', Pid, {updated, IdxState}}, #st{mod=Mod, pid=Pid}=State) ->
+handle_cast({Pid, updated, IdxState}, #st{mod=Mod, pid=Pid}=State) ->
Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
?LOG_INFO("Index update finished for db: ~s idx: ~s", Args),
ok = gen_server:cast(State#st.idx, {updated, IdxState}),
{noreply, State#st{pid=undefined}};
+handle_cast(_Mesg, State) ->
+ {stop, unknown_cast, State}.
+
+
handle_info({'EXIT', Pid, reset}, #st{idx=Idx, pid=Pid}=State) ->
{ok, NewIdxState} = gen_server:call(State#st.idx, reset),
- Pid2 = spawn_link(fun() -> update(Idx, State#st.mod, NewIdxState) end),
+ Self = self(),
+ Fun = fun() -> update(Self, Idx, State#st.mod, NewIdxState) end,
+ Pid2 = spawn_link(Fun),
{noreply, State#st{pid=Pid2}};
handle_info({'EXIT', Pid, normal}, #st{pid=Pid}=State) ->
{noreply, State#st{pid=undefined}};
@@ -114,7 +118,7 @@ code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-update(Idx, Mod, IdxState) ->
+update(Parent, Idx, Mod, IdxState) ->
DbName = Mod:get(db_name, IdxState),
CurrSeq = Mod:get(update_seq, IdxState),
UpdateOpts = Mod:get(update_options, IdxState),
@@ -181,7 +185,7 @@ update(Idx, Mod, IdxState) ->
end,
{ok, FinalIdxState} = Mod:finish_update(LastIdxSt),
- exit({updated, FinalIdxState})
+ gen_server:cast(Parent, {self(), updated, FinalIdxState})
end).