couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vatam...@apache.org
Subject [06/50] couch-replicator commit: updated refs/heads/63012-scheduler to 27a5eae
Date Tue, 14 Mar 2017 19:26:01 GMT
Re-create missing design doc if it is not found.

Previously only created the document when a new replicator db was created or
was found. Howver, user can delete the design document anytime. When they,
query the _scheduler/docs endpoint, the query would crash as the view will
not be there.

So to fix, when querying the view and it is missing, try to re-create it.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/commit/3bb565ad
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/3bb565ad
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/3bb565ad

Branch: refs/heads/63012-scheduler
Commit: 3bb565ade9799a74a037ea3d822450228e232c37
Parents: b759481
Author: Nick Vatamaniuc <vatamane@apache.org>
Authored: Thu Oct 20 17:56:05 2016 -0400
Committer: Nick Vatamaniuc <vatamane@apache.org>
Committed: Mon Oct 24 13:59:25 2016 -0400

----------------------------------------------------------------------
 src/couch_replicator.erl      | 11 +++++++++--
 src/couch_replicator_docs.erl | 10 ++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/3bb565ad/src/couch_replicator.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator.erl b/src/couch_replicator.erl
index 0bfd9f6..a8d4608 100644
--- a/src/couch_replicator.erl
+++ b/src/couch_replicator.erl
@@ -164,8 +164,15 @@ stream_terminal_docs_info(Db, Cb, UserAcc, States) ->
     try fabric:query_view(Db, DDoc, View, QueryCb, Acc, Args) of
     {ok, {Db, Cb, UserAcc1, States}} ->
         UserAcc1
-    catch error:database_does_not_exist ->
-        UserAcc
+    catch
+        error:database_does_not_exist ->
+            UserAcc;
+        error:{badmatch, {not_found, Reason}} ->
+            Msg = "Could not find _design/~s ~s view in replicator db ~s : ~p",
+            couch_log:error(Msg, [DDoc, View, Db, Reason]),
+            couch_replicator_docs:ensure_cluster_rep_ddoc_exists(Db),
+            timer:sleep(1000),
+            stream_terminal_docs_info(Db, Cb, UserAcc, States)
     end.
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/3bb565ad/src/couch_replicator_docs.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_docs.erl b/src/couch_replicator_docs.erl
index aeb9219..e27aad6 100644
--- a/src/couch_replicator_docs.erl
+++ b/src/couch_replicator_docs.erl
@@ -16,6 +16,7 @@
 -export([parse_rep_doc_without_id/1, parse_rep_doc_without_id/2]).
 -export([before_doc_update/2, after_doc_read/2]).
 -export([ensure_rep_db_exists/0, ensure_rep_ddoc_exists/1]).
+-export([ensure_cluster_rep_ddoc_exists/1]).
 -export([
     remove_state_fields/2,
     update_doc_completed/3,
@@ -28,6 +29,7 @@
 
 -include_lib("couch/include/couch_db.hrl").
 -include_lib("ibrowse/include/ibrowse.hrl").
+-include_lib("mem3/include/mem3.hrl").
 -include("couch_replicator_api_wrap.hrl").
 -include("couch_replicator.hrl").
 
@@ -134,6 +136,14 @@ ensure_rep_ddoc_exists(RepDb, DDocId) ->
     end,
     ok.
 
+
+-spec ensure_cluster_rep_ddoc_exists(binary()) -> ok.
+ensure_cluster_rep_ddoc_exists(RepDb) ->
+    DDocId = ?REP_DESIGN_DOC,
+    [#shard{name = DbShard} | _] = mem3:shards(RepDb, DDocId),
+    ensure_rep_ddoc_exists(DbShard, DDocId).
+
+
 -spec compare_ejson({[_]}, {[_]}) -> boolean().
 compare_ejson(EJson1, EJson2) ->
     EjsonSorted1 = couch_replicator_filters:ejsort(EJson1),


Mime
View raw message