couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1126457 - /couchdb/trunk/src/couchdb/couch_replicator_doc_copier.erl
Date Mon, 23 May 2011 11:56:01 GMT
Author: fdmanana
Date: Mon May 23 11:56:01 2011
New Revision: 1126457

URL: http://svn.apache.org/viewvc?rev=1126457&view=rev
Log:
Replicator: re-enable batching of documents with small attachments

This was removed in revision 1085178, for local -> remote replications,
for dealing gracefully with missing_stub errors. Batching is now enabled
again if none of the attachments is a stub.

Modified:
    couchdb/trunk/src/couchdb/couch_replicator_doc_copier.erl

Modified: couchdb/trunk/src/couchdb/couch_replicator_doc_copier.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_replicator_doc_copier.erl?rev=1126457&r1=1126456&r2=1126457&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_replicator_doc_copier.erl (original)
+++ couchdb/trunk/src/couchdb/couch_replicator_doc_copier.erl Mon May 23 11:56:01 2011
@@ -347,18 +347,21 @@ fetch_doc(Source, {Id, Revs, PAs, _Seq},
     end.
 
 
-local_doc_handler({ok, #doc{atts = []} = Doc}, {Target, DocList, W, F}) ->
-    {Target, [Doc | DocList], W, F};
 local_doc_handler({ok, Doc}, {Target, DocList, W, F}) ->
-    ?LOG_DEBUG("Worker flushing doc with attachments", []),
-    Target2 = open_db(Target),
-    Success = (flush_doc(Target2, Doc) =:= ok),
-    close_db(Target2),
-    case Success of
+    case batch_doc(Doc) of
     true ->
-        {Target, DocList, W + 1, F};
+        {Target, [Doc | DocList], W, F};
     false ->
-        {Target, DocList, W, F + 1}
+        ?LOG_DEBUG("Worker flushing doc with attachments", []),
+        Target2 = open_db(Target),
+        Success = (flush_doc(Target2, Doc) =:= ok),
+        close_db(Target2),
+        case Success of
+        true ->
+            {Target, DocList, W + 1, F};
+        false ->
+            {Target, DocList, W, F + 1}
+        end
     end;
 local_doc_handler(_, Acc) ->
     Acc.
@@ -431,11 +434,9 @@ maybe_flush_docs(Doc, #state{target = Ta
 
 
 maybe_flush_docs(#httpdb{} = Target,
-    #batch{docs = DocAcc, size = SizeAcc} = Batch, #doc{atts = Atts} = Doc) ->
-    case (length(Atts) > ?MAX_BULK_ATTS_PER_DOC) orelse
-        lists:any(
-            fun(A) -> A#att.disk_len > ?MAX_BULK_ATT_SIZE end, Atts) of
-    true ->
+    #batch{docs = DocAcc, size = SizeAcc} = Batch, Doc) ->
+    case batch_doc(Doc) of
+    false ->
         ?LOG_DEBUG("Worker flushing doc with attachments", []),
         case flush_doc(Target, Doc) of
         ok ->
@@ -443,7 +444,7 @@ maybe_flush_docs(#httpdb{} = Target,
         _ ->
             {Batch, 0, 1}
         end;
-    false ->
+    true ->
         JsonDoc = ?JSON_ENCODE(couch_doc:to_json_obj(Doc, [revs, attachments])),
         case SizeAcc + iolist_size(JsonDoc) of
         SizeAcc2 when SizeAcc2 > ?DOC_BUFFER_BYTE_SIZE ->
@@ -455,8 +456,7 @@ maybe_flush_docs(#httpdb{} = Target,
         end
     end;
 
-maybe_flush_docs(#db{} = Target, #batch{docs = DocAcc, size = SizeAcc},
-    #doc{atts = []} = Doc) ->
+maybe_flush_docs(#db{} = Target, #batch{docs = DocAcc, size = SizeAcc}, Doc) ->
     case SizeAcc + 1 of
     SizeAcc2 when SizeAcc2 >= ?DOC_BUFFER_LEN ->
         ?LOG_DEBUG("Worker flushing doc batch of ~p docs", [SizeAcc2]),
@@ -467,6 +467,16 @@ maybe_flush_docs(#db{} = Target, #batch{
     end.
 
 
+batch_doc(#doc{atts = []}) ->
+    true;
+batch_doc(#doc{atts = Atts}) ->
+    (length(Atts) =< ?MAX_BULK_ATTS_PER_DOC) andalso
+        lists:all(
+            fun(#att{disk_len = L, data = Data}) ->
+                (L =< ?MAX_BULK_ATT_SIZE) andalso (Data =/= stub)
+            end, Atts).
+
+
 flush_docs(_Target, []) ->
     {0, 0};
 



Mime
View raw message