Author: kocolosk
Date: Fri Sep 23 19:53:08 2011
New Revision: 1174981

URL: http://svn.apache.org/viewvc?rev=1174981&view=rev
Log:
Write header before handing over compacted group

Writing the header first ensures that the index will not be reset if
the server crashes in between the handoff and the next delayed_commit.

See COUCHDB-994

Modified:
    couchdb/branches/1.0.x/src/couchdb/couch_view_compactor.erl
    couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl

Modified: couchdb/branches/1.0.x/src/couchdb/couch_view_compactor.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_view_compactor.erl?rev=1174981&r1=1174980&r2=1174981&view=diff
==============================================================================
--- couchdb/branches/1.0.x/src/couchdb/couch_view_compactor.erl (original)
+++ couchdb/branches/1.0.x/src/couchdb/couch_view_compactor.erl Fri Sep 23 
19:53:08 2011
@@ -37,6 +37,8 @@ compact_group(Group, EmptyGroup) ->
 
     #group{
         db = Db,
+        sig = Sig,
+        fd = NewFd,
         id_btree = EmptyIdBtree,
         views = EmptyViews
     } = EmptyGroup,
@@ -76,6 +78,8 @@ compact_group(Group, EmptyGroup) ->
         current_seq=Seq
     },
 
+    Header = {Sig, couch_view_group:get_index_header_data(NewGroup)},
+    ok = couch_file:write_header(NewFd, Header),
     Pid = couch_view:get_group_server(DbName, GroupId),
     gen_server:cast(Pid, {compact_done, NewGroup}).
 

Modified: couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl
URL: 
http://svn.apache.org/viewvc/couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl?rev=1174981&r1=1174980&r2=1174981&view=diff
==============================================================================
--- couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl (original)
+++ couchdb/branches/1.0.x/src/couchdb/couch_view_group.erl Fri Sep 23 19:53:08 
2011
@@ -17,6 +17,9 @@
 -export([start_link/1, request_group/2, request_group_info/1]).
 -export([open_db_group/2, open_temp_group/5, 
design_doc_to_view_group/1,design_root/2]).
 
+%% Exports for the compactor
+-export([get_index_header_data/1]).
+
 %% gen_server callbacks
 -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
          terminate/2, code_change/3]).


Reply via email to