Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions src/couch_compaction_daemon.erl
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ maybe_compact_db(DbName, Config) ->
false -> maybe_compact_views(DbName, DDocNames, Config)
end;
{error, timeout} ->
?LOG_INFO("Compaction daemon - canceling compaction "
couch_log:info("Compaction daemon - canceling compaction "
"for databaes `~s` because exceeded the allowed time.",
[DbName]),
ok = couch_db:cancel_compact(Db),
couch_db:close(Db);
{error, Reason} ->
couch_db:close(Db),
?LOG_ERROR("Compaction daemon - an error ocurred while"
couch_log:error("Compaction daemon - an error ocurred while"
" compacting the database `~s`: ~p", [DbName, Reason])
end,
case ViewsMonRef of
Expand Down Expand Up @@ -243,14 +243,14 @@ maybe_compact_view(DbName, GroupId, Config) ->
{'DOWN', MonRef, process, _, normal} ->
ok;
{'DOWN', MonRef, process, _, Reason} ->
?LOG_ERROR("Compaction daemon - an error ocurred while compacting"
" the view group `~s` from database `~s`: ~p",
[GroupId, DbName, Reason]),
couch_log:error("Compaction daemon - an error ocurred"
" while compacting the view group `~s` from database "
"`~s`: ~p", [GroupId, DbName, Reason]),
ok
after TimeLeft ->
?LOG_INFO("Compaction daemon - canceling the compaction for the "
"view group `~s` of the database `~s` because it's exceeding"
" the allowed period.", [GroupId, DbName]),
couch_log:info("Compaction daemon - canceling the compaction"
" for the view group `~s` of the database `~s` because it's"
" exceeding the allowed period.", [GroupId, DbName]),
erlang:demonitor(MonRef, [flush]),
ok = couch_mrview:cancel_compaction(DbName, DDocId),
timeout
Expand All @@ -259,7 +259,7 @@ maybe_compact_view(DbName, GroupId, Config) ->
ok
end;
Error ->
?LOG_ERROR("Error opening view group `~s` from database `~s`: ~p",
couch_log:error("Error opening view group `~s` from database `~s`: ~p",
[GroupId, DbName, Error]),
ok
end.
Expand Down Expand Up @@ -300,8 +300,9 @@ can_db_compact(#config{db_frag = Threshold} = Config, Db) ->
true ->
{ok, DbInfo} = couch_db:get_db_info(Db),
{Frag, SpaceRequired} = frag(DbInfo),
?LOG_DEBUG("Fragmentation for database `~s` is ~p%, estimated space for"
" compaction is ~p bytes.", [Db#db.name, Frag, SpaceRequired]),
couch_log:debug("Fragmentation for database `~s` is ~p%, estimated"
" space for compaction is ~p bytes.",
[Db#db.name, Frag, SpaceRequired]),
case check_frag(Threshold, Frag) of
false ->
false;
Expand All @@ -311,10 +312,10 @@ can_db_compact(#config{db_frag = Threshold} = Config, Db) ->
true ->
true;
false ->
?LOG_WARN("Compaction daemon - skipping database `~s` "
couch_log:warning("Compaction daemon - skipping database `~s` "
"compaction: the estimated necessary disk space is about ~p"
" bytes but the currently available disk space is ~p bytes.",
[Db#db.name, SpaceRequired, Free]),
[Db#db.name, SpaceRequired, Free]),
false
end
end
Expand All @@ -330,8 +331,8 @@ can_view_compact(Config, DbName, GroupId, GroupInfo) ->
false;
false ->
{Frag, SpaceRequired} = frag(GroupInfo),
?LOG_DEBUG("Fragmentation for view group `~s` (database `~s`) is "
"~p%, estimated space for compaction is ~p bytes.",
couch_log:debug("Fragmentation for view group `~s` (database `~s`)"
" is ~p%, estimated space for compaction is ~p bytes.",
[GroupId, DbName, Frag, SpaceRequired]),
case check_frag(Config#config.view_frag, Frag) of
false ->
Expand All @@ -342,10 +343,10 @@ can_view_compact(Config, DbName, GroupId, GroupInfo) ->
true ->
true;
false ->
?LOG_WARN("Compaction daemon - skipping view group `~s` "
"compaction (database `~s`): the estimated necessary "
"disk space is about ~p bytes but the currently available"
" disk space is ~p bytes.",
couch_log:warning("Compaction daemon - skipping view group"
" `~s` compaction (database `~s`): the estimated"
" necessary disk space is about ~p bytes"
" but the currently available disk space is ~p bytes.",
[GroupId, DbName, SpaceRequired, Free]),
false
end
Expand Down Expand Up @@ -414,12 +415,13 @@ parse_config(DbName, ConfigString) ->
{ok, Conf} ->
{ok, Conf};
incomplete_period ->
?LOG_ERROR("Incomplete period ('to' or 'from' missing) in the compaction"
" configuration for database `~s`", [DbName]),
couch_log:error("Incomplete period ('to' or 'from' missing)"
" in the compaction configuration for database `~s`",
[DbName]),
error;
_ ->
?LOG_ERROR("Invalid compaction configuration for database "
"`~s`: `~s`", [DbName, ConfigString]),
couch_log:error("Invalid compaction configuration for database "
"`~s`: `~s`", [DbName, ConfigString]),
error
end.

Expand Down
13 changes: 8 additions & 5 deletions src/couch_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ open_db_file(Filepath, Options) ->
% crashed during the file switch.
case couch_file:open(Filepath ++ ".compact", [nologifmissing]) of
{ok, Fd} ->
?LOG_INFO("Found ~s~s compaction file, using as primary storage.", [Filepath, ".compact"]),
couch_log:info("Found ~s~s compaction file, using as primary"
" storage.", [Filepath, ".compact"]),
ok = file:rename(Filepath ++ ".compact", Filepath),
ok = couch_file:sync(Fd),
{ok, Fd};
Expand Down Expand Up @@ -430,7 +431,9 @@ check_is_member(#db{user_ctx=#user_ctx{name=Name,roles=Roles}=UserCtx}=Db) ->
WithAdminRoles -> % same list, not an reader role
case ReaderNames -- [Name] of
ReaderNames -> % same names, not a reader
?LOG_DEBUG("Not a reader: UserCtx ~p vs Names ~p Roles ~p",[UserCtx, ReaderNames, WithAdminRoles]),
couch_log:debug("Not a reader: UserCtx ~p"
" vs Names ~p Roles ~p",
[UserCtx, ReaderNames, WithAdminRoles]),
throw({unauthorized, <<"You are not authorized to access this db.">>});
_ ->
ok
Expand Down Expand Up @@ -603,7 +606,7 @@ load_validation_funs(#db{main_pid=Pid, name = <<"shards/", _/binary>>}=Db) ->
gen_server:cast(Pid, {load_validation_funs, Funs}),
Funs;
{'DOWN', Ref, _, _, Reason} ->
?LOG_ERROR("could not load validation funs ~p", [Reason]),
couch_log:error("could not load validation funs ~p", [Reason]),
throw(internal_server_error)
end;
load_validation_funs(#db{main_pid=Pid}=Db) ->
Expand Down Expand Up @@ -966,8 +969,8 @@ set_commit_option(Options) ->
{_, "false"} ->
[full_commit|Options];
{_, Else} ->
?LOG_ERROR("[couchdb] delayed_commits setting must be true/false, not ~p",
[Else]),
couch_log:error("[couchdb] delayed_commits setting must be true/false,"
" not ~p", [Else]),
[full_commit|Options]
end.

Expand Down
25 changes: 13 additions & 12 deletions src/couch_db_updater.erl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ handle_cast({load_validation_funs, ValidationFuns}, Db) ->
handle_cast(start_compact, Db) ->
case Db#db.compactor_pid of
nil ->
?LOG_INFO("Starting compaction for db \"~s\"", [Db#db.name]),
couch_log:info("Starting compaction for db \"~s\"", [Db#db.name]),
Pid = spawn_link(fun() -> start_copy_compact(Db) end),
Db2 = Db#db{compactor_pid=Pid},
ok = gen_server:call(couch_server, {db_updated, Db2}, infinity),
Expand Down Expand Up @@ -242,8 +242,8 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
revs_limit = Db#db.revs_limit
}),

?LOG_DEBUG("CouchDB swapping files ~s and ~s.",
[Filepath, CompactFilepath]),
couch_log:debug("CouchDB swapping files ~s and ~s.",
[Filepath, CompactFilepath]),
ok = file:rename(CompactFilepath, Filepath ++ ".compact"),
RootDir = config:get("couchdb", "database_dir", "."),
couch_file:delete(RootDir, Filepath),
Expand All @@ -255,12 +255,12 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
NewDb3 = refresh_validate_doc_funs(NewDb2),
ok = gen_server:call(couch_server, {db_updated, NewDb3}, infinity),
couch_event:notify(NewDb3#db.name, compacted),
?LOG_INFO("Compaction for db \"~s\" completed.", [Db#db.name]),
couch_log:info("Compaction for db \"~s\" completed.", [Db#db.name]),
{noreply, NewDb3#db{compactor_pid=nil}};
false ->
?LOG_INFO("Compaction file still behind main file "
"(update seq=~p. compact update seq=~p). Retrying.",
[Db#db.update_seq, NewSeq]),
couch_log:info("Compaction file still behind main file "
"(update seq=~p. compact update seq=~p). Retrying.",
[Db#db.update_seq, NewSeq]),
close_db(NewDb),
Pid = spawn_link(fun() -> start_copy_compact(Db) end),
Db2 = Db#db{compactor_pid=Pid},
Expand All @@ -269,7 +269,8 @@ handle_cast({compact_done, CompactFilepath}, #db{filepath=Filepath}=Db) ->
end;

handle_cast(Msg, #db{name = Name} = Db) ->
?LOG_ERROR("Database `~s` updater received unexpected cast: ~p", [Name, Msg]),
couch_log:error("Database `~s` updater received unexpected cast: ~p",
[Name, Msg]),
{stop, Msg, Db}.


Expand Down Expand Up @@ -331,7 +332,7 @@ handle_info({'EXIT', _Pid, normal}, Db) ->
handle_info({'EXIT', _Pid, Reason}, Db) ->
{stop, Reason, Db};
handle_info({'DOWN', Ref, _, _, Reason}, #db{fd_monitor=Ref, name=Name} = Db) ->
?LOG_ERROR("DB ~s shutting down - Fd ~p", [Name, Reason]),
couch_log:error("DB ~s shutting down - Fd ~p", [Name, Reason]),
{stop, normal, Db#db{fd=undefined, fd_monitor=closed}}.

code_change(_OldVsn, State, _Extra) ->
Expand Down Expand Up @@ -652,8 +653,8 @@ flush_trees(#db{fd = Fd} = Db,
% Fd where the attachments were written to is not the same
% as our Fd. This can happen when a database is being
% switched out during a compaction.
?LOG_DEBUG("File where the attachments are written has"
" changed. Possibly retrying.", []),
couch_log:debug("File where the attachments are written has"
" changed. Possibly retrying.", []),
throw(retry)
end,
ExternalSize = ?term_size(Summary),
Expand Down Expand Up @@ -1182,7 +1183,7 @@ copy_compact(Db, NewDb0, Retry) ->
start_copy_compact(#db{}=Db) ->
erlang:put(io_priority, {db_compact, Db#db.name}),
#db{name=Name, filepath=Filepath, options=Options, header=Header} = Db,
?LOG_DEBUG("Compaction process spawned for db \"~s\"", [Name]),
couch_log:debug("Compaction process spawned for db \"~s\"", [Name]),

{ok, NewDb, DName, DFd, MFd, Retry} =
open_compaction_files(Name, Header, Filepath, Options),
Expand Down
10 changes: 5 additions & 5 deletions src/couch_doc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ validate_docid(Id) when is_binary(Id) ->
_Else -> ok
end;
validate_docid(Id) ->
?LOG_DEBUG("Document id is not a string: ~p", [Id]),
couch_log:debug("Document id is not a string: ~p", [Id]),
throw({bad_request, <<"Document id must be a string">>}).

transfer_fields([], #doc{body=Fields}=Doc) ->
Expand Down Expand Up @@ -472,12 +472,12 @@ doc_from_multi_part_stream(ContentType, DataFun, Ref) ->
{'DOWN', ParserRef, _, _, normal} ->
ok;
{'DOWN', ParserRef, process, Parser, {{nocatch, {Error, Msg}}, _}} ->
?LOG_ERROR("Multipart streamer ~p died with reason ~p",
[ParserRef, Msg]),
couch_log:error("Multipart streamer ~p died with reason ~p",
[ParserRef, Msg]),
throw({Error, Msg});
{'DOWN', ParserRef, _, _, Reason} ->
?LOG_ERROR("Multipart streamer ~p died with reason ~p",
[ParserRef, Reason]),
couch_log:error("Multipart streamer ~p died with reason ~p",
[ParserRef, Reason]),
throw({error, Reason})
end.

Expand Down
2 changes: 1 addition & 1 deletion src/couch_drv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ init([]) ->
ok ->
{ok, nil};
{error, already_loaded} ->
?LOG_INFO("~p reloading couch_icu_driver", [?MODULE]),
couch_log:info("~p reloading couch_icu_driver", [?MODULE]),
ok = erl_ddll:reload(LibDir, "couch_icu_driver"),
{ok, nil};
{error, Error} ->
Expand Down
4 changes: 2 additions & 2 deletions src/couch_external_manager.erl
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ handle_cast(_Whatever, State) ->
{noreply, State}.

handle_info({'EXIT', Pid, normal}, Handlers) ->
?LOG_INFO("EXTERNAL: Server ~p terminated normally", [Pid]),
couch_log:info("EXTERNAL: Server ~p terminated normally", [Pid]),
% The process terminated normally without us asking - Remove Pid from the
% handlers table so we don't attempt to reuse it
ets:match_delete(Handlers, {'_', Pid}),
{noreply, Handlers};

handle_info({'EXIT', Pid, Reason}, Handlers) ->
?LOG_INFO("EXTERNAL: Server ~p died. (reason: ~p)", [Pid, Reason]),
couch_log:info("EXTERNAL: Server ~p died. (reason: ~p)", [Pid, Reason]),
% Remove Pid from the handlers table so we don't try closing
% it a second time in terminate/2.
ets:match_delete(Handlers, {'_', Pid}),
Expand Down
9 changes: 5 additions & 4 deletions src/couch_external_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ execute(Pid, JsonReq) ->
% Gen Server Handlers

init([Name, Command]) ->
?LOG_INFO("EXTERNAL: Starting process for: ~s", [Name]),
?LOG_INFO("COMMAND: ~s", [Command]),
couch_log:info("EXTERNAL: Starting process for: ~s", [Name]),
couch_log:info("COMMAND: ~s", [Command]),
process_flag(trap_exit, true),
Timeout = list_to_integer(config:get("couchdb", "os_process_timeout",
"5000")),
Expand All @@ -63,11 +63,12 @@ handle_info(restart_config_listener, State) ->
handle_info({'EXIT', _Pid, normal}, State) ->
{noreply, State};
handle_info({'EXIT', Pid, Reason}, {Name, Command, Pid}) ->
?LOG_INFO("EXTERNAL: Process for ~s exiting. (reason: ~w)", [Name, Reason]),
couch_log:info("EXTERNAL: Process for ~s exiting. (reason: ~w)",
[Name, Reason]),
{stop, Reason, {Name, Command, Pid}}.

handle_cast(stop, {Name, Command, Pid}) ->
?LOG_INFO("EXTERNAL: Shutting down ~s", [Name]),
couch_log:info("EXTERNAL: Shutting down ~s", [Name]),
exit(Pid, normal),
{stop, normal, {Name, Command, Pid}};
handle_cast(_Whatever, State) ->
Expand Down
4 changes: 2 additions & 2 deletions src/couch_file.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ open(Filepath, Options) ->
case {lists:member(nologifmissing, Options), Reason} of
{true, enoent} -> ok;
_ ->
?LOG_ERROR("Could not open file ~s: ~s",
[Filepath, file:format_error(Reason)])
couch_log:error("Could not open file ~s: ~s",
[Filepath, file:format_error(Reason)])
end,
Error
end;
Expand Down
Loading