couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1038665 - in /couchdb/trunk: share/www/script/test/replicator_db.js src/couchdb/couch_doc.erl src/couchdb/couch_rep.erl
Date Wed, 24 Nov 2010 16:10:00 GMT
Author: fdmanana
Date: Wed Nov 24 16:09:59 2010
New Revision: 1038665

URL: http://svn.apache.org/viewvc?rev=1038665&view=rev
Log:
Replicator DB: added _replication_state_time (a unix timestamp value) to replication documents.

Modified:
    couchdb/trunk/share/www/script/test/replicator_db.js
    couchdb/trunk/src/couchdb/couch_doc.erl
    couchdb/trunk/src/couchdb/couch_rep.erl

Modified: couchdb/trunk/share/www/script/test/replicator_db.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/replicator_db.js?rev=1038665&r1=1038664&r2=1038665&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/replicator_db.js (original)
+++ couchdb/trunk/share/www/script/test/replicator_db.js Wed Nov 24 16:09:59 2010
@@ -104,6 +104,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1.source === repDoc.source);
     T(repDoc1.target === repDoc.target);
     T(repDoc1._replication_state === "completed", "simple");
+    T(typeof repDoc1._replication_state_time === "number");
     T(typeof repDoc1._replication_id  === "string");
   }
 
@@ -155,6 +156,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1.source === repDoc.source);
     T(repDoc1.target === repDoc.target);
     T(repDoc1._replication_state === "completed", "filtered");
+    T(typeof repDoc1._replication_state_time === "number");
     T(typeof repDoc1._replication_id  === "string");
   }
 
@@ -198,6 +200,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1.source === repDoc.source);
     T(repDoc1.target === repDoc.target);
     T(repDoc1._replication_state === "triggered");
+    T(typeof repDoc1._replication_state_time === "number");
     T(typeof repDoc1._replication_id  === "string");
 
     // add a design doc to source, it will be replicated to target
@@ -312,6 +315,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1_copy.source === repDoc1.source);
     T(repDoc1_copy.target === repDoc1.target);
     T(repDoc1_copy._replication_state === "completed");
+    T(typeof repDoc1_copy._replication_state_time === "number");
     T(typeof repDoc1_copy._replication_id  === "string");
 
     var newDoc = {
@@ -342,6 +346,7 @@ couchTests.replicator_db = function(debu
     T(repDoc2_copy.source === repDoc1.source);
     T(repDoc2_copy.target === repDoc1.target);
     T(repDoc2_copy._replication_state === "completed");
+    T(typeof repDoc2_copy._replication_state_time === "number");
     T(typeof repDoc2_copy._replication_id === "string");
     T(repDoc2_copy._replication_id === repDoc1_copy._replication_id);
   }
@@ -378,11 +383,13 @@ couchTests.replicator_db = function(debu
     repDoc1 = repDb.open("foo_dup_rep_doc_1");
     T(repDoc1 !== null);
     T(repDoc1._replication_state === "completed", "identical");
+    T(typeof repDoc1._replication_state_time === "number");
     T(typeof repDoc1._replication_id  === "string");
 
     repDoc2 = repDb.open("foo_dup_rep_doc_2");
     T(repDoc2 !== null);
     T(typeof repDoc2._replication_state === "undefined");
+    T(typeof repDoc2._replication_state_time === "undefined");
     T(repDoc2._replication_id === repDoc1._replication_id);
   }
 
@@ -420,11 +427,13 @@ couchTests.replicator_db = function(debu
     repDoc1 = repDb.open("foo_dup_cont_rep_doc_1");
     T(repDoc1 !== null);
     T(repDoc1._replication_state === "triggered");
+    T(typeof repDoc1._replication_state_time === "number");
     T(typeof repDoc1._replication_id  === "string");
 
     repDoc2 = repDb.open("foo_dup_cont_rep_doc_2");
     T(repDoc2 !== null);
     T(typeof repDoc2._replication_state === "undefined");
+    T(typeof repDoc2._replication_state_time === "undefined");
     T(repDoc2._replication_id === repDoc1._replication_id);
 
     var newDoc = {
@@ -444,6 +453,7 @@ couchTests.replicator_db = function(debu
     repDoc1 = repDb.open("foo_dup_cont_rep_doc_1");
     T(repDoc1 !== null);
     T(repDoc1._replication_state === "triggered");
+    T(typeof repDoc1._replication_state_time === "number");
 
     var newDoc2 = {
         _id: "foo5000",
@@ -711,6 +721,7 @@ couchTests.replicator_db = function(debu
     T(repDoc1.target === repDoc.target);
     T(repDoc1._replication_state === "completed",
       "replication document with bad replication id failed");
+    T(typeof repDoc1._replication_state_time === "number");
     T(typeof repDoc1._replication_id  === "string");
     T(repDoc1._replication_id !== "1234abc");
   }
@@ -730,6 +741,7 @@ couchTests.replicator_db = function(debu
     var repDoc1 = repDb.open(repDoc._id);
     T(repDoc1 !== null);
     T(repDoc1._replication_state === "error");
+    T(typeof repDoc1._replication_state_time === "number");
     T(typeof repDoc1._replication_id  === "string");
   }
 

Modified: couchdb/trunk/src/couchdb/couch_doc.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_doc.erl?rev=1038665&r1=1038664&r2=1038665&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_doc.erl (original)
+++ couchdb/trunk/src/couchdb/couch_doc.erl Wed Nov 24 16:09:59 2010
@@ -256,6 +256,9 @@ transfer_fields([{<<"_deleted_conflicts"
 transfer_fields([{<<"_replication_state">>, _} = Field | Rest],
     #doc{body=Fields} = Doc) ->
     transfer_fields(Rest, Doc#doc{body=[Field|Fields]});
+transfer_fields([{<<"_replication_state_time">>, _} = 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]});

Modified: couchdb/trunk/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=1038665&r1=1038664&r2=1038665&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Wed Nov 24 16:09:59 2010
@@ -854,8 +854,15 @@ update_rep_doc({Props} = _RepDoc, KVs) -
 
 update_rep_doc(RepDb, #doc{body = {RepDocBody}} = RepDoc, KVs) ->
     NewRepDocBody = lists:foldl(
-        fun({K, _V} = KV, Body) ->
-            lists:keystore(K, 1, Body, KV)
+        fun({<<"_replication_state">> = K, _V} = KV, Body) ->
+                Body1 = lists:keystore(K, 1, Body, KV),
+                {Mega, Secs, _} = erlang:now(),
+                UnixTime = Mega * 1000000 + Secs,
+                lists:keystore(
+                    <<"_replication_state_time">>, 1,
+                    Body1, {<<"_replication_state_time">>, UnixTime});
+            ({K, _V} = KV, Body) ->
+                lists:keystore(K, 1, Body, KV)
         end,
         RepDocBody,
         KVs



Mime
View raw message