From d0fd91529110be9ac4d4dcb5e42da2bc30d5bf0f Mon Sep 17 00:00:00 2001 From: Noah Shaw Date: Tue, 12 Jul 2022 16:21:21 -0500 Subject: [PATCH] Fix not_found error smoosh --- src/smoosh/src/smoosh_channel.erl | 54 ++++++++++++++++++++----------- src/smoosh/src/smoosh_server.erl | 18 ++++++++--- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/smoosh/src/smoosh_channel.erl b/src/smoosh/src/smoosh_channel.erl index 04b74864915..7671d120b67 100644 --- a/src/smoosh/src/smoosh_channel.erl +++ b/src/smoosh/src/smoosh_channel.erl @@ -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 @@ -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) -> diff --git a/src/smoosh/src/smoosh_server.erl b/src/smoosh/src/smoosh_server.erl index ffd7961b90b..5e66258c3d1 100644 --- a/src/smoosh/src/smoosh_server.erl +++ b/src/smoosh/src/smoosh_server.erl @@ -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),