diff options
author | Joan Touzet <joant@atypical.net> | 2017-04-30 01:43:32 -0400 |
---|---|---|
committer | Joan Touzet <joant@atypical.net> | 2017-04-30 01:43:32 -0400 |
commit | 2689507fc0f4a4a3731df34d3634bb1bcd4afbc3 (patch) | |
tree | b61907c8ea28532862c8c038cf0961e3530704e1 | |
parent | fa2bcb53c7225150612519f8d9816fe757aec2d4 (diff) | |
download | couchdb-2689507fc0f4a4a3731df34d3634bb1bcd4afbc3.tar.gz |
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.
-rw-r--r-- | src/mem3/src/mem3_shards.erl | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mem3/src/mem3_shards.erl b/src/mem3/src/mem3_shards.erl index 3c2001b1b..7182f09da 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. |