nickva commented on code in PR #5986: URL: https://github.com/apache/couchdb/pull/5986#discussion_r3155179524
########## src/couch_index/src/couch_index_cleanup.erl: ########## @@ -0,0 +1,98 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(couch_index_cleanup). +-behaviour(gen_server). + +-export([ + start_link/0, + schedule/1 +]). + +-export([ + init/1, + handle_call/3, + handle_cast/2, + handle_info/2 +]). + +-export([ + handle_db_event/3 +]). + +-define(DEFAULT_DELAY_MSEC, 30000). + +-record(st, { + pending = #{} :: #{binary() => reference()} +}). + +start_link() -> + gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). + +schedule(DbName) when is_binary(DbName) -> + gen_server:cast(?MODULE, {schedule, DbName, fanout}). + +init([]) -> + {ok, _} = couch_event:link_listener(?MODULE, handle_db_event, nil, [all_dbs]), + {ok, #st{}}. + +handle_call(Msg, _From, #st{} = St) -> + {stop, {invalid_call, Msg}, {invalid_call, Msg}, St}. + +handle_cast({schedule, DbName, Mode}, #st{pending = Pending} = St) -> + case maps:is_key(DbName, Pending) of + true -> + {noreply, St}; + false -> + case Mode of + fanout -> fanout(DbName); + no_fanout -> ok + end, + TRef = erlang:send_after(delay_msec(), self(), {run_cleanup, DbName}), Review Comment: Yup, exactly. That's why I kept the cleanup in smoosh as well. It's an idempotent process we can always run cleanup again and it should cleanup any left overs or just do nothing -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
