couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [2/2] couchdb-cassim git commit: Add get_security retry logic for handling conflicts
Date Thu, 23 Apr 2015 23:50:52 GMT
Add get_security retry logic for handling conflicts


Project: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/commit/47ed4c46
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/tree/47ed4c46
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-cassim/diff/47ed4c46

Branch: refs/heads/2657-fix-cassim-fabric-calls
Commit: 47ed4c4619b4be547d3804f33218ed32261167c3
Parents: e67d7ee
Author: Russell Branca <chewbranca@apache.org>
Authored: Thu Apr 23 23:50:18 2015 +0000
Committer: Russell Branca <chewbranca@apache.org>
Committed: Thu Apr 23 23:50:18 2015 +0000

----------------------------------------------------------------------
 src/cassim_security.erl | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-cassim/blob/47ed4c46/src/cassim_security.erl
----------------------------------------------------------------------
diff --git a/src/cassim_security.erl b/src/cassim_security.erl
index 796cd67..c094c85 100644
--- a/src/cassim_security.erl
+++ b/src/cassim_security.erl
@@ -52,14 +52,30 @@ get_security(DbName, Options) ->
     end.
 
 
-get_security_doc(DbName0) when is_binary(DbName0) ->
+get_security_doc(DbName) when is_binary(DbName) ->
+    RetryCnt = config:get_integer("cassim", "get_security_retries", 3),
+    get_security_doc(DbName, RetryCnt).
+
+
+get_security_doc(DbName, RetryCnt) when RetryCnt =< 0 ->
+    couch_log:error(
+        "Exhausted retry limit loading security doc for db ~s", [DbName]
+    ),
+    throw({retries_limit_exhaused, "Exhaused security doc retry limit"});
+get_security_doc(DbName0, RetryCnt) ->
     DbName = mem3:dbname(DbName0),
     MetaId = cassim_metadata_cache:security_meta_id(DbName),
     case cassim_metadata_cache:load_meta(MetaId) of
         undefined ->
             SecProps = fabric:get_security(DbName),
-            {ok, SecDoc} = migrate_security_props(DbName, SecProps),
-            SecDoc;
+            try migrate_security_props(DbName, SecProps) of
+                {ok, SecDoc} ->
+                    SecDoc
+            catch conflict ->
+                get_security_doc(DbName0, RetryCnt-1)
+            end;
+        %% TODO: handle deleted case?
+        %% deleted ->
         {error, Error} ->
             throw(Error);
         SecProps ->


Mime
View raw message