Skip to content

Instantly share code, notes, and snippets.

@davisp
Created May 3, 2016 16:05
Show Gist options
  • Select an option

  • Save davisp/153c239cfcd8a4dc53be2e43e84d280d to your computer and use it in GitHub Desktop.

Select an option

Save davisp/153c239cfcd8a4dc53be2e43e84d280d to your computer and use it in GitHub Desktop.
diff --git a/src/couch_index_updater.erl b/src/couch_index_updater.erl
index ad48f40..7153248 100644
--- a/src/couch_index_updater.erl
+++ b/src/couch_index_updater.erl
@@ -94,7 +94,7 @@ handle_info({'EXIT', _, {updated, Pid, IdxState}}, #st{pid=Pid}=State) ->
Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
couch_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}};
+ {noreply, State#st{pid=maybe_restart_updater(IdxState)}};
handle_info({'EXIT', _, {reset, Pid}}, #st{idx=Idx, pid=Pid}=State) ->
{ok, NewIdxState} = gen_server:call(State#st.idx, reset),
Pid2 = spawn_link(?MODULE, update, [Idx, State#st.mod, NewIdxState]),
@@ -209,3 +209,16 @@ purge_index(Db, Mod, IdxState) ->
true ->
reset
end.
+
+maybe_restart_updater(IdxState) ->
+ DbName = get_dbname(IdxState),
+ UpdateSeq = get_update_seq(IdxState),
+ couch_db:with_db(DbName, fun(Db) ->
+ case couch_db:get_update_seq(Db) > UpdateSeq of
+ true ->
+ spawn index updater
+ false ->
+ undefined
+ end
+ end).
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment