You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2025/09/05 17:59:51 UTC

(couchdb) branch auto-delete-tseq updated (ed2c9cb7f -> 31c5a27d9)

This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a change to branch auto-delete-tseq
in repository https://gitbox.apache.org/repos/asf/couchdb.git


 discard ed2c9cb7f purge tombstones that exceed TTL
 discard dca1f8c4d [fixup] [couch_db_updater] Use couch_time_seq:update/3 (fix bad fixup)
 discard 7d03e3b01 [fixup] [docs] fix inix/unix typo
 discard 756d483da [fixup] [couch_db_updater] Use couch_time_seq:update/3 only, update/2 is gone
 discard bbb2e9a9c [fixup] [couch_db_int] bring back and explain the "repurposed" field
 discard a36deb955 [fixup] [couch_db_engine] improve wording in the set_time_seq API
 discard 9eba0a136 [fixup] [couch_time_seq] remove update/2
 discard 1a37dbf3f Add time-seq and _changes since=time docs
 discard 6d7094694 Time-based since parameter for _changes
 discard eca77c543 Add an HTTP API to query and reset time-seq values
 discard 5fe24137f Add time-seq to the db header and update it on commit
 discard 5b1a3a7cf Implement an exponentially decaying time intervals data structure
     add efbb5c6ec Prevent B-tree duplicate entries. Add property tests.
     add 600318913 Reduce btree prop test count a bit
     add 1b4cca582 Implement an exponentially decaying time intervals data structure
     add a1214bbb5 Add time-seq to the db header and update it on commit
     add 3a1619441 Add an HTTP API to query and reset time-seq values
     add 164878126 Time-based since parameter for _changes
     add aff29aee1 Add time-seq and _changes since=time docs
     new 31c5a27d9 purge tombstones that exceed TTL

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (ed2c9cb7f)
            \
             N -- N -- N   refs/heads/auto-delete-tseq (31c5a27d9)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/couch/src/couch_btree.erl                   |  14 +-
 src/couch/src/couch_time_seq.erl                |   4 +-
 src/couch/src/couch_tombstone_remover.erl       |  60 +++----
 src/couch/test/eunit/couch_btree_prop_tests.erl | 225 ++++++++++++++++++++++++
 4 files changed, 270 insertions(+), 33 deletions(-)
 create mode 100644 src/couch/test/eunit/couch_btree_prop_tests.erl


(couchdb) 01/01: purge tombstones that exceed TTL

Posted by rn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch auto-delete-tseq
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 31c5a27d9837c3607b2da40087e1cb53c01d4695
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Sep 2 15:32:21 2025 +0100

    purge tombstones that exceed TTL
---
 src/couch/src/couch_tombstone_remover.erl | 128 ++++++++++++++++++++++++++++++
 1 file changed, 128 insertions(+)

diff --git a/src/couch/src/couch_tombstone_remover.erl b/src/couch/src/couch_tombstone_remover.erl
new file mode 100644
index 000000000..3334cb24b
--- /dev/null
+++ b/src/couch/src/couch_tombstone_remover.erl
@@ -0,0 +1,128 @@
+% 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_tombstone_remover).
+-behaviour(couch_scanner_plugin).
+
+-export([
+    start/2,
+    resume/2,
+    complete/1,
+    checkpoint/1,
+    db/2,
+    db_opened/2,
+    db_closing/2,
+    doc_fdi/3
+]).
+
+-include_lib("couch_scanner/include/couch_scanner_plugin.hrl").
+
+start(ScanId, #{}) ->
+    St = init_config(ScanId),
+    case should_run() of
+        true ->
+            ?INFO("Starting.", [], St),
+            {ok, St};
+        false ->
+            ?INFO("Not starting.", [], St),
+            skip
+    end.
+
+resume(ScanId, #{}) ->
+    St = init_config(ScanId),
+    case should_run() of
+        true ->
+            ?INFO("Resuming.", [], St),
+            {ok, St};
+        false ->
+            ?INFO("Not resuming.", [], St),
+            skip
+    end.
+
+complete(St) ->
+    ?INFO("Completed", [], St),
+    {ok, #{}}.
+
+checkpoint(_St) ->
+    {ok, #{}}.
+
+db(St, DbName) ->
+    case config:get_integer("tombstone_remover_ttl", ?b2l(DbName), 0) of
+        0 ->
+            {skip, St};
+        TTL when is_integer(TTL), TTL > 0 ->
+            {ok, St#{ttl => TTL}}
+    end.
+
+db_opened(#{} = St, Db) ->
+    #{ttl := TTL} = St,
+    EndSeq = couch_time_seq:since(couch_db:get_time_seq(Db), couch_time_seq:timestamp() - TTL),
+    ChangeOpts =
+        if
+            EndSeq == now -> [];
+            true -> [{end_key, EndSeq}]
+        end,
+    ?INFO("scanning for tombstones in ~s up to ~p", [couch_db:name(Db), EndSeq], meta(St)),
+    {0, ChangeOpts, St#{count => 0, end_seq => EndSeq}}.
+
+db_closing(#{} = St, Db) ->
+    #{count := Count} = St,
+    ?INFO("purged ~B tombstones from ~s", [Count, couch_db:name(Db)], meta(St)),
+    {ok, St}.
+
+doc_fdi(#{} = St, #full_doc_info{deleted = true} = FDI, Db) ->
+    #{end_seq := EndSeq} = St,
+    if
+        FDI#full_doc_info.update_seq =< EndSeq ->
+            {ok, purge(St, FDI, Db)};
+        true ->
+            {ok, St}
+    end;
+doc_fdi(#{} = St, #full_doc_info{}, _Db) ->
+    {ok, St}.
+
+purge(#{} = St, #full_doc_info{} = FDI, Db) ->
+    IDRevs = fdi_to_idrevs(FDI),
+    MaxBatchSize = config:get_integer("couch_tombstone_remover", "max_batch_size", 100),
+    purge(St, IDRevs, MaxBatchSize, Db).
+
+purge(#{} = St, {Id, Revs}, MaxBatchSize, Db) when length(Revs) =< MaxBatchSize ->
+    DbName = mem3:dbname(couch_db:name(Db)),
+    {Pid, Ref} = spawn_monitor(fun() ->
+        exit(fabric:purge_docs(DbName, [{Id, Revs}], [?ADMIN_CTX]))
+    end),
+    receive
+        {'DOWN', Ref, process, Pid, {_Health, _Results}} ->
+            %% TODO check Results for success/failure
+            #{count := Count} = St,
+            St#{count => Count + length(Revs)}
+    end;
+purge(#{} = St0, {Id, Revs}, MaxBatchSize, Db) ->
+    {RevBatch, RevRest} = lists:split(MaxBatchSize, Revs),
+    St1 = purge(St0, {Id, RevBatch}, MaxBatchSize, Db),
+    purge(St1, {Id, RevRest}, MaxBatchSize, Db).
+
+fdi_to_idrevs(#full_doc_info{} = FDI) ->
+    Revs = [
+        couch_doc:rev_to_str({Pos, RevId})
+     || {#leaf{}, {Pos, [RevId | _]}} <- couch_key_tree:get_all_leafs(FDI#full_doc_info.rev_tree)
+    ],
+    {FDI#full_doc_info.id, Revs}.
+
+init_config(ScanId) ->
+    #{sid => ScanId}.
+
+should_run() ->
+    true.
+
+meta(#{sid := ScanId}) ->
+    #{sid => ScanId}.