couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject [50/50] git commit: Allow mrview reads to continue after compaction.
Date Wed, 26 Oct 2011 18:05:34 GMT
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.



git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1172381 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/e71e8028
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/e71e8028
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/e71e8028

Branch: refs/heads/1319-large-headers-are-corrupted
Commit: e71e802897bb8544cc352179a9247b815d8d61d5
Parents: fb7879e
Author: Paul Joseph Davis <davisp@apache.org>
Authored: Sun Sep 18 21:53:29 2011 +0000
Committer: Paul Joseph Davis <davisp@apache.org>
Committed: Sun Sep 18 21:53:29 2011 +0000

----------------------------------------------------------------------
 src/couch_mrview/include/couch_mrview.hrl       |    1 +
 src/couch_mrview/src/couch_mrview_compactor.erl |    7 +++----
 src/couch_mrview/src/couch_mrview_index.erl     |    8 ++++++--
 src/couch_mrview/src/couch_mrview_util.erl      |    1 +
 4 files changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/e71e8028/src/couch_mrview/include/couch_mrview.hrl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/include/couch_mrview.hrl b/src/couch_mrview/include/couch_mrview.hrl
index e17bb9a..bf3bcac 100644
--- a/src/couch_mrview/include/couch_mrview.hrl
+++ b/src/couch_mrview/include/couch_mrview.hrl
@@ -13,6 +13,7 @@
 -record(mrst, {
     sig=nil,
     fd=nil,
+    refc,
     db_name,
     idx_name,
     language,

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e71e8028/src/couch_mrview/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/src/couch_mrview_compactor.erl b/src/couch_mrview/src/couch_mrview_compactor.erl
index d092adb..989b234 100644
--- a/src/couch_mrview/src/couch_mrview_compactor.erl
+++ b/src/couch_mrview/src/couch_mrview_compactor.erl
@@ -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}}.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e71e8028/src/couch_mrview/src/couch_mrview_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/src/couch_mrview_index.erl b/src/couch_mrview/src/couch_mrview_index.erl
index d2d700d..8fca96a 100644
--- a/src/couch_mrview/src/couch_mrview_index.erl
+++ b/src/couch_mrview/src/couch_mrview_index.erl
@@ -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)),

http://git-wip-us.apache.org/repos/asf/couchdb/blob/e71e8028/src/couch_mrview/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl
index 0c26109..a13b154 100644
--- a/src/couch_mrview/src/couch_mrview_util.erl
+++ b/src/couch_mrview/src/couch_mrview_util.erl
@@ -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