summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Sun <tony.sun427@gmail.com>2020-09-14 11:12:47 -0700
committerjiangph <jiangph@cn.ibm.com>2020-11-07 08:27:04 +0800
commitca9df691448253b7cb051de91a5e2554755f5659 (patch)
tree9c9a539288faeeb0fc0815b731de3d83d9aae48f
parent0a66d5b6720b716a45f5ce1ea02485210ef555df (diff)
downloadcouchdb-3.x-re-monitor-compaction-pid.tar.gz
fix race condition (#3150)3.x-re-monitor-compaction-pid
This fixes a94e693f32672e4613bce0d80d0b9660f85275ea because a race condition exisited where the 'DOWN' message could be received before the compactor pid is spawned. Adding a synchronous call to get the compactor pid guarantees that the couch_db_updater process handling of finish_compaction has occurred.
-rw-r--r--src/couch/src/couch_db.erl9
-rw-r--r--src/smoosh/src/smoosh_channel.erl2
2 files changed, 10 insertions, 1 deletions
diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index e1d726dc9..390a198df 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -37,6 +37,7 @@
get_committed_update_seq/1,
get_compacted_seq/1,
get_compactor_pid/1,
+ get_compactor_pid_sync/1,
get_db_info/1,
get_partition_info/2,
get_del_doc_count/1,
@@ -572,6 +573,14 @@ get_compacted_seq(#db{}=Db) ->
get_compactor_pid(#db{compactor_pid = Pid}) ->
Pid.
+get_compactor_pid_sync(#db{main_pid=Pid}=Db) ->
+ case gen_server:call(Pid, compactor_pid, infinity) of
+ CPid when is_pid(CPid) ->
+ CPid;
+ _ ->
+ nil
+ end.
+
get_db_info(Db) ->
#db{
name = Name,
diff --git a/src/smoosh/src/smoosh_channel.erl b/src/smoosh/src/smoosh_channel.erl
index 2a45c17dc..2bc98be9d 100644
--- a/src/smoosh/src/smoosh_channel.erl
+++ b/src/smoosh/src/smoosh_channel.erl
@@ -293,7 +293,7 @@ start_compact(State, Db) ->
maybe_remonitor_cpid(State, DbName, Reason) when is_binary(DbName) ->
{ok, Db} = couch_db:open_int(DbName, []),
- case couch_db:get_compactor_pid(Db) of
+ case couch_db:get_compactor_pid_sync(Db) of
nil ->
couch_log:warning("exit for compaction of ~p: ~p",
[smoosh_utils:stringify(DbName), Reason]),