You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by gi...@git.apache.org on 2017/05/02 16:42:49 UTC

[GitHub] iilyak commented on issue #501: Fix error on race condition in mem3 startup

iilyak commented on issue #501: Fix error on race condition in mem3 startup
URL: https://github.com/apache/couchdb/pull/501#issuecomment-298691336
 
 
   > Question: Why not call couch_db:open/2 with Options including create_if_missing once, and if that fails with file_exists, just call it again without that option?
   
   Thank you @wohali your suggestion is great. Following works locally:
   ```
   diff --git a/src/mem3/src/mem3_util.erl b/src/mem3/src/mem3_util.erl
   index 2cd444d..71ef5b6 100644
   --- a/src/mem3/src/mem3_util.erl
   +++ b/src/mem3/src/mem3_util.erl
   @@ -214,11 +214,12 @@ shard_info(DbName) ->
    ensure_exists(DbName) when is_list(DbName) ->
        ensure_exists(list_to_binary(DbName));
    ensure_exists(DbName) ->
   -    case couch_db:open(DbName, [nologifmissing, sys_db | [?ADMIN_CTX]]) of
   +    Options = [nologifmissing, sys_db, {create_if_missing, true}, ?ADMIN_CTX],
   +    case couch_db:open(DbName, Options) of
        {ok, Db} ->
            {ok, Db};
   -    _ ->
   -        couch_server:create(DbName, [?ADMIN_CTX])
   +    file_exists ->
   +        couch_db:open(DbName, [sys_db, ?ADMIN_CTX])
        end.
   ```
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services