You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ji...@apache.org on 2018/06/21 13:36:03 UTC

[couchdb] branch COUCHDB-3326-clustered-purge-pr5-implementation updated: Refactor on EPI approach

This is an automated email from the ASF dual-hosted git repository.

jiangphcn pushed a commit to branch COUCHDB-3326-clustered-purge-pr5-implementation
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/COUCHDB-3326-clustered-purge-pr5-implementation by this push:
     new 9556d86  Refactor on EPI approach
9556d86 is described below

commit 9556d86920266a1ecdeb838055f43407056051d8
Author: jiangphcn <ji...@cn.ibm.com>
AuthorDate: Thu Jun 21 21:34:49 2018 +0800

    Refactor on EPI approach
    
       - add error handling
       - simplfy verify_index_exists/1
    
    COUCHDB-3326
---
 src/couch/src/couch_db.erl                         | 16 +++++---
 src/couch_mrview/src/couch_mrview_index.erl        | 43 +++++++++-------------
 .../test/couch_mrview_purge_docs_tests.erl         |  1 -
 3 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index bbf7537..ed089fb 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -477,22 +477,28 @@ purge_client_exists(DbName, DocId, Props) ->
     try
         Type = couch_util:get_value(<<"type">>, Props),
         CheckFun = get_purge_client_fun(Type),
+        if CheckFun =/= undefined -> ok; true ->
+            Fmt1 = "Failed to get client function using '~p' document in
+                database '~p'",
+            couch_log:error(Fmt1, [DbName, DocId]),
+            throw(failed)
+        end,
         Exists = CheckFun(Props),
         if not Exists -> ok; true ->
             Updated = couch_util:get_value(<<"updated_on">>, Props),
             if is_integer(Updated) and Updated > LagThreshold -> ok; true ->
                 Diff = NowSecs - Updated,
-                Fmt1 = "Purge checkpoint '~s' not updated in ~p seconds",
-                couch_log:error(Fmt1, [DocId, Diff])
+                Fmt2 = "Purge checkpoint '~s' not updated in ~p seconds",
+                couch_log:error(Fmt2, [DocId, Diff])
             end
         end,
         Exists
     catch _:_ ->
         % If we fail to check for a client we have to assume that
         % it exists.
-        Fmt2 = "Failed to check purge checkpoint using
-            document '~p' on database ~p",
-        couch_log:error(Fmt2, [DbName, DocId]),
+        Fmt3 = "Failed to check purge checkpoint using
+            document '~p' in database ~p",
+        couch_log:error(Fmt3, [DbName, DocId]),
         true
     end.
 
diff --git a/src/couch_mrview/src/couch_mrview_index.erl b/src/couch_mrview/src/couch_mrview_index.erl
index 02b8941..e8457f7 100644
--- a/src/couch_mrview/src/couch_mrview_index.erl
+++ b/src/couch_mrview/src/couch_mrview_index.erl
@@ -232,33 +232,26 @@ verify_index_exists(Props) ->
         <<"signature">>,
         Props
     ),
-    case couch_db:open_int(ShardDbName, []) of
-        {ok, Db} ->
-            try
-                DbName = mem3:dbname(couch_db:name(Db)),
-                case ddoc_cache:open(DbName, DDocId) of
-                    {ok, DDoc} ->
-                        {ok, IdxState} = couch_mrview_util:ddoc_to_mrst(
-                            ShardDbName,
-                            DDoc
-                        ),
-                        IdxSig = IdxState#mrst.sig,
-                        couch_index_util:hexsig(IdxSig) == SigInLocal;
-                    _Else ->
-                        false
-                end
-            catch E:T ->
-                Stack = erlang:get_stacktrace(),
-                couch_log:error(
-                    "Error occurs when verifying existence of ~s/~s :: ~p ~p",
-                    [ShardDbName, DDocId, {E, T}, Stack]
+    try
+        DbName = mem3:dbname(ShardDbName),
+        case ddoc_cache:open(DbName, DDocId) of
+            {ok, DDoc} ->
+                {ok, IdxState} = couch_mrview_util:ddoc_to_mrst(
+                    ShardDbName,
+                    DDoc
                 ),
+                IdxSig = IdxState#mrst.sig,
+                couch_index_util:hexsig(IdxSig) == SigInLocal;
+            _Else ->
                 false
-            after
-                catch couch_db:close(Db)
-            end;
-        _ ->
-            false
+        end
+    catch E:T ->
+        Stack = erlang:get_stacktrace(),
+        couch_log:error(
+            "Error occurs when verifying existence of ~s/~s :: ~p ~p",
+            [ShardDbName, DDocId, {E, T}, Stack]
+        ),
+        false
     end.
 
 
diff --git a/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl b/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl
index d5bf9f6..6aa7a0e 100644
--- a/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl
+++ b/src/couch_mrview/test/couch_mrview_purge_docs_tests.erl
@@ -375,7 +375,6 @@ test_purge_compact_for_stale_purge_cp_with_client(Db) ->
         % run query again to reflect purge requests
         % to mrview
         {ok, Db2} = couch_db:reopen(Db1),
-        _Result1 = run_query(Db2, []),
         {ok, PurgedIdRevs} = couch_db:fold_purge_infos(
                 Db2,
                 0,