couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r802987 - /couchdb/trunk/src/couchdb/couch_rep_writer.erl
Date Tue, 11 Aug 2009 04:51:03 GMT
Author: kocolosk
Date: Tue Aug 11 04:51:03 2009
New Revision: 802987

URL: http://svn.apache.org/viewvc?rev=802987&view=rev
Log:
whoops, process dictionary certainly won't work there

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

Modified: couchdb/trunk/src/couchdb/couch_rep_writer.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_rep_writer.erl?rev=802987&r1=802986&r2=802987&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_rep_writer.erl (original)
+++ couchdb/trunk/src/couchdb/couch_rep_writer.erl Tue Aug 11 04:51:03 2009
@@ -27,21 +27,23 @@
     Size = size(Data),
     {Size, [ibrowse_lib:dec2hex(8, Size), "\r\n", Data, "\r\n"]}.
 
-upload_docs({start, Docs}) ->
+upload_docs({start, W, Docs}) ->
     {Size, Chunk} = make_chunk(<<"{\"new_edits\":false, \"docs\":[">>),
-    {ok, Chunk, {continue, Docs, "", Size}};
-upload_docs({continue, Docs, _, ByteCount}) when ByteCount > ?MAX_BYTES ->
-    put(docs_remaining, Docs),
+    {ok, Chunk, {continue, W, Docs, "", Size}};
+upload_docs({continue, W, Docs, _, ByteCount}) when ByteCount > ?MAX_BYTES ->
+    W ! {docs_remaining, length(Docs)},
     {ok, "2\r\n]}\r\n", last_chunk};
-upload_docs({continue, [Doc|Rest], Prepend, ByteCount}) ->
+upload_docs({continue, W, [Doc|Rest], Prepend, ByteCount}) ->
     JsonDoc = ?JSON_ENCODE(couch_doc:to_json_obj(Doc, [revs,attachments])),
     {Size, Chunk} = make_chunk([Prepend, JsonDoc]),
-    {ok, Chunk, {continue, Rest, ",", ByteCount+Size}};
-upload_docs({continue, [], _, _}) ->
+    {ok, Chunk, {continue, W, Rest, ",", ByteCount+Size}};
+upload_docs({continue, W, [], _, _}) ->
+    W ! {docs_remaining, 0},
     {ok, "2\r\n]}\r\n", last_chunk};
 upload_docs(last_chunk) ->
     {ok, "0\r\n\r\n", finish};
 upload_docs(finish) ->
+    couch_util:should_flush(),
     eof.
     
 writer_loop(Parent, Reader, Target) ->
@@ -65,6 +67,7 @@
         end,
         Parent ! {writer_checkpoint, HighSeq},
         couch_rep_att:cleanup(),
+        couch_util:should_flush(),
         writer_loop(Parent, Reader, Target)
     end.
 
@@ -72,7 +75,7 @@
     ErrorsJson = couch_rep_httpc:request(Db#http_db{
         resource = "_bulk_docs",
         method = post,
-        body = {fun upload_docs/1, {start, Docs}},
+        body = {fun upload_docs/1, {start, self(), Docs}},
         headers = [{"transfer-encoding", "chunked"} | Db#http_db.headers]
     }),
     ErrorsList =
@@ -85,10 +88,11 @@
             Reason = proplists:get_value(<<"reason">>, Props),
             {{Id, Rev}, {ErrId, Reason}}
         end, ErrorsJson),
-    case erase(docs_remaining) of
-    undefined ->
+    receive
+    {docs_remaining, 0} ->
         {ok, lists:flatten([ErrorsList|ErrorsAcc])};
-    MoreDocs ->
+    {docs_remaining, N} ->
+        MoreDocs = lists:nthtail(length(Docs)-N, Docs),
         write_docs(Db, MoreDocs, [ErrorsList|ErrorsAcc])
     end;
 write_docs(Db, Docs, _) ->



Mime
View raw message