couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonysu...@apache.org
Subject [couchdb] 01/01: catch database not exist error
Date Tue, 23 May 2017 20:02:44 GMT
This is an automated email from the ASF dual-hosted git repository.

tonysun83 pushed a commit to branch 3423-add-try-catch-mem3
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 1aaf1b22bd6d2addf439f1096a93e16547f1186f
Author: Tony Sun <tony.sun@cloudant.com>
AuthorDate: Tue May 23 13:05:15 2017 -0700

    catch database not exist error
    
    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
---
 src/mem3/src/mem3_sync_security.erl       | 14 ++++++++++++--
 src/mem3/test/mem3_sync_security_test.erl | 29 +++++++++++++++++++++++++++++
 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 9edd0ec..291e4e0 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 0000000..8b6af3c
--- /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).

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

Mime
View raw message