eiri commented on a change in pull request #1187: [WIP] Couchdb 3326 clustered purge URL: https://github.com/apache/couchdb/pull/1187#discussion_r173857571
########## File path: src/couch_index/src/couch_index_plugin_couch_db.erl ########## @@ -0,0 +1,42 @@ +% 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_index_plugin_couch_db). + +-export([ + before_copy_purge_info/1 +]). + +-include_lib("couch/include/couch_db.hrl"). +-include_lib("couch_mrview/include/couch_mrview.hrl"). + + +before_copy_purge_info(DbName) -> + {ok, DDocs} = design_docs(DbName), + lists:map(fun(DDoc) -> + JsonDDoc = couch_doc:from_json_obj(DDoc), + couch_mrview_index:maybe_create_local_purge_doc(DbName, JsonDDoc) + end, DDocs). + +%% Internal functions + +design_docs(DbName) -> Review comment: This looks expensive, to be honest. Db can have thousands views, so attempt to write thousand local docs on compaction of any _shard_ of db doesn't look like something that'd scale well. I'm still familiarizing myself with clustered purge, but can we write a _single_ local_purge_doc before each _view_ compaction instead? On a separate note, if you are doing `try / catch` why also `case`? Just do matching `fabric:design_docs/1` to `{ok, Docs}` and catch possible crash on `{error, {maintenance_mode` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
