Github user iilyak commented on a diff in the pull request:
https://github.com/apache/couchdb-couch/pull/241#discussion_r109014150
--- Diff: src/couch_db_updater.erl ---
@@ -1323,12 +1326,82 @@ bind_id_tree(Db, Fd, State) ->
Db#db{id_tree=IdBtree}.
-sort_meta_data(Db0) ->
- {ok, Ems} = couch_emsort:merge(Db0#db.id_tree),
- Db0#db{id_tree=Ems}.
+sort_meta_data(Db0, DocCount) ->
+ couch_task_status:update([
+ {phase, sort_ids_init},
+ {total_changes, DocCount},
+ {changes_done, 0},
+ {progress, 0}
+ ]),
+ Ems0 = Db0#db.id_tree,
+ Options = [
+ {event_cb, fun emsort_cb/3},
+ {event_st, {init, 0, 0}}
+ ],
+ Ems1 = couch_emsort:set_options(Ems0, Options),
+ {ok, Ems2} = couch_emsort:merge(Ems1),
+ Db0#db{id_tree=Ems2}.
+
+
+emsort_cb(_Ems, {merge, chain}, {init, Copied, Nodes}) ->
+ {init, Copied, Nodes + 1};
+emsort_cb(_Ems, row_copy, {init, Copied, Nodes}) when Copied >= 1000 ->
+ update_compact_task(Copied + 1),
+ {init, 0, Nodes};
+emsort_cb(_Ems, row_copy, {init, Copied, Nodes}) ->
+ {init, Copied + 1, Nodes};
+emsort_cb(Ems, {merge_start, reverse}, {init, Copied, Nodes}) ->
--- End diff --
I noticed that we can also have `{merge_start, forward}`
[event](https://github.com/apache/couchdb-couch/blob/1db1337301a7c897be41e13cd328270509008478/src/couch_emsort.erl#L246:L252).
Should we handle it as well?
---
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.
---