diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-03-25 15:00:45 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-04-10 16:30:49 -0500 |
commit | 7aeb54bf6012c234c5806db6f438427c9cb53c4a (patch) | |
tree | d86827e80069f8de19b4dc7dc097e00d4986fdce | |
parent | 4275a496dbfcec36ff0777b1cf350fffcc7756b9 (diff) | |
download | couchdb-7aeb54bf6012c234c5806db6f438427c9cb53c4a.tar.gz |
Optionally cleanup stale indices automatically
-rw-r--r-- | rel/overlay/etc/default.ini | 3 | ||||
-rw-r--r-- | src/fabric/src/fabric2_index.erl | 22 |
2 files changed, 20 insertions, 5 deletions
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini index 376089a98..e10a5a0c7 100644 --- a/rel/overlay/etc/default.ini +++ b/rel/overlay/etc/default.ini @@ -236,6 +236,9 @@ port = 6984 ; ; How often to check if databases may need their indices updated. ;index_updater_resolution_msec = 10000 +; +; Enable or disable automatic stale index removal in the auto-updater +;index_updater_remove_old_indices = false ; [rexi] ; buffer_count = 2000 diff --git a/src/fabric/src/fabric2_index.erl b/src/fabric/src/fabric2_index.erl index 7f9d51974..25c31a8c8 100644 --- a/src/fabric/src/fabric2_index.erl +++ b/src/fabric/src/fabric2_index.erl @@ -61,10 +61,8 @@ db_updated(DbName) when is_binary(DbName) -> 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()) + DDocs = fabric2_db:get_design_docs(Db), + cleanup_indices(TxDb, DDocs) end) catch error:database_does_not_exist -> @@ -184,7 +182,11 @@ process_db(DbName) when is_binary(DbName) -> DDocs1 = fabric2_db:get_design_docs(TxDb), DDocs2 = lists:filter(fun should_update/1, DDocs1), DDocs3 = shuffle(DDocs2), - build_indices(TxDb, DDocs3) + build_indices(TxDb, DDocs3), + case auto_cleanup() of + true -> cleanup_indices(TxDb, DDocs1); + false -> ok + end end). @@ -197,6 +199,12 @@ build_indices(TxDb, DDocs) -> end, registrations()). +cleanup_indices(TxDb, DDocs) -> + lists:foreach(fun(Mod) -> + Mod:cleanup_indices(TxDb, DDocs) + end, registrations()). + + registrations() -> application:get_env(fabric, indices, []). @@ -227,3 +235,7 @@ delay_msec() -> resolution_msec() -> config:get_integer("fabric", "index_updater_resolution_msec", ?DEFAULT_RESOLUTION_MSEC). + + +auto_cleanup() -> + config:get_boolean("fabric", "index_updater_remove_old_indices", false). |