summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Sun <tony.sun@cloudant.com>2017-05-10 21:16:13 -0700
committerTony Sun <tony.sun@cloudant.com>2017-05-30 11:28:18 -0700
commit0b4ef0d4117827353fa2da04c48db15530b9effc (patch)
treefaf2190d4be4afc82fb7190ebe9482ab0e86825b
parent3691c2edbc6603963b1b5ad1bf97dfb69886c4a6 (diff)
downloadcouchdb-0b4ef0d4117827353fa2da04c48db15530b9effc.tar.gz
add compaction logging3417-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
-rw-r--r--src/couch/src/couch_db_updater.erl9
-rw-r--r--src/couch_mrview/src/couch_mrview_compactor.erl11
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
@@ -275,8 +275,12 @@ 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),