You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2026/01/23 14:36:37 UTC
(couchdb) 02/02: log the time it takes to compact a view and swap it into use
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch view-compaction-duration-log
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit c1a9f86afcbaec61f2737d75443c1d70f81e31f9
Author: Robert Newson <rn...@apache.org>
AuthorDate: Fri Jan 23 14:34:56 2026 +0000
log the time it takes to compact a view and swap it into use
---
src/couch_mrview/include/couch_mrview.hrl | 3 ++-
src/couch_mrview/src/couch_mrview_compactor.erl | 16 ++++++++++++----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/couch_mrview/include/couch_mrview.hrl b/src/couch_mrview/include/couch_mrview.hrl
index 6ba226aad..ae1e0288f 100644
--- a/src/couch_mrview/include/couch_mrview.hrl
+++ b/src/couch_mrview/include/couch_mrview.hrl
@@ -30,7 +30,8 @@
doc_queue,
write_queue,
qserver=nil,
- view_info=#{}
+ view_info=#{},
+ start_time
}).
diff --git a/src/couch_mrview/src/couch_mrview_compactor.erl b/src/couch_mrview/src/couch_mrview_compactor.erl
index a534dd0e8..3dbfd6773 100644
--- a/src/couch_mrview/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview/src/couch_mrview_compactor.erl
@@ -26,6 +26,8 @@
total_changes
}).
+-compile({no_auto_import,[now/0]}).
+
-define(DEFAULT_RECOMPACT_RETRY_COUNT, 3).
compact(_Db, State, Opts) ->
@@ -129,7 +131,8 @@ compact(State) ->
{ok, EmptyState#mrst{
id_btree = NewIdBtree,
views = NewViews,
- update_seq = Seq
+ update_seq = Seq,
+ start_time = now()
}}.
recompact(State) ->
@@ -248,10 +251,12 @@ swap_compacted(OldState, NewState) ->
{ok, Pre} = couch_file:bytes(Fd),
{ok, Post} = couch_file:bytes(NewFd),
- couch_log:notice("Compaction swap for view ~s ~p ~p", [
+ Duration = now() - NewState#mrst.start_time,
+ couch_log:notice("Compaction swap for view ~s ~p ~p ~Bs", [
IndexFName,
Pre,
- Post
+ Post,
+ Duration
]),
ok = couch_file:delete(RootDir, IndexFName),
ok = file:rename(CompactFName, IndexFName),
@@ -259,7 +264,7 @@ swap_compacted(OldState, NewState) ->
unlink(OldState#mrst.fd),
demonitor(OldState#mrst.fd_monitor, [flush]),
- {ok, NewState#mrst{fd_monitor = Ref}}.
+ {ok, NewState#mrst{fd_monitor = Ref, start_time = now()}}.
remove_compacted(#mrst{sig = Sig, db_name = DbName} = State) ->
RootDir = couch_index_util:root_dir(),
@@ -267,6 +272,9 @@ remove_compacted(#mrst{sig = Sig, db_name = DbName} = State) ->
ok = couch_file:delete(RootDir, CompactFName),
{ok, State}.
+now() ->
+ erlang:monotonic_time(second).
+
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").