summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2010-11-23 15:50:26 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2010-11-23 15:50:26 +0000
commit5dcc10a9ad8b180431bee49cc1b36a8f0859ff71 (patch)
tree9014fbe569ae9af2c3ad91027a1729ecafe79e8a
parent1b07ac052dd87d5dd255ebc328e9b8e66fac21c5 (diff)
Merged revision 1038172 from trunk:
Replicator DB: added underscore prefix to the replication document fields that are meant to to be set/updated only by the replicator. This makes it more clear to end users that those fields are meant to be used internally by CouchDB. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1038173 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--share/www/script/test/replicator_db.js52
-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
4 files changed, 51 insertions, 40 deletions
diff --git a/share/www/script/test/replicator_db.js b/share/www/script/test/replicator_db.js
index 00168695..7df57a8c 100644
--- a/share/www/script/test/replicator_db.js
+++ b/share/www/script/test/replicator_db.js
@@ -45,7 +45,7 @@ couchTests.replicator_db = function(debug) {
do {
newRep = repDb.open(repDoc._id);
t1 = new Date();
- } while (((t1 - t0) <= ms) && newRep.state !== state);
+ } while (((t1 - t0) <= ms) && newRep._replication_state !== state);
}
function waitForSeq(sourceDb, targetDb) {
@@ -103,8 +103,8 @@ couchTests.replicator_db = function(debug) {
T(repDoc1 !== null);
T(repDoc1.source === repDoc.source);
T(repDoc1.target === repDoc.target);
- T(repDoc1.state === "completed", "simple");
- T(typeof repDoc1.replication_id === "string");
+ T(repDoc1._replication_state === "completed", "simple");
+ T(typeof repDoc1._replication_id === "string");
}
@@ -154,8 +154,8 @@ couchTests.replicator_db = function(debug) {
T(repDoc1 !== null);
T(repDoc1.source === repDoc.source);
T(repDoc1.target === repDoc.target);
- T(repDoc1.state === "completed", "filtered");
- T(typeof repDoc1.replication_id === "string");
+ T(repDoc1._replication_state === "completed", "filtered");
+ T(typeof repDoc1._replication_id === "string");
}
@@ -197,8 +197,8 @@ couchTests.replicator_db = function(debug) {
T(repDoc1 !== null);
T(repDoc1.source === repDoc.source);
T(repDoc1.target === repDoc.target);
- T(repDoc1.state === "triggered");
- T(typeof repDoc1.replication_id === "string");
+ T(repDoc1._replication_state === "triggered");
+ T(typeof repDoc1._replication_id === "string");
// add a design doc to source, it will be replicated to target
// when the "user_ctx" property is not defined in the replication doc,
@@ -311,8 +311,8 @@ couchTests.replicator_db = function(debug) {
T(repDoc1_copy !== null);
T(repDoc1_copy.source === repDoc1.source);
T(repDoc1_copy.target === repDoc1.target);
- T(repDoc1_copy.state === "completed");
- T(typeof repDoc1_copy.replication_id === "string");
+ T(repDoc1_copy._replication_state === "completed");
+ T(typeof repDoc1_copy._replication_id === "string");
var newDoc = {
_id: "doc666",
@@ -341,9 +341,9 @@ couchTests.replicator_db = function(debug) {
T(repDoc2_copy !== null);
T(repDoc2_copy.source === repDoc1.source);
T(repDoc2_copy.target === repDoc1.target);
- T(repDoc2_copy.state === "completed");
- T(typeof repDoc2_copy.replication_id === "string");
- T(repDoc2_copy.replication_id === repDoc1_copy.replication_id);
+ T(repDoc2_copy._replication_state === "completed");
+ T(typeof repDoc2_copy._replication_id === "string");
+ T(repDoc2_copy._replication_id === repDoc1_copy._replication_id);
}
@@ -377,13 +377,13 @@ couchTests.replicator_db = function(debug) {
repDoc1 = repDb.open("foo_dup_rep_doc_1");
T(repDoc1 !== null);
- T(repDoc1.state === "completed", "identical");
- T(typeof repDoc1.replication_id === "string");
+ T(repDoc1._replication_state === "completed", "identical");
+ T(typeof repDoc1._replication_id === "string");
repDoc2 = repDb.open("foo_dup_rep_doc_2");
T(repDoc2 !== null);
- T(typeof repDoc2.state === "undefined");
- T(repDoc2.replication_id === repDoc1.replication_id);
+ T(typeof repDoc2._replication_state === "undefined");
+ T(repDoc2._replication_id === repDoc1._replication_id);
}
@@ -419,13 +419,13 @@ couchTests.replicator_db = function(debug) {
repDoc1 = repDb.open("foo_dup_cont_rep_doc_1");
T(repDoc1 !== null);
- T(repDoc1.state === "triggered");
- T(typeof repDoc1.replication_id === "string");
+ T(repDoc1._replication_state === "triggered");
+ T(typeof repDoc1._replication_id === "string");
repDoc2 = repDb.open("foo_dup_cont_rep_doc_2");
T(repDoc2 !== null);
- T(typeof repDoc2.state === "undefined");
- T(repDoc2.replication_id === repDoc1.replication_id);
+ T(typeof repDoc2._replication_state === "undefined");
+ T(repDoc2._replication_id === repDoc1._replication_id);
var newDoc = {
_id: "foo666",
@@ -443,7 +443,7 @@ couchTests.replicator_db = function(debug) {
T(repDb.deleteDoc(repDoc2).ok);
repDoc1 = repDb.open("foo_dup_cont_rep_doc_1");
T(repDoc1 !== null);
- T(repDoc1.state === "triggered");
+ T(repDoc1._replication_state === "triggered");
var newDoc2 = {
_id: "foo5000",
@@ -709,10 +709,10 @@ couchTests.replicator_db = function(debug) {
T(repDoc1 !== null);
T(repDoc1.source === repDoc.source);
T(repDoc1.target === repDoc.target);
- T(repDoc1.state === "completed",
+ T(repDoc1._replication_state === "completed",
"replication document with bad replication id failed");
- T(typeof repDoc1.replication_id === "string");
- T(repDoc1.replication_id !== "1234abc");
+ T(typeof repDoc1._replication_id === "string");
+ T(repDoc1._replication_id !== "1234abc");
}
@@ -729,8 +729,8 @@ couchTests.replicator_db = function(debug) {
waitForRep(repDb, repDoc, "error");
var repDoc1 = repDb.open(repDoc._id);
T(repDoc1 !== null);
- T(repDoc1.state === "error");
- T(typeof repDoc1.replication_id === "string");
+ T(repDoc1._replication_state === "error");
+ T(typeof repDoc1._replication_id === "string");
}
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) ->