diff options
author | Peng Hui Jiang <jiangphcn@apache.org> | 2018-08-22 00:53:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-22 00:53:20 +0800 |
commit | 2d3f935eb87224906ab7b1f273b15fa736cee6b4 (patch) | |
tree | 9700a0eef38fe255333aeeaee05ac51facd0678b | |
parent | c02f6d294d962d18c22d8179f43ee07add5437eb (diff) | |
parent | ab12e0be80f37bbf9b77f0977393c89696a0b948 (diff) | |
download | couchdb-2d3f935eb87224906ab7b1f273b15fa736cee6b4.tar.gz |
Merge pull request #1369 from apache/COUCHDB-3326-clustered-purge-pr4-on-compact-plugin
[4/5] Clustered Purge: Add on_compact EPI hook
-rw-r--r-- | src/couch/src/couch_bt_engine_compactor.erl | 2 | ||||
-rw-r--r-- | src/couch/src/couch_db_engine.erl | 31 | ||||
-rw-r--r-- | src/couch/src/couch_db_plugin.erl | 5 |
3 files changed, 37 insertions, 1 deletions
diff --git a/src/couch/src/couch_bt_engine_compactor.erl b/src/couch/src/couch_bt_engine_compactor.erl index 4e52064b4..2c5b78e0b 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 49742012d..2fe0b0d9d 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 740b8121b..816325699 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], []). |