summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_doc.erl8
-rw-r--r--src/couchdb/couch_rep.erl15
-rw-r--r--src/couchdb/couch_rep_db_listener.erl16
3 files changed, 25 insertions, 14 deletions
diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl
index f8c874b0..b014de2d 100644
--- a/src/couchdb/couch_doc.erl
+++ b/src/couchdb/couch_doc.erl
@@ -252,6 +252,14 @@ transfer_fields([{<<"_conflicts">>, _} | Rest], Doc) ->
transfer_fields([{<<"_deleted_conflicts">>, _} | Rest], Doc) ->
transfer_fields(Rest, Doc);
+% special fields for replication documents
+transfer_fields([{<<"_replication_state">>, _} = Field | Rest],
+ #doc{body=Fields} = Doc) ->
+ transfer_fields(Rest, Doc#doc{body=[Field|Fields]});
+transfer_fields([{<<"_replication_id">>, _} = Field | Rest],
+ #doc{body=Fields} = Doc) ->
+ transfer_fields(Rest, Doc#doc{body=[Field|Fields]});
+
% unknown special field
transfer_fields([{<<"_",Name/binary>>, _} | _], _) ->
throw({doc_validation,
diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl
index 8eaa99ee..663fd838 100644
--- a/src/couchdb/couch_rep.erl
+++ b/src/couchdb/couch_rep.erl
@@ -263,12 +263,14 @@ handle_info({'EXIT', _Pid, Reason}, State) ->
terminate(normal, #state{checkpoint_scheduled=nil} = State) ->
do_terminate(State),
- update_rep_doc(State#state.rep_doc, [{<<"state">>, <<"completed">>}]);
+ update_rep_doc(
+ State#state.rep_doc, [{<<"_replication_state">>, <<"completed">>}]);
terminate(normal, State) ->
timer:cancel(State#state.checkpoint_scheduled),
do_terminate(do_checkpoint(State)),
- update_rep_doc(State#state.rep_doc, [{<<"state">>, <<"completed">>}]);
+ update_rep_doc(
+ State#state.rep_doc, [{<<"_replication_state">>, <<"completed">>}]);
terminate(shutdown, #state{listeners = Listeners} = State) ->
% continuous replication stopped
@@ -278,7 +280,8 @@ terminate(shutdown, #state{listeners = Listeners} = State) ->
terminate(Reason, #state{listeners = Listeners} = State) ->
[gen_server:reply(L, {error, Reason}) || L <- Listeners],
terminate_cleanup(State),
- update_rep_doc(State#state.rep_doc, [{<<"state">>, <<"error">>}]).
+ update_rep_doc(
+ State#state.rep_doc, [{<<"_replication_state">>, <<"error">>}]).
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
@@ -866,15 +869,15 @@ update_rep_doc(RepDb, #doc{body = {RepDocBody}} = RepDoc, KVs) ->
).
maybe_set_triggered({RepProps} = RepDoc, RepId) ->
- case couch_util:get_value(<<"state">>, RepProps) of
+ case couch_util:get_value(<<"_replication_state">>, RepProps) of
<<"triggered">> ->
ok;
_ ->
update_rep_doc(
RepDoc,
[
- {<<"state">>, <<"triggered">>},
- {<<"replication_id">>, ?l2b(RepId)}
+ {<<"_replication_state">>, <<"triggered">>},
+ {<<"_replication_id">>, ?l2b(RepId)}
]
)
end.
diff --git a/src/couchdb/couch_rep_db_listener.erl b/src/couchdb/couch_rep_db_listener.erl
index 5a5ab164..e4e8b246 100644
--- a/src/couchdb/couch_rep_db_listener.erl
+++ b/src/couchdb/couch_rep_db_listener.erl
@@ -156,7 +156,7 @@ process_change({Change}) ->
true ->
rep_doc_deleted(DocId);
false ->
- case couch_util:get_value(<<"state">>, RepProps) of
+ case couch_util:get_value(<<"_replication_state">>, RepProps) of
<<"completed">> ->
replication_complete(DocId);
<<"error">> ->
@@ -166,8 +166,8 @@ process_change({Change}) ->
undefined ->
maybe_start_replication(DocId, JsonRepDoc);
_ ->
- ?LOG_ERROR("Invalid value for the `state` property of the "
- "replication document `~s`", [DocId])
+ ?LOG_ERROR("Invalid value for the `_replication_state` property"
+ " of the replication document `~s`", [DocId])
end
end,
ok.
@@ -201,13 +201,13 @@ maybe_start_replication(DocId, JsonRepDoc) ->
maybe_tag_rep_doc(DocId, {Props} = JsonRepDoc, RepId, OtherDocId) ->
- case couch_util:get_value(<<"replication_id">>, Props) of
+ case couch_util:get_value(<<"_replication_id">>, Props) of
RepId ->
ok;
_ ->
?LOG_INFO("The replication specified by the document `~s` was already"
" triggered by the document `~s`", [DocId, OtherDocId]),
- couch_rep:update_rep_doc(JsonRepDoc, [{<<"replication_id">>, RepId}])
+ couch_rep:update_rep_doc(JsonRepDoc, [{<<"_replication_id">>, RepId}])
end.
@@ -222,11 +222,11 @@ start_replication({RepProps} = RepDoc, {Base, Ext} = RepId, UserCtx) ->
couch_rep:update_rep_doc(
RepDoc,
[
- {<<"state">>, <<"error">>},
- {<<"replication_id">>, ?l2b(element(1, RepId))}
+ {<<"_replication_state">>, <<"error">>},
+ {<<"_replication_id">>, ?l2b(Base)}
]
),
- ?LOG_ERROR("Error starting replication ~p: ~p", [RepId, Error])
+ ?LOG_ERROR("Error starting replication `~s`: ~p", [Base ++ Ext, Error])
end.
rep_doc_deleted(DocId) ->