diff options
author | Nick Vatamaniuc <vatamane@apache.org> | 2018-11-27 22:37:38 -0500 |
---|---|---|
committer | Nick Vatamaniuc <vatamane@apache.org> | 2018-11-27 22:55:55 -0500 |
commit | 33736f27b5eb4535a896d076cca95a3cb185696d (patch) | |
tree | 17a971111ced4476d8e39f21ef5a8cba2e91e4f2 | |
parent | fd03aa409a5a040f98eb934df3c4cd5d5bf1acd9 (diff) | |
download | couchdb-fix-view-compaction.tar.gz |
Use fabric to get design docs in the compaction daemonfix-view-compaction
Previously the compaction daemon looked for design docs in each shard file.
This worked well for versions < 2.x, however, for clustered databases design
documents will only be found in their respective shards based on the document
id hashing algorithm. This meant that in a default setup of Q=8 only the views
of one shard range, where the _design document lives, would be compacted.
The fix for this issue is to use fabric to retrive all the design documents for
clustered database.
Issue #1579
-rw-r--r-- | src/couch/src/couch_compaction_daemon.erl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/couch/src/couch_compaction_daemon.erl b/src/couch/src/couch_compaction_daemon.erl index 1a535dba7..608ea1908 100644 --- a/src/couch/src/couch_compaction_daemon.erl +++ b/src/couch/src/couch_compaction_daemon.erl @@ -239,6 +239,36 @@ maybe_compact_views(DbName, [DDocName | Rest], Config) -> db_ddoc_names(Db) -> + DbName = couch_db:name(Db), + ClusteredDbName = mem3:dbname(DbName), + case ClusteredDbName == DbName of + true -> + db_local_ddoc_names(Db); + false -> + db_cluster_ddoc_names(ClusteredDbName) + end. + + +db_cluster_ddoc_names(ClusteredDbName) -> + try + case fabric:design_docs(ClusteredDbName) of + {ok, DDocs} -> + lists:map(fun({Props}) -> + DocId = proplists:get_value(<<"_id">>, Props), + <<"_design/", GroupName/binary>> = DocId, + GroupName + end, DDocs); + Error -> + ErrMsg = "Could not get design docs for ~p error:~p", + couch_log:error(ErrMsg, [ClusteredDbName, Error]), + [] + end + catch error:database_does_not_exist -> + [] + end. + + +db_local_ddoc_names(Db) -> FoldFun = fun ddoc_name/2, Opts = [{start_key, <<"_design/">>}], {ok, DDocNames} = couch_db:fold_docs(Db, FoldFun, [], Opts), |