You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wo...@apache.org on 2017/04/30 05:57:00 UTC

[couchdb] branch master updated: Fix error on race condition in mem3 startup

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

wohali pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git

The following commit(s) were added to refs/heads/master by this push:
       new  2689507   Fix error on race condition in mem3 startup
2689507 is described below

commit 2689507fc0f4a4a3731df34d3634bb1bcd4afbc3
Author: Joan Touzet <jo...@atypical.net>
AuthorDate: Sun Apr 30 01:43:32 2017 -0400

    Fix error on race condition in mem3 startup
    
    During mem3 startup, 2 paths attempt to call `couch_server:create/2` on
    `_dbs`:
    
    ```
    gen_server:init_it/6
      -> mem3_shards:init/1
        -> mem3_shards:get_update_seq/0
          -> couch_server:create/2
    ```
    
    and
    
    ```
    mem3_sync:initial_sync/1
      -> mem3_shards:fold/2
        -> couch_server:create/2
    ```
    
    Normally, the first path completes before the second. If the second path
    finishes first, the first path fails because it does not expect a
    `file_exists` response.
    
    This patch simply retries mem3_util:ensure_exists/1 once if it gets back
    a `file_exists` response. Any failures past this point are not handled.
    
    Fixes COUCHDB-3402.
---
 src/mem3/src/mem3_shards.erl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/mem3/src/mem3_shards.erl b/src/mem3/src/mem3_shards.erl
index 3c2001b..7182f09 100644
--- a/src/mem3/src/mem3_shards.erl
+++ b/src/mem3/src/mem3_shards.erl
@@ -315,7 +315,12 @@ fold_fun(#doc_info{}=DI, _, {Db, UFun, UAcc}) ->
 
 get_update_seq() ->
     DbName = config:get("mem3", "shards_db", "_dbs"),
-    {ok, Db} = mem3_util:ensure_exists(DbName),
+    case mem3_util:ensure_exists(DbName) of
+    {ok, Db} ->
+        {ok, Db};
+    file_exists ->
+        {ok, Db} = mem3_util:ensure_exists(DbName)
+    end,
     couch_db:close(Db),
     Db#db.update_seq.
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].