Skip to content

Commit

Permalink
Fix not_found error smoosh
Browse files Browse the repository at this point in the history
  • Loading branch information
noahshaw11 authored and nickva committed Jul 15, 2022
1 parent 005843a commit d0fd915
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
54 changes: 35 additions & 19 deletions src/smoosh/src/smoosh_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,19 @@ maybe_start_compaction(State) ->
start_compact(State, DbName) when is_list(DbName) ->
start_compact(State, ?l2b(DbName));
start_compact(State, DbName) when is_binary(DbName) ->
{ok, Db} = couch_db:open_int(DbName, []),
try
start_compact(State, Db)
after
couch_db:close(Db)
case couch_db:open_int(DbName, []) of
{ok, Db} ->
try
start_compact(State, Db)
after
couch_db:close(Db)
end;
Error = {not_found, no_db_file} ->
couch_log:warning(
"Error starting compaction for ~p: ~p",
[smoosh_utils:stringify(DbName), Error]
),
false
end;
start_compact(State, {Shard, GroupId}) ->
case smoosh_utils:ignore_db({Shard, GroupId}) of
Expand Down Expand Up @@ -517,23 +525,31 @@ start_compact(State, Db) ->
end.

maybe_remonitor_cpid(State, DbName, Reason) when is_binary(DbName) ->
{ok, Db} = couch_db:open_int(DbName, []),
case couch_db:get_compactor_pid_sync(Db) of
nil ->
case couch_db:open_int(DbName, []) of
{ok, Db} ->
case couch_db:get_compactor_pid_sync(Db) of
nil ->
couch_log:warning(
"exit for compaction of ~p: ~p",
[smoosh_utils:stringify(DbName), Reason]
),
{ok, _} = timer:apply_after(5000, smoosh_server, enqueue, [DbName]),
State;
CPid ->
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]
),
erlang:monitor(process, CPid),
State#state{active = [{DbName, CPid} | State#state.active]}
end;
Error = {not_found, no_db_file} ->
couch_log:warning(
"exit for compaction of ~p: ~p",
[smoosh_utils:stringify(DbName), Reason]
),
{ok, _} = timer:apply_after(5000, smoosh_server, enqueue, [DbName]),
State;
CPid ->
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]
[smoosh_utils:stringify(DbName), Error]
),
erlang:monitor(process, CPid),
State#state{active = [{DbName, CPid} | State#state.active]}
State
end;
% not a database compaction, so ignore the pid check
maybe_remonitor_cpid(State, Key, Reason) ->
Expand Down
18 changes: 13 additions & 5 deletions src/smoosh/src/smoosh_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,19 @@ get_priority(Channel, {Shard, GroupId}) ->
get_priority(Channel, DbName) when is_list(DbName) ->
get_priority(Channel, ?l2b(DbName));
get_priority(Channel, DbName) when is_binary(DbName) ->
{ok, Db} = couch_db:open_int(DbName, []),
try
get_priority(Channel, Db)
after
couch_db:close(Db)
case couch_db:open_int(DbName, []) of
{ok, Db} ->
try
get_priority(Channel, Db)
after
couch_db:close(Db)
end;
Error = {not_found, no_db_file} ->
couch_log:warning(
"~p: Error getting priority for ~p: ~p",
[Channel, DbName, Error]
),
0
end;
get_priority(Channel, Db) ->
{ok, DocInfo} = couch_db:get_db_info(Db),
Expand Down

0 comments on commit d0fd915

Please sign in to comment.