This is an automated email from the ASF dual-hosted git repository. rnewson pushed a commit to branch deleted_document_ttl_enhancement in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit a4afdc935bda91237ef45b0c5990eabddbb94a8b Author: Robert Newson <[email protected]> AuthorDate: Thu Oct 9 14:43:46 2025 +0100 change deleted_document_ttl to match scanner repeat format --- src/couch/src/couch_auto_purge_plugin.erl | 19 ++++++++++++++++--- .../test/eunit/couch_auto_purge_plugin_tests.erl | 4 ++-- src/couch_scanner/src/couch_scanner_util.erl | 3 ++- src/docs/src/api/database/misc.rst | 6 +++--- src/docs/src/config/scanner.rst | 7 +++++-- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/couch/src/couch_auto_purge_plugin.erl b/src/couch/src/couch_auto_purge_plugin.erl index a6088cd42..e309a647a 100644 --- a/src/couch/src/couch_auto_purge_plugin.erl +++ b/src/couch/src/couch_auto_purge_plugin.erl @@ -133,14 +133,14 @@ ttl(St, DbName) -> DbTTL = case fabric:get_auto_purge_props(DbName) of {ok, AutoPurgeProps} -> - case couch_util:get_value(<<"deleted_document_ttl">>, AutoPurgeProps) of + case parse_deleted_document_ttl(AutoPurgeProps) of TTL when is_integer(TTL) -> TTL; undefined -> undefined; Else -> ?WARN( - "TTL in ~s as ttl was '~p', not integer", + "ignoring TTL in ~s as ttl was '~p'", [DbName, Else], meta(St) ), @@ -156,6 +156,19 @@ ttl(St, DbName) -> end, if DbTTL /= undefined -> DbTTL; - DefaultTTL /= undefined -> list_to_integer(DefaultTTL); + DefaultTTL /= undefined -> parse_ttl(DefaultTTL); true -> undefined end. + +parse_deleted_document_ttl(AutoPurgeProps) -> + case couch_util:get_value( <<"deleted_document_ttl">>, AutoPurgeProps) of + undefined -> + undefined; + Else -> + parse_ttl(Else) + end. + +parse_ttl([$- | TTL]) -> + -(parse_ttl(TTL)); +parse_ttl(TTL) -> + couch_scanner_util:parse_non_weekday_period(TTL). diff --git a/src/couch/test/eunit/couch_auto_purge_plugin_tests.erl b/src/couch/test/eunit/couch_auto_purge_plugin_tests.erl index 371abcb05..5a322b7c0 100644 --- a/src/couch/test/eunit/couch_auto_purge_plugin_tests.erl +++ b/src/couch/test/eunit/couch_auto_purge_plugin_tests.erl @@ -62,7 +62,7 @@ t_no_auto_purge_by_default({_, DbName}) -> ok. t_auto_purge_after_config_ttl({_, DbName}) -> - config:set(atom_to_list(?PLUGIN), "deleted_document_ttl", "-1000000", false), + config:set(atom_to_list(?PLUGIN), "deleted_document_ttl", "-3_hour", false), ok = add_doc(DbName, <<"doc1">>, #{<<"_deleted">> => true}), ?assertEqual(1, doc_del_count(DbName)), meck:reset(couch_scanner_server), @@ -73,7 +73,7 @@ t_auto_purge_after_config_ttl({_, DbName}) -> ok. t_auto_purge_after_db_ttl({_, DbName}) -> - ok = fabric:set_auto_purge_props(DbName, [{<<"deleted_document_ttl">>, -1000000}]), + ok = fabric:set_auto_purge_props(DbName, [{<<"deleted_document_ttl">>, "-3_hour"}]), ok = add_doc(DbName, <<"doc1">>, #{<<"_deleted">> => true}), ?assertEqual(1, doc_del_count(DbName)), meck:reset(couch_scanner_server), diff --git a/src/couch_scanner/src/couch_scanner_util.erl b/src/couch_scanner/src/couch_scanner_util.erl index ff4edafd3..e556ff369 100644 --- a/src/couch_scanner/src/couch_scanner_util.erl +++ b/src/couch_scanner/src/couch_scanner_util.erl @@ -22,7 +22,8 @@ compile_regexes/1, match_regexes/2, on_first_node/0, - consistent_hash_nodes/1 + consistent_hash_nodes/1, + parse_non_weekday_period/1 ]). -define(SECOND, 1). diff --git a/src/docs/src/api/database/misc.rst b/src/docs/src/api/database/misc.rst index 446113bc9..02a0fdcf7 100644 --- a/src/docs/src/api/database/misc.rst +++ b/src/docs/src/api/database/misc.rst @@ -373,12 +373,12 @@ following behavior: Date: Mon, 22 Sep 2025 11:01:00 GMT Server: CouchDB (Erlang/OTP) - {"deleted_document_ttl": 259200} + {"deleted_document_ttl": "3_mon"} .. http:put:: /{db}/_auto_purge :synopsis: Update auto purge settings - Retrieves the auto purge settings for the database. These settings + Updates the auto purge settings for the database. These settings are used by the :ref:`auto purge plugin <config/auto_purge_plugin>`. :param db: Database name @@ -403,7 +403,7 @@ following behavior: Content-Type: application/json Host: localhost:5984 - {"deleted_document_ttl": 259200} + {"deleted_document_ttl": "3_hour"} **Response**: diff --git a/src/docs/src/config/scanner.rst b/src/docs/src/config/scanner.rst index bad2480db..9c56891d2 100644 --- a/src/docs/src/config/scanner.rst +++ b/src/docs/src/config/scanner.rst @@ -256,7 +256,10 @@ settings in their ``[{plugin}]`` section. .. config:option:: deleted_document_ttl - Set the default interval, in seconds, before the plugin will purge - a deleted document. The database may override this setting with the + Set the default interval before the plugin will purge + a deleted document. Possible ttl formats are: ``{num}_{timeunit}`` (ex.: + ``1000_sec``, ``30_min``, ``8_hours``, ``24_hour``, ``2_days``, + ``3_weeks``, ``1_month``). + The database may override this setting with the :ref:`api/db/auto_purge` endpoint. If neither is set, the plugin will not purge deleted documents.
