couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1139823 - in /couchdb/trunk: share/www/script/test/replication.js src/couchdb/couch_replicator.erl src/couchdb/couch_replicator_utils.erl
Date Sun, 26 Jun 2011 15:57:37 GMT
Author: fdmanana
Date: Sun Jun 26 15:57:36 2011
New Revision: 1139823

URL: http://svn.apache.org/viewvc?rev=1139823&view=rev
Log:
Add since_seq parameter to replication documents

This optional parameter allows a user to start a replication
from a specified source database sequence number (similar to
the ?since=SeqNum parameter for /db/_changes/). The advantage
of this is that to replicate very large databases, the user
can copy the database file into another server (via rsync for
example) and then start a continuous replication with the
"since_seq" parameter set to the value of the copy's update
sequence number, speeding up the replication process.

This parameter, and its purpose, was discussed in COUCHDB-892.


Modified:
    couchdb/trunk/share/www/script/test/replication.js
    couchdb/trunk/src/couchdb/couch_replicator.erl
    couchdb/trunk/src/couchdb/couch_replicator_utils.erl

Modified: couchdb/trunk/share/www/script/test/replication.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/replication.js?rev=1139823&r1=1139822&r2=1139823&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/replication.js (original)
+++ couchdb/trunk/share/www/script/test/replication.js Sun Jun 26 15:57:36 2011
@@ -504,6 +504,47 @@ couchTests.replication = function(debug)
   }
 
 
+  // test since_seq parameter
+  docs = makeDocs(1, 6);
+
+  for (i = 0; i < dbPairs.length; i++) {
+    var since_seq = 3;
+    populateDb(sourceDb, docs);
+    populateDb(targetDb, []);
+
+    var expected_ids = [];
+    var changes = sourceDb.changes({since: since_seq});
+    for (j = 0; j < changes.results.length; j++) {
+      expected_ids.push(changes.results[j].id);
+    }
+    TEquals(2, expected_ids.length, "2 documents since since_seq");
+
+    repResult = CouchDB.replicate(
+      dbPairs[i].source,
+      dbPairs[i].target,
+      {body: {since_seq: since_seq}}
+    );
+    TEquals(true, repResult.ok);
+    TEquals(2, repResult.history[0].missing_checked);
+    TEquals(2, repResult.history[0].missing_found);
+    TEquals(2, repResult.history[0].docs_read);
+    TEquals(2, repResult.history[0].docs_written);
+    TEquals(0, repResult.history[0].doc_write_failures);
+
+    for (j = 0; j < docs.length; j++) {
+      doc = docs[j];
+      copy = targetDb.open(doc._id);
+
+      if (expected_ids.indexOf(doc._id) === -1) {
+        T(copy === null);
+      } else {
+        T(copy !== null);
+        TEquals(true, compareObjects(doc, copy));
+      }
+    }
+  }
+
+
   // test errors due to doc validate_doc_update functions in the target endpoint
   docs = makeDocs(1, 8);
   docs[2]["_attachments"] = {

Modified: couchdb/trunk/src/couchdb/couch_replicator.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_replicator.erl?rev=1139823&r1=1139822&r2=1139823&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_replicator.erl (original)
+++ couchdb/trunk/src/couchdb/couch_replicator.erl Sun Jun 26 15:57:36 2011
@@ -537,7 +537,8 @@ init_state(Rep) ->
 
     [SourceLog, TargetLog] = find_replication_logs([Source, Target], Rep),
 
-    {StartSeq, History} = compare_replication_logs(SourceLog, TargetLog),
+    {StartSeq0, History} = compare_replication_logs(SourceLog, TargetLog),
+    StartSeq = get_value(since_seq, Options, StartSeq0),
     #doc{body={CheckpointHistory}} = SourceLog,
     State = #rep_state{
         rep_details = Rep,

Modified: couchdb/trunk/src/couchdb/couch_replicator_utils.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_replicator_utils.erl?rev=1139823&r1=1139822&r2=1139823&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_replicator_utils.erl (original)
+++ couchdb/trunk/src/couchdb/couch_replicator_utils.erl Sun Jun 26 15:57:36 2011
@@ -258,6 +258,8 @@ convert_options([{<<"connection_timeout"
 convert_options([{<<"socket_options">>, V} | R]) ->
     {ok, SocketOptions} = couch_util:parse_term(V),
     [{socket_options, SocketOptions} | convert_options(R)];
+convert_options([{<<"since_seq">>, V} | R]) ->
+    [{since_seq, V} | convert_options(R)];
 convert_options([_ | R]) -> % skip unknown option
     convert_options(R).
 



Mime
View raw message