Author: fdmanana
Date: Tue Nov 23 15:50:26 2010
New Revision: 1038173

URL: http://svn.apache.org/viewvc?rev=1038173&view=rev
Log:
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.


Modified:
    couchdb/branches/1.1.x/share/www/script/test/replicator_db.js
    couchdb/branches/1.1.x/src/couchdb/couch_doc.erl
    couchdb/branches/1.1.x/src/couchdb/couch_rep.erl
    couchdb/branches/1.1.x/src/couchdb/couch_rep_db_listener.erl

Modified: couchdb/branches/1.1.x/share/www/script/test/replicator_db.js
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/test/replicator_db.js?rev=1038173&r1=1038172&r2=1038173&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/test/replicator_db.js (original)
+++ couchdb/branches/1.1.x/share/www/script/test/replicator_db.js Tue Nov 23 
15:50:26 2010
@@ -45,7 +45,7 @@ couchTests.replicator_db = function(debu
     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(debu
     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(debu
     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(debu
     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(debu
     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(debu
     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(debu
 
     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(debu
 
     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(debu
     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(debu
     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(debu
     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");
   }
 
 

Modified: couchdb/branches/1.1.x/src/couchdb/couch_doc.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_doc.erl?rev=1038173&r1=1038172&r2=1038173&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_doc.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_doc.erl Tue Nov 23 15:50:26 2010
@@ -252,6 +252,14 @@ transfer_fields([{<<"_conflicts">>, _} |
 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,

Modified: couchdb/branches/1.1.x/src/couchdb/couch_rep.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_rep.erl?rev=1038173&r1=1038172&r2=1038173&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_rep.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_rep.erl Tue Nov 23 15:50:26 2010
@@ -263,12 +263,14 @@ handle_info({'EXIT', _Pid, Reason}, Stat
 
 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 = L
 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 = {RepDo
     ).
 
 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.

Modified: couchdb/branches/1.1.x/src/couchdb/couch_rep_db_listener.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_rep_db_listener.erl?rev=1038173&r1=1038172&r2=1038173&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_rep_db_listener.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_rep_db_listener.erl Tue Nov 23 
15:50:26 2010
@@ -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, JsonRepDo
 
 
 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, {
         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) ->


Reply via email to