From 0b4ef0d4117827353fa2da04c48db15530b9effc Mon Sep 17 00:00:00 2001 From: Tony Sun Date: Wed, 10 May 2017 21:16:13 -0700 Subject: add compaction logging To predict future compaction results, we log pre-compaction and post-compaction file sizes. These log results will be used as data points for regression analysis. COUCHDB-3417 --- src/couch/src/couch_db_updater.erl | 9 ++++++--- src/couch_mrview/src/couch_mrview_compactor.erl | 11 ++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl index 78726358e..bb8e9dafb 100644 --- a/src/couch/src/couch_db_updater.erl +++ b/src/couch/src/couch_db_updater.erl @@ -218,7 +218,7 @@ handle_cast(start_compact, Db) -> % compact currently running, this is a no-op {noreply, Db} end; -handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) -> +handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath,fd=Fd}=Db) -> {ok, NewFd} = couch_file:open(CompactFilepath), {ok, NewHeader0} = couch_file:read_header(NewFd), NewHeader = couch_db_header:set(NewHeader0, [ @@ -242,8 +242,11 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) -> revs_limit = Db#db.revs_limit }), - couch_log:debug("CouchDB swapping files ~s and ~s.", - [Filepath, CompactFilepath]), + {ok, Pre} = couch_file:bytes(Fd), + {ok, Post} = couch_file:bytes(NewFd), + + couch_log:notice("Compaction swap for db: ~s ~p ~p", [Filepath, + Pre, Post]), ok = file:rename(CompactFilepath, Filepath ++ ".compact"), RootDir = config:get("couchdb", "database_dir", "."), couch_file:delete(RootDir, Filepath), diff --git a/src/couch_mrview/src/couch_mrview_compactor.erl b/src/couch_mrview/src/couch_mrview_compactor.erl index fabe2894c..c1b2fbc21 100644 --- a/src/couch_mrview/src/couch_mrview_compactor.erl +++ b/src/couch_mrview/src/couch_mrview_compactor.erl @@ -274,9 +274,13 @@ update_task(VID, #acc{changes=Changes, total_changes=Total}=Acc, ChangesInc) -> swap_compacted(OldState, NewState) -> + #mrst{ + fd = Fd + } = OldState, #mrst{ sig=Sig, - db_name=DbName + db_name=DbName, + fd=NewFd } = NewState, link(NewState#mrst.fd), @@ -285,6 +289,11 @@ swap_compacted(OldState, NewState) -> RootDir = couch_index_util:root_dir(), IndexFName = couch_mrview_util:index_file(DbName, Sig), CompactFName = couch_mrview_util:compaction_file(DbName, Sig), + + {ok, Pre} = couch_file:bytes(Fd), + {ok, Post} = couch_file:bytes(NewFd), + couch_log:notice("Compaction swap for view ~s ~p ~p", [IndexFName, + Pre, Post]), ok = couch_file:delete(RootDir, IndexFName), ok = file:rename(CompactFName, IndexFName), -- cgit v1.2.1