You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2022/03/29 21:50:52 UTC
[couchdb] 02/02: Implement configurable compaction log levels
This is an automated email from the ASF dual-hosted git repository.
jaydoane pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 5edab6273855e597d11a93645cf62a01d24fbe8d
Author: Jay Doane <ja...@apache.org>
AuthorDate: Sun Mar 27 17:01:29 2022 -0700
Implement configurable compaction log levels
Create new config options in `couchdb` and `smoosh` sections to enable
finer control of compaction logging levels.
---
rel/overlay/etc/default.ini | 6 ++++++
src/couch/src/couch_bt_engine.erl | 7 ++++++-
src/couch/src/couch_db_updater.erl | 7 ++++++-
src/smoosh/src/smoosh_channel.erl | 30 +++++++++++++++++++++---------
src/smoosh/src/smoosh_priority_queue.erl | 6 ++++--
src/smoosh/src/smoosh_server.erl | 12 ++++++++----
src/smoosh/src/smoosh_utils.erl | 7 ++++++-
7 files changed, 57 insertions(+), 18 deletions(-)
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 5def66c..7535501 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -84,6 +84,9 @@ view_index_dir = {{view_index_dir}}
; to request attachment data before returning a response to the client.
;attachment_writer_timeout = 300000
+; Sets the log level for informational compaction related entries.
+;compaction_log_level = info
+
[purge]
; Allowed maximum number of documents in one purge request
;max_document_id_number = 100
@@ -647,6 +650,9 @@ partitioned||* = true
; Directory to store the state of smoosh
state_dir = {{state_dir}}
+; Sets the log level for informational compaction related entries.
+;compaction_log_level = notice
+
[ioq]
; The maximum number of concurrent in-flight IO requests that
;concurrency = 10
diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl
index 42dbed2..ca0828b 100644
--- a/src/couch/src/couch_bt_engine.erl
+++ b/src/couch/src/couch_bt_engine.erl
@@ -644,7 +644,12 @@ finish_compaction(OldState, DbName, Options, CompactFilePath) ->
true ->
finish_compaction_int(OldState, NewState1);
false ->
- couch_log:info(
+ Level = list_to_existing_atom(
+ config:get(
+ "couchdb", "compaction_log_level", "info"
+ )
+ ),
+ couch_log:Level(
"Compaction file still behind main file "
"(update seq=~p. compact update seq=~p). Retrying.",
[OldSeq, NewSeq]
diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl
index 710b705..17a1e91 100644
--- a/src/couch/src/couch_db_updater.erl
+++ b/src/couch/src/couch_db_updater.erl
@@ -139,7 +139,12 @@ handle_cast(start_compact, Db) ->
% type to compact to with a new copy compactor.
UpdateSeq = couch_db_engine:get_update_seq(Db),
Args = [Db#db.name, UpdateSeq],
- couch_log:info("Starting compaction for db \"~s\" at ~p", Args),
+ Level = list_to_existing_atom(
+ config:get(
+ "couchdb", "compaction_log_level", "info"
+ )
+ ),
+ couch_log:Level("Starting compaction for db \"~s\" at ~p", Args),
{ok, Db2} = couch_db_engine:start_compaction(Db),
ok = couch_server:db_updated(Db2),
{noreply, Db2, idle_limit()};
diff --git a/src/smoosh/src/smoosh_channel.erl b/src/smoosh/src/smoosh_channel.erl
index 2f4c7bf..da8bacf 100644
--- a/src/smoosh/src/smoosh_channel.erl
+++ b/src/smoosh/src/smoosh_channel.erl
@@ -148,7 +148,8 @@ handle_cast({enqueue, _Object, 0}, #state{} = State) ->
handle_cast({enqueue, Object, Priority}, #state{activated = true} = State) ->
{noreply, maybe_start_compaction(add_to_queue(Object, Priority, State))};
handle_cast({enqueue, Object, Priority}, #state{activated = false, requests = Requests} = State0) ->
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"~p Channel is not activated yet. Adding ~p to requests with priority ~p.", [
?MODULE,
Object,
@@ -197,7 +198,8 @@ handle_info({'DOWN', Ref, _, Job, Reason}, State) ->
handle_info({Ref, {ok, Pid}}, State) when is_reference(Ref) ->
case lists:keytake(Ref, 1, State#state.starting) of
{value, {_, Key}, Starting1} ->
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"~s: Started compaction for ~s",
[State#state.name, smoosh_utils:stringify(Key)]
),
@@ -252,7 +254,8 @@ handle_info(start_recovery, #state{name = Name, waiting = Waiting0} = State0) ->
RecActive
),
State1 = maybe_start_compaction(State0#state{paused = false, waiting = Waiting1}),
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"~p Previously active compaction jobs (if any) have been successfully recovered and restarted.",
[?MODULE]
),
@@ -289,7 +292,8 @@ do_recover(FilePath) ->
<<Vsn, Binary/binary>> = Content,
try parse_state(Vsn, ?VSN, Binary) of
Term ->
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"~p Successfully restored state file ~s", [?MODULE, FilePath]
),
{ok, Term}
@@ -302,7 +306,8 @@ do_recover(FilePath) ->
error
end;
{error, enoent} ->
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"~p (~p) State file ~s does not exist. Not restoring.", [?MODULE, enoent, FilePath]
),
error;
@@ -353,7 +358,8 @@ add_to_queue(Key, Priority, State) ->
State;
false ->
Capacity = list_to_integer(smoosh_utils:get(State#state.name, "capacity", "9999")),
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"~s: adding ~p to internal compactor queue with priority ~p",
[State#state.name, Key, Priority]
),
@@ -425,7 +431,11 @@ maybe_start_compaction(State) ->
false ->
State;
State1 ->
- couch_log:notice(
+ Level = smoosh_utils:log_level(
+ "compaction_log_level",
+ "notice"
+ ),
+ couch_log:Level(
"~s: Starting compaction for ~s (priority ~p)",
[State#state.name, smoosh_utils:stringify(Key), Priority]
),
@@ -498,7 +508,8 @@ start_compact(State, Db) ->
State#state{starting = [{Ref, Key} | State#state.starting]};
% Compaction is already running, so monitor existing compaction pid.
CPid ->
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"Db ~s continuing compaction",
[smoosh_utils:stringify(Key)]
),
@@ -520,7 +531,8 @@ maybe_remonitor_cpid(State, DbName, Reason) when is_binary(DbName) ->
{ok, _} = timer:apply_after(5000, smoosh_server, enqueue, [DbName]),
State;
CPid ->
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"~s compaction already running. Re-monitor Pid ~p",
[smoosh_utils:stringify(DbName), CPid]
),
diff --git a/src/smoosh/src/smoosh_priority_queue.erl b/src/smoosh/src/smoosh_priority_queue.erl
index 83c9366..000297a 100644
--- a/src/smoosh/src/smoosh_priority_queue.erl
+++ b/src/smoosh/src/smoosh_priority_queue.erl
@@ -144,7 +144,8 @@ do_recover(FilePath) ->
<<Vsn, Binary/binary>> = Content,
try parse_queue(Vsn, ?VSN, Binary) of
Bin ->
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"~p Successfully restored state file ~s", [?MODULE, FilePath]
),
{ok, Bin}
@@ -157,7 +158,8 @@ do_recover(FilePath) ->
error
end;
{error, enoent} ->
- couch_log:notice(
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level(
"~p (~p) Queue file ~s does not exist. Not restoring.", [?MODULE, enoent, FilePath]
),
error;
diff --git a/src/smoosh/src/smoosh_server.erl b/src/smoosh/src/smoosh_server.erl
index cfde748..f0260e9 100644
--- a/src/smoosh/src/smoosh_server.erl
+++ b/src/smoosh/src/smoosh_server.erl
@@ -173,7 +173,8 @@ handle_call({enqueue, Object}, _From, State) ->
handle_call(suspend, _From, State) ->
ets:foldl(
fun(#channel{name = Name, pid = P}, _) ->
- couch_log:notice("Suspending ~p", [Name]),
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level("Suspending ~p", [Name]),
smoosh_channel:suspend(P)
end,
0,
@@ -183,7 +184,8 @@ handle_call(suspend, _From, State) ->
handle_call(resume, _From, State) ->
ets:foldl(
fun(#channel{name = Name, pid = P}, _) ->
- couch_log:notice("Resuming ~p", [Name]),
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level("Resuming ~p", [Name]),
smoosh_channel:resume(P)
end,
0,
@@ -222,11 +224,13 @@ handle_cast({enqueue, Object}, State) ->
end.
handle_info({'EXIT', Pid, Reason}, #state{event_listener = Pid} = State) ->
- couch_log:notice("update notifier died ~p", [Reason]),
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level("update notifier died ~p", [Reason]),
{ok, Pid1} = start_event_listener(),
{noreply, State#state{event_listener = Pid1}};
handle_info({'EXIT', Pid, Reason}, State) ->
- couch_log:notice("~p ~p died ~p", [?MODULE, Pid, Reason]),
+ Level = smoosh_utils:log_level("compaction_log_level", "notice"),
+ couch_log:Level("~p ~p died ~p", [?MODULE, Pid, Reason]),
case ets:match_object(State#state.tab, #channel{pid = Pid, _ = '_'}) of
[#channel{name = Name}] ->
ets:delete(State#state.tab, Name);
diff --git a/src/smoosh/src/smoosh_utils.erl b/src/smoosh/src/smoosh_utils.erl
index 625a9e4..72be585 100644
--- a/src/smoosh/src/smoosh_utils.erl
+++ b/src/smoosh/src/smoosh_utils.erl
@@ -15,6 +15,7 @@
-export([get/2, get/3, group_pid/1, split/1, stringify/1, ignore_db/1]).
-export([in_allowed_window/1, write_to_file/3]).
+-export([log_level/2]).
group_pid({Shard, GroupId}) ->
case couch_view_group:open_db_group(Shard, GroupId) of
@@ -87,7 +88,8 @@ throw_on_error(Args, {error, Reason}) ->
throw({error, {Reason, Args}}).
write_to_file(Content, FileName, VSN) ->
- couch_log:notice("~p Writing state to state file ~s", [?MODULE, FileName]),
+ Level = log_level("compaction_log_level", "notice"),
+ couch_log:Level("~p Writing state ~s", [?MODULE, FileName]),
OnDisk = <<VSN, (erlang:term_to_binary(Content, [compressed, {minor_version, 1}]))/binary>>,
TmpFileName = FileName ++ ".tmp",
try
@@ -116,3 +118,6 @@ parse_time(String, Default) ->
couch_log:error("Malformed compaction schedule configuration: ~s", [String]),
Default
end.
+
+log_level(Key, Default) when is_list(Key), is_list(Default) ->
+ list_to_existing_atom(config:get("smoosh", Key, Default)).