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/05/02 18:15:01 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 81ee7c5 Fix error on race condition in mem3 startup
81ee7c5 is described below
commit 81ee7c5ac71e617a03e967b4fc5d0358f4ba9459
Author: Joan Touzet <jo...@atypical.net>
AuthorDate: Sun Apr 30 02:49:20 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 makes `mem3_util:ensure_enxists/1` more robust in the face of
a race to create `_dbs`.
Fixes COUCHDB-3402.
Approved by @davisp and @iilyak
---
src/mem3/src/mem3_util.erl | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
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.
--
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].