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 2018/07/06 17:36:35 UTC

[couchdb] branch COUCHDB-3326-clustered-purge-pr4-on-compact-plugin updated (b4f3ceb -> 1499c79)

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

davisp pushed a change to branch COUCHDB-3326-clustered-purge-pr4-on-compact-plugin
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


    omit b4f3ceb  Create new on_compact trigger
    omit 527c6f5  Enhance PSE tests with setup/teardown functions
     add 826b17e  Enhance PSE tests with setup/teardown functions
     new 1499c79  Create new on_compact trigger

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   (b4f3ceb)
            \
             N -- N -- N   refs/heads/COUCHDB-3326-clustered-purge-pr4-on-compact-plugin (1499c79)

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_pse_tests/src/cpse_test_read_write_docs.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[couchdb] 01/01: Create new on_compact trigger

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

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-pr4-on-compact-plugin
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 1499c79808c7a3d1c9a7bcbd3dfc3bb75e0e1ec3
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Wed May 30 14:34:44 2018 -0500

    Create new on_compact trigger
    
    This trigger allows any storage engine that makes use of compaction to
    notify that compaction is starting. This is preparatory work for
    clustered indexes so that existing indexes are allowed to ensure they
    have a clustered purge local doc before compaction runs.
    
    COUCHDB-3326
    
    Co-Authored-By: jiangphcn <ji...@cn.ibm.com>
---
 src/couch/src/couch_bt_engine_compactor.erl |  2 ++
 src/couch/src/couch_db_engine.erl           | 31 ++++++++++++++++++++++++++++-
 src/couch/src/couch_db_plugin.erl           |  5 +++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/couch/src/couch_bt_engine_compactor.erl b/src/couch/src/couch_bt_engine_compactor.erl
index 4e52064..2c5b78e 100644
--- a/src/couch/src/couch_bt_engine_compactor.erl
+++ b/src/couch/src/couch_bt_engine_compactor.erl
@@ -44,6 +44,8 @@ start(#st{} = St, DbName, Options, Parent) ->
     } = St,
     couch_log:debug("Compaction process spawned for db \"~s\"", [DbName]),
 
+    couch_db_engine:trigger_on_compact(DbName),
+
     {ok, NewSt, DName, DFd, MFd, Retry} =
             open_compaction_files(Header, FilePath, Options),
     erlang:monitor(process, MFd),
diff --git a/src/couch/src/couch_db_engine.erl b/src/couch/src/couch_db_engine.erl
index 4974201..2fe0b0d 100644
--- a/src/couch/src/couch_db_engine.erl
+++ b/src/couch/src/couch_db_engine.erl
@@ -627,7 +627,8 @@
     count_changes_since/2,
 
     start_compaction/1,
-    finish_compaction/2
+    finish_compaction/2,
+    trigger_on_compact/1
 ]).
 
 
@@ -891,3 +892,31 @@ finish_compaction(Db, CompactInfo) ->
     end,
     ok = gen_server:call(couch_server, {db_updated, NewDb}, infinity),
     {ok, NewDb}.
+
+
+trigger_on_compact(DbName) ->
+    {ok, DDocs} = get_ddocs(DbName),
+    couch_db_plugin:on_compact(DbName, DDocs).
+
+
+get_ddocs(<<"shards/", _/binary>> = DbName) ->
+    {_, Ref} = spawn_monitor(fun() ->
+        exit(fabric:design_docs(mem3:dbname(DbName)))
+    end),
+    receive
+        {'DOWN', Ref, _, _, {ok, JsonDDocs}} ->
+            {ok, lists:map(fun(JsonDDoc) ->
+                couch_doc:from_json_obj(JsonDDoc)
+            end, JsonDDocs)};
+        {'DOWN', Ref, _, _, Else} ->
+            Else
+    end;
+get_ddocs(DbName) ->
+    couch_util:with_db(DbName, fun(Db) ->
+        FoldFun = fun(FDI, Acc) ->
+            Doc = couch_db:open_doc_int(Db, FDI, []),
+            {ok, [Doc | Acc]}
+        end,
+        {ok, Docs} = couch_db:fold_design_docs(Db, FoldFun, [], []),
+        {ok, lists:reverse(Docs)}
+    end).
diff --git a/src/couch/src/couch_db_plugin.erl b/src/couch/src/couch_db_plugin.erl
index 740b812..8163256 100644
--- a/src/couch/src/couch_db_plugin.erl
+++ b/src/couch/src/couch_db_plugin.erl
@@ -18,6 +18,7 @@
     after_doc_read/2,
     validate_docid/1,
     check_is_admin/1,
+    on_compact/2,
     on_delete/2
 ]).
 
@@ -56,6 +57,10 @@ check_is_admin(Db) ->
     %% callbacks return true only if it specifically allow the given Id
     couch_epi:any(Handle, ?SERVICE_ID, check_is_admin, [Db], []).
 
+on_compact(DbName, DDocs) ->
+    Handle = couch_epi:get_handle(?SERVICE_ID),
+    couch_epi:apply(Handle, ?SERVICE_ID, on_compact, [DbName, DDocs], []).
+
 on_delete(DbName, Options) ->
     Handle = couch_epi:get_handle(?SERVICE_ID),
     couch_epi:apply(Handle, ?SERVICE_ID, on_delete, [DbName, Options], []).