You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/01/17 23:09:56 UTC
[11/49] git commit: Allow mrview reads to continue after compaction.
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-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/a26ed9a3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/a26ed9a3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/a26ed9a3
Branch: refs/heads/import
Commit: a26ed9a35e2879ff3b46aaf16d4858f893e792dc
Parents: 2b91066
Author: Paul Joseph Davis <da...@apache.org>
Authored: Sun Sep 18 21:53:29 2011 +0000
Committer: Paul Joseph Davis <da...@apache.org>
Committed: Sun Sep 18 21:53:29 2011 +0000
----------------------------------------------------------------------
include/couch_mrview.hrl | 1 +
src/couch_mrview_compactor.erl | 7 +++----
src/couch_mrview_index.erl | 8 ++++++--
src/couch_mrview_util.erl | 1 +
4 files changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/a26ed9a3/include/couch_mrview.hrl
----------------------------------------------------------------------
diff --git a/include/couch_mrview.hrl b/include/couch_mrview.hrl
index e17bb9a..bf3bcac 100644
--- a/include/couch_mrview.hrl
+++ b/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-couch-mrview/blob/a26ed9a3/src/couch_mrview_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_compactor.erl b/src/couch_mrview_compactor.erl
index d092adb..989b234 100644
--- a/src/couch_mrview_compactor.erl
+++ b/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-couch-mrview/blob/a26ed9a3/src/couch_mrview_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_index.erl b/src/couch_mrview_index.erl
index d2d700d..8fca96a 100644
--- a/src/couch_mrview_index.erl
+++ b/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-couch-mrview/blob/a26ed9a3/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index 0c26109..a13b154 100644
--- a/src/couch_mrview_util.erl
+++ b/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