couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r807208 - in /couchdb/trunk/src/couchdb: couch_rep.erl couch_rep_writer.erl
Date Mon, 24 Aug 2009 13:31:48 GMT
Author: kocolosk
Date: Mon Aug 24 13:31:48 2009
New Revision: 807208

URL: http://svn.apache.org/viewvc?rev=807208&view=rev
Log:
skip full_commit during replication when its safe

Modified:
    couchdb/trunk/src/couchdb/couch_rep.erl
    couchdb/trunk/src/couchdb/couch_rep_writer.erl

Modified: couchdb/trunk/src/couchdb/couch_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep.erl?rev=807208&r1=807207&r2=807208&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep.erl Mon Aug 24 13:31:48 2009
@@ -462,9 +462,9 @@
 
     try
     {SrcRevPos,SrcRevId} =
-        update_doc(Source, SourceLog#doc{body=NewRepHistory}, []),
+        update_local_doc(Source, SourceLog#doc{body=NewRepHistory}),
     {TgtRevPos,TgtRevId} =
-        update_doc(Target, TargetLog#doc{body=NewRepHistory}, []),
+        update_local_doc(Target, TargetLog#doc{body=NewRepHistory}),
     State#state{
         checkpoint_history = NewRepHistory,
         source_log = SourceLog#doc{revs={SrcRevPos, [SrcRevId]}},
@@ -504,20 +504,33 @@
     true = proplists:get_value(<<"ok">>, ResultProps),
     proplists:get_value(<<"instance_start_time">>, ResultProps);
 ensure_full_commit(Db) ->
-    {ok, StartTime} = couch_db:ensure_full_commit(Db),
-    StartTime.
+    {ok, NewDb} = couch_db:open(Db#db.name, []),
+    UpdateSeq = couch_db:get_update_seq(Db),
+    CommitSeq = couch_db:get_committed_update_seq(NewDb),
+    InstanceStartTime = NewDb#db.instance_start_time,
+    couch_db:close(NewDb),
+    if UpdateSeq > CommitSeq ->
+        ?LOG_DEBUG("replication needs a full commit: update ~p commit ~p",
+            [UpdateSeq, CommitSeq]),
+        {ok, NewTime} = couch_db:ensure_full_commit(Db),
+        NewTime;
+    true ->
+        ?LOG_DEBUG("replication doesn't need a full commit", []),
+        InstanceStartTime
+    end.
 
-update_doc(#http_db{} = Db, #doc{id=DocId} = Doc, []) ->
+update_local_doc(#http_db{} = Db, #doc{id=DocId} = Doc) ->
     Req = Db#http_db{
         resource = couch_util:url_encode(DocId),
         method = put,
-        body = couch_doc:to_json_obj(Doc, [attachments])
+        body = couch_doc:to_json_obj(Doc, [attachments]),
+        headers = [{"x-couch-full-commit", "false"} | Db#http_db.headers]
     },
     {ResponseMembers} = couch_rep_httpc:request(Req),
     Rev = proplists:get_value(<<"rev">>, ResponseMembers),
     couch_doc:parse_rev(Rev);
-update_doc(Db, Doc, Options) ->
-    {ok, Result} = couch_db:update_doc(Db, Doc, Options),
+update_local_doc(Db, Doc) ->
+    {ok, Result} = couch_db:update_doc(Db, Doc, [delay_commit]),
     Result.
 
 up_to_date(#http_db{}, _Seq) ->

Modified: couchdb/trunk/src/couchdb/couch_rep_writer.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep_writer.erl?rev=807208&r1=807207&r2=807208&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep_writer.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep_writer.erl Mon Aug 24 13:31:48 2009
@@ -48,7 +48,8 @@
     ErrorsJson = couch_rep_httpc:request(Db#http_db{
         resource = "_bulk_docs",
         method = post,
-        body = {[{new_edits, false}, {docs, JsonDocs}]}
+        body = {[{new_edits, false}, {docs, JsonDocs}]},
+        headers = [{"x-couch-full-commit", "false"} | Db#http_db.headers]
     }),
     ErrorsList =
     lists:map(
@@ -62,4 +63,4 @@
         end, ErrorsJson),
     {ok, ErrorsList};
 write_docs(Db, Docs) ->
-    couch_db:update_docs(Db, Docs, [], replicated_changes).
+    couch_db:update_docs(Db, Docs, [delay_commit], replicated_changes).



Mime
View raw message