couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [03/14] couch-httpd commit: updated refs/heads/1994-merge-rcouch to d936233
Date Thu, 13 Feb 2014 03:09:59 GMT
couch_index: add background indexing facility

This change add the possibility to trigger a view indexation in
background. The indexation can only work in background if at least one
process acquired it using the `couch_index_server:acquire_index/3`
function. If all the process that acquired it are down or released it
using `couch_index_server:release_indexer/3` then the background task is
stopped.

By default the background indexation will happen every 1s or when 200
docs has been saved in the database. These parameters can be changed
using the options `threshold` and `refresh_interval` in the couch_index
section.

To use it with couch_mrview a new option {refresh, true} has been added
to couch_mrview_changes:handle_changes Also the query parameter
refresh=true is passsed in t the HTTP changes API.


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

Branch: refs/heads/1994-merge-rcouch
Commit: c1d2f8f0fe1af2159a8872629c965fcef4d7234e
Parents: f870b4b
Author: benoitc <benoitc@apache.org>
Authored: Sat Feb 8 19:55:40 2014 +0100
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Wed Feb 12 21:05:52 2014 -0600

----------------------------------------------------------------------
 src/couch_httpd_changes.erl | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-httpd/blob/c1d2f8f0/src/couch_httpd_changes.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_changes.erl b/src/couch_httpd_changes.erl
index 82d9fe0..510e20a 100644
--- a/src/couch_httpd_changes.erl
+++ b/src/couch_httpd_changes.erl
@@ -177,8 +177,11 @@ handle_view_changes(#db{name=DbName}=Db0, DDocId, VName, ViewOptions,
         since = Since,
         db_open_options = DbOptions} = ChangesArgs,
 
+    Refresh = refresh_option(Req),
+
     Options0 = [{since, Since},
-                {view_options, ViewOptions}],
+                {view_options, ViewOptions},
+                {refresh, Refresh}],
     Options = case ResponseType of
         "continuous" -> [stream | Options0];
         "eventsource" -> [stream | Options0];
@@ -236,9 +239,9 @@ view_changes_cb({{Seq, _Key, DocId}, _VAl},
             %% if we achieved the limit, stop here, else continue.
             NewLimit = OldLimit + 1,
             if Limit > NewLimit ->
-                    {ok, {<<",\n">>, Db, NewLimit, Callback, Args}};
+                    {ok, {<<",\n">>, NewLimit, Db, Callback, Args}};
                 true ->
-                    {stop, {<<"">>, Db, NewLimit, Callback, Args}}
+                    {stop, {<<"">>, NewLimit, Db, Callback, Args}}
             end;
         {error, not_found} ->
             %% doc not found, continue
@@ -416,6 +419,15 @@ parse_view_options([{K, V} | Rest], Acc) ->
     end,
     parse_view_options(Rest, Acc1).
 
+refresh_option({json_req, {Props}}) ->
+    {Query} = couch_util:get_value(<<"query">>, Props),
+    couch_util:get_value(<<"refresh">>, Query, true);
+refresh_option(Req) ->
+    case couch_httpd:qs_value(Req, "refresh", "true") of
+        "false" -> false;
+        _ -> true
+    end.
+
 parse_json(V) when is_list(V) ->
     ?JSON_DECODE(V);
 parse_json(V) ->


Mime
View raw message