diff options
author | Adam Kocoloski <kocolosk@apache.org> | 2009-08-24 13:31:48 +0000 |
---|---|---|
committer | Adam Kocoloski <kocolosk@apache.org> | 2009-08-24 13:31:48 +0000 |
commit | e1b6dd15d993a3f424747ef5fc89ffa95a961613 (patch) | |
tree | afd250106695bdbc6c357bce76136e33d316296b | |
parent | ab71069d36708d68206b79d97affce03173366b7 (diff) |
skip full_commit during replication when its safe
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@807208 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/couchdb/couch_rep.erl | 29 | ||||
-rw-r--r-- | src/couchdb/couch_rep_writer.erl | 5 |
2 files changed, 24 insertions, 10 deletions
diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl index 592693ee..95a23869 100644 --- a/src/couchdb/couch_rep.erl +++ b/src/couchdb/couch_rep.erl @@ -462,9 +462,9 @@ do_checkpoint(State) -> 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 @@ ensure_full_commit(#http_db{} = Db) -> 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) -> diff --git a/src/couchdb/couch_rep_writer.erl b/src/couchdb/couch_rep_writer.erl index adc7a9e5..e9538640 100644 --- a/src/couchdb/couch_rep_writer.erl +++ b/src/couchdb/couch_rep_writer.erl @@ -48,7 +48,8 @@ write_docs(#http_db{} = Db, Docs) -> 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 @@ write_docs(#http_db{} = Db, Docs) -> 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). |