couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1172381 - in /couchdb/trunk/src/couch_mrview: include/couch_mrview.hrl src/couch_mrview_compactor.erl src/couch_mrview_index.erl src/couch_mrview_util.erl
Date Sun, 18 Sep 2011 21:53:29 GMT
Author: davisp
Date: Sun Sep 18 21:53:29 2011
New Revision: 1172381

URL: http://svn.apache.org/viewvc?rev=1172381&view=rev
Log:
Allow mrview reads to continue after compaction.

This adds a ref counter to handle the shutdown of the mrview file
instead of closing it forcibly in swap_compacted. This fixes a
behavior regression introduced with the new indexer implementation.


Modified:
    couchdb/trunk/src/couch_mrview/include/couch_mrview.hrl
    couchdb/trunk/src/couch_mrview/src/couch_mrview_compactor.erl
    couchdb/trunk/src/couch_mrview/src/couch_mrview_index.erl
    couchdb/trunk/src/couch_mrview/src/couch_mrview_util.erl

Modified: couchdb/trunk/src/couch_mrview/include/couch_mrview.hrl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couch_mrview/include/couch_mrview.hrl?rev=1172381&r1=1172380&r2=1172381&view=diff
==============================================================================
--- couchdb/trunk/src/couch_mrview/include/couch_mrview.hrl (original)
+++ couchdb/trunk/src/couch_mrview/include/couch_mrview.hrl Sun Sep 18 21:53:29 2011
@@ -13,6 +13,7 @@
 -record(mrst, {
     sig=nil,
     fd=nil,
+    refc,
     db_name,
     idx_name,
     language,

Modified: couchdb/trunk/src/couch_mrview/src/couch_mrview_compactor.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couch_mrview/src/couch_mrview_compactor.erl?rev=1172381&r1=1172380&r2=1172381&view=diff
==============================================================================
--- couchdb/trunk/src/couch_mrview/src/couch_mrview_compactor.erl (original)
+++ couchdb/trunk/src/couch_mrview/src/couch_mrview_compactor.erl Sun Sep 18 21:53:29 2011
@@ -164,12 +164,11 @@ swap_compacted(OldState, NewState) ->
     RootDir = couch_index_util:root_dir(),
     IndexFName = couch_mrview_util:index_file(DbName, Sig),
     CompactFName = couch_mrview_util:compaction_file(DbName, Sig),
-    couch_file:close(OldState#mrst.fd),
     ok = couch_file:delete(RootDir, IndexFName),
     ok = file:rename(CompactFName, IndexFName),
 
     unlink(OldState#mrst.fd),
+    couch_ref_counter:drop(OldState#mrst.refc),
+    {ok, NewRefCounter} = couch_ref_counter:start([NewState#mrst.fd]),
     
-    {ok, NewState}.
-
-
+    {ok, NewState#mrst{refc=NewRefCounter}}.

Modified: couchdb/trunk/src/couch_mrview/src/couch_mrview_index.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couch_mrview/src/couch_mrview_index.erl?rev=1172381&r1=1172380&r2=1172381&view=diff
==============================================================================
--- couchdb/trunk/src/couch_mrview/src/couch_mrview_index.erl (original)
+++ couchdb/trunk/src/couch_mrview/src/couch_mrview_index.erl Sun Sep 18 21:53:29 2011
@@ -80,9 +80,13 @@ open(Db, State) ->
             case (catch couch_file:read_header(Fd)) of
                 {ok, {Sig, Header}} ->
                     % Matching view signatures.
-                    {ok, couch_mrview_util:init_state(Db, Fd, State, Header)};
+                    NewSt = couch_mrview_util:init_state(Db, Fd, State, Header),
+                    {ok, RefCounter} = couch_ref_counter:start([Fd]),
+                    {ok, NewSt#mrst{refc=RefCounter}};
                 _ ->
-                    {ok, couch_mrview_util:reset_index(Db, Fd, State)}
+                    NewSt = couch_mrview_util:reset_index(Db, Fd, State),
+                    {ok, RefCounter} = couch_ref_counter:start([Fd]),
+                    {ok, NewSt#mrst{refc=RefCounter}}
             end;
         Error ->
             (catch couch_mrview_util:delete_files(DbName, Sig)),

Modified: couchdb/trunk/src/couch_mrview/src/couch_mrview_util.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couch_mrview/src/couch_mrview_util.erl?rev=1172381&r1=1172380&r2=1172381&view=diff
==============================================================================
--- couchdb/trunk/src/couch_mrview/src/couch_mrview_util.erl (original)
+++ couchdb/trunk/src/couch_mrview/src/couch_mrview_util.erl Sun Sep 18 21:53:29 2011
@@ -47,6 +47,7 @@ get_view(Db, DDoc, ViewName, Args0) ->
         {ok, _} = Resp -> Resp;
         Error -> throw(Error)
     end,
+    couch_ref_counter:add(State#mrst.refc),
     if Args2#mrargs.stale == update_after ->
         spawn(fun() -> catch couch_index:get_state(Pid, DbUpdateSeq) end);
         true -> ok



Mime
View raw message