couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bbast...@apache.org
Subject [couchdb] 04/04: Update couch_mrview to use new index LRU
Date Fri, 14 Apr 2017 07:14:52 GMT
This is an automated email from the ASF dual-hosted git repository.

bbastian pushed a commit to branch 8409-view-lru
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit dfee786cc1fab950adbe0497a35fbeea66e0286d
Author: Benjamin Bastian <benjamin.bastian@gmail.com>
AuthorDate: Thu Apr 13 16:44:28 2017 -0700

    Update couch_mrview to use new index LRU
---
 src/couch_mrview/src/couch_mrview.erl      | 32 ++++++++++++++++++++----------
 src/couch_mrview/src/couch_mrview_util.erl |  9 +++++++--
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/src/couch_mrview/src/couch_mrview.erl b/src/couch_mrview/src/couch_mrview.erl
index 088327c..1e49579 100644
--- a/src/couch_mrview/src/couch_mrview.erl
+++ b/src/couch_mrview/src/couch_mrview.erl
@@ -325,16 +325,19 @@ count_view_changes_since(Db, DDoc, VName, SinceSeq, Options) ->
 
 
 get_info(Db, DDoc) ->
-    {ok, Pid} = couch_index_server:get_index(couch_mrview_index, Db, DDoc),
-    couch_index:get_info(Pid).
+    {ok, Pid, Mon} = couch_index_server:get_index(couch_mrview_index, Db, DDoc),
+    Info = couch_index:get_info(Pid),
+    ok = couch_index_server:close(Mon),
+    Info.
 
 
 trigger_update(Db, DDoc) ->
     trigger_update(Db, DDoc, couch_db:get_update_seq(Db)).
 
 trigger_update(Db, DDoc, UpdateSeq) ->
-    {ok, Pid} = couch_index_server:get_index(couch_mrview_index, Db, DDoc),
-    couch_index:trigger_update(Pid, UpdateSeq).
+    {ok, Pid, Mon} = couch_index_server:get_index(couch_mrview_index, Db, DDoc),
+    couch_index:trigger_update(Pid, UpdateSeq),
+    couch_index_server:close(Mon).
 
 %% get informations on a view
 get_view_info(Db, DDoc, VName) ->
@@ -369,10 +372,14 @@ refresh(Db, DDoc) ->
             end),
 
     case couch_index_server:get_index(couch_mrview_index, Db, DDoc) of
-        {ok, Pid} ->
-            case catch couch_index:get_state(Pid, UpdateSeq) of
-                {ok, _} -> ok;
-                Error -> {error, Error}
+        {ok, Pid, Mon} ->
+            try
+                case catch couch_index:get_state(Pid, UpdateSeq) of
+                    {ok, _} -> ok;
+                    Error -> {error, Error}
+                end
+            after
+                couch_index_server:close(Mon)
             end;
         Error ->
             {error, Error}
@@ -383,17 +390,20 @@ compact(Db, DDoc) ->
 
 
 compact(Db, DDoc, Opts) ->
-    {ok, Pid} = couch_index_server:get_index(couch_mrview_index, Db, DDoc),
-    couch_index:compact(Pid, Opts).
+    {ok, Pid, Mon} = couch_index_server:get_index(couch_mrview_index, Db, DDoc),
+    Ret = couch_index:compact(Pid, Opts),
+    couch_index_server:close(Mon),
+    Ret.
 
 
 cancel_compaction(Db, DDoc) ->
-    {ok, IPid} = couch_index_server:get_index(couch_mrview_index, Db, DDoc),
+    {ok, IPid, Mon} = couch_index_server:get_index(couch_mrview_index, Db, DDoc),
     {ok, CPid} = couch_index:get_compactor_pid(IPid),
     ok = couch_index_compactor:cancel(CPid),
 
     % Cleanup the compaction file if it exists
     {ok, #mrst{sig=Sig, db_name=DbName}} = couch_index:get_state(IPid, 0),
+    couch_index_server:close(Mon),
     couch_mrview_util:delete_compaction_file(DbName, Sig),
     ok.
 
diff --git a/src/couch_mrview/src/couch_mrview_util.erl b/src/couch_mrview/src/couch_mrview_util.erl
index 3830b96..be29cb3 100644
--- a/src/couch_mrview/src/couch_mrview_util.erl
+++ b/src/couch_mrview/src/couch_mrview_util.erl
@@ -40,7 +40,7 @@
 
 
 get_view(Db, DDoc, ViewName, Args0) ->
-    {ok, Pid, Args2} = get_view_index_pid(Db, DDoc, ViewName, Args0),
+    {ok, Pid, Mon, Args2} = get_view_index_pid(Db, DDoc, ViewName, Args0),
     DbUpdateSeq = couch_util:with_db(Db, fun(WDb) ->
         couch_db:get_update_seq(WDb)
     end),
@@ -51,9 +51,14 @@ get_view(Db, DDoc, ViewName, Args0) ->
         {ok, _} = Resp -> Resp;
         Error -> throw(Error)
     end,
+    ok = couch_index_server:close(Mon),
     Ref = erlang:monitor(process, State#mrst.fd),
     if Args2#mrargs.update == lazy ->
-        spawn(fun() -> catch couch_index:get_state(Pid, DbUpdateSeq) end);
+        spawn(fun() ->
+            {ok, Pid2, Mon2} = couch_index_server:get_index(?MOD, Db, DDoc),
+            catch couch_index:get_state(Pid2, DbUpdateSeq),
+            ok = couch_index_server:close(Mon2)
+        end);
         true -> ok
     end,
     #mrst{language=Lang, views=Views} = State,

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <commits@couchdb.apache.org>.

Mime
View raw message