Github user iilyak commented on the pull request:

    https://github.com/apache/couchdb-couch-index/pull/16#issuecomment-219868691
  
    @rnewson: This change is for view_compaction (not db compaction). Here is 
my understanding of how it would work. 
    
    - The entry point to trigger compaction is 
[`couch_index:compact`](https://github.com/cloudant/couchdb-couch-index/blob/a3af68f86ee21a9e072507b9d1d7da11e001b299/src/couch_index.erl#L76).
 
    - It will do [gen_server:call(CPid, 
compact)](https://github.com/apache/couchdb-couch-index/blob/master/src/couch_index.erl#L77)
 to compactor Pid. 
    - `couch_index_compactor` would [spawn_link(fun() -> 
compact/3..](https://github.com/apache/couchdb-couch-index/blob/master/src/couch_index_compactor.erl#L64).
 
    - `couch_index_compactor:compact/3` would call 
[Mod:compact/3](https://github.com/apache/couchdb-couch-index/blob/master/src/couch_index_compactor.erl#L104).
 
    In our case `Mod` would be `couch_mrview_index`.
    - `couch_mrview_index:compact/3` would dispatch the call to 
[couch_mrview_compactor:compact/3](https://github.com/apache/couchdb-couch-mrview/blob/master/src/couch_mrview_index.erl#L193).
 
    - When compaction is finished we get control back into 
[couch_index_compactor:compact](https://github.com/apache/couchdb-couch-index/blob/master/src/couch_index_compactor.erl#L106).
 
    - Where right after `couch_mrview_compactor` we do 
`Mod:commit(NewIdxState)`. We notify couch_index by doing [gen_server:call(Idx, 
{compacted, 
NewIdxState})](https://github.com/apache/couchdb-couch-index/blob/master/src/couch_index_compactor.erl#L107).
 
    - I.e. we get 
[here](https://github.com/cloudant/couchdb-couch-index/blob/a3af68f86ee21a9e072507b9d1d7da11e001b299/src/couch_index.erl#L191).
 Where we can check if re-compaction is enabled. 
    - If re-compaction is not enabled we swap files. 
    Otherwise we reply `{reply, recompact, State}`. So  we can trigger 
[couch_mrview_index:compact(_, _, 
[recompact])](https://github.com/cloudant/couchdb-couch-index/blob/a3af68f86ee21a9e072507b9d1d7da11e001b299/src/couch_index_compactor.erl#L108:L110).
    
    Please let me know what I'm missing.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to