You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ji...@apache.org on 2020/11/06 13:47:24 UTC

[couchdb] branch 3.x-fix-compaction-race-condition created (now db872d0)

This is an automated email from the ASF dual-hosted git repository.

jiangphcn pushed a change to branch 3.x-fix-compaction-race-condition
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at db872d0  fix race condition (#3150)

This branch includes the following new commits:

     new db872d0  fix race condition (#3150)

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: fix race condition (#3150)

Posted by ji...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jiangphcn pushed a commit to branch 3.x-fix-compaction-race-condition
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit db872d0a2be7f5915c0dfba43db2914fdc501811
Author: Tony Sun <to...@gmail.com>
AuthorDate: Mon Sep 14 11:12:47 2020 -0700

    fix race condition (#3150)
    
    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.
---
 src/couch/src/couch_db.erl        | 9 +++++++++
 src/smoosh/src/smoosh_channel.erl | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index e1d726d..390a198 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 d8a8d14..058f551 100644
--- a/src/smoosh/src/smoosh_channel.erl
+++ b/src/smoosh/src/smoosh_channel.erl
@@ -276,7 +276,7 @@ start_compact(State, Db) ->
     false ->
         DbPid = couch_db:get_pid(Db),
         Key = couch_db:name(Db),
-        case couch_db:get_compactor_pid(Db) of
+        case couch_db:get_compactor_pid_sync(Db) of
             nil ->
                 Ref = erlang:monitor(process, DbPid),
                 DbPid ! {'$gen_call', {self(), Ref}, start_compact},