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 2020/04/10 21:31:04 UTC
[couchdb] 05/11: Extend fabric2_index callbacks for index cleanup
This is an automated email from the ASF dual-hosted git repository.
davisp pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 7bc9148b75b1396b91b6cdccca2c8e87b791e0f0
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Wed Mar 25 14:50:45 2020 -0500
Extend fabric2_index callbacks for index cleanup
Each registered index type can now get a signal on when to clean up
their indexes.
---
src/fabric/src/fabric2_index.erl | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/fabric/src/fabric2_index.erl b/src/fabric/src/fabric2_index.erl
index 9a6607e..7f9d519 100644
--- a/src/fabric/src/fabric2_index.erl
+++ b/src/fabric/src/fabric2_index.erl
@@ -19,6 +19,7 @@
-export([
register_index/1,
db_updated/1,
+ cleanup/1,
start_link/0
]).
@@ -38,6 +39,9 @@
-callback build_indices(Db :: map(), DDocs :: list(#doc{})) ->
[{ok, JobId::binary()} | {error, any()}].
+-callback cleanup_indices(Db :: map(), DDocs :: list(#doc{})) ->
+ [ok | {error, any()}].
+
-define(SHARDS, 32).
-define(DEFAULT_DELAY_MSEC, 60000).
@@ -54,6 +58,25 @@ db_updated(DbName) when is_binary(DbName) ->
ets:insert_new(Table, {DbName, now_msec()}).
+cleanup(Db) ->
+ try
+ fabric2_fdb:transactional(Db, fun(TxDb) ->
+ DDocs = fabric2_db:get_design_docs(TxDb),
+ lists:foreach(fun(Mod) ->
+ Mod:cleanup_indices(TxDb, DDocs)
+ end, registrations())
+ end)
+ catch
+ error:database_does_not_exist ->
+ ok;
+ Tag:Reason ->
+ Stack = erlang:get_stacktrace(),
+ DbName = fabric2_db:name(Db),
+ LogMsg = "~p failed to cleanup indices for `~s` ~p:~p ~p",
+ couch_log:error(LogMsg, [?MODULE, DbName, Tag, Reason, Stack])
+ end.
+
+
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).