summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Sun <tony.sun@cloudant.com>2017-05-23 13:05:15 -0700
committerTony Sun <tony.sun@cloudant.com>2017-05-23 13:05:15 -0700
commit1aaf1b22bd6d2addf439f1096a93e16547f1186f (patch)
treef80c33863575925ad46d97b3f5c4dc04e7eedd04
parentfe972cbd1448815bdf25c97d1322a4ee16dc4653 (diff)
downloadcouchdb-3423-add-try-catch-mem3.tar.gz
catch database not exist error3423-add-try-catch-mem3
If dbs do not exist, we catch the error for mem3_sync_security so that it can continue for databases that do exist. COUCHDB-3423
-rw-r--r--src/mem3/src/mem3_sync_security.erl14
-rw-r--r--src/mem3/test/mem3_sync_security_test.erl29
2 files changed, 41 insertions, 2 deletions
diff --git a/src/mem3/src/mem3_sync_security.erl b/src/mem3/src/mem3_sync_security.erl
index 9edd0ec57..291e4e085 100644
--- a/src/mem3/src/mem3_sync_security.erl
+++ b/src/mem3/src/mem3_sync_security.erl
@@ -44,10 +44,20 @@ maybe_sync_int(#shard{name=Name}=Src, Dst) ->
go() ->
{ok, Dbs} = fabric:all_dbs(),
- lists:foreach(fun handle_db/1, Dbs).
+ lists:foreach(fun handle_existing_db/1, Dbs).
go(DbName) when is_binary(DbName) ->
- handle_db(DbName).
+ handle_existing_db(DbName).
+
+handle_existing_db(DbName) ->
+ try handle_db(DbName) of
+ _ -> ok
+ catch
+ error:database_does_not_exist->
+ couch_log:error("Db was deleted while getting security"
+ " object. DbName: ~p", [DbName]),
+ ok
+ end.
handle_db(DbName) ->
ShardCount = length(mem3:shards(DbName)),
diff --git a/src/mem3/test/mem3_sync_security_test.erl b/src/mem3/test/mem3_sync_security_test.erl
new file mode 100644
index 000000000..8b6af3c0f
--- /dev/null
+++ b/src/mem3/test/mem3_sync_security_test.erl
@@ -0,0 +1,29 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(mem3_sync_security_test).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+-include("mem3.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+go_test() ->
+ Ctx = test_util:start_couch([fabric, mem3]),
+ ok = meck:new(fabric, [passthrough]),
+ meck:expect(fabric, all_dbs, fun() ->
+ {ok, [<<"NoExistDb1">>, <<"NoExistDb2">>]}
+ end),
+ Result = mem3_sync_security:go(),
+ meck:unload(fabric),
+ test_util:stop_couch(Ctx),
+ ?assertEqual(ok, Result).