couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [1/2] couch-mrview commit: updated refs/heads/master to d450960
Date Thu, 06 Oct 2016 19:35:05 GMT
Repository: couchdb-couch-mrview
Updated Branches:
  refs/heads/master d27941193 -> d4509606f


Replace `stale` with `stable` and `update`

The `stale` mechanism for view queries conflates two independent
concerns:

1. Whether or not the view results should be returned from a "stable"
   set of shards; i.e., mem3:ushards. This semantic is new in 2.0,
   having originated in Cloudant code in 2011[1].

2. Whether or not the view in question should be updated prior to
   responding to the user, i.e., the pre-2.0 semantics.

Both of these concerns represent consistency/availability tradeoffs, but
they're addressing rather different aspects of that continuum. As such,
the "stale" mechanism limits flexibility.

For example, it's quite likely that a user would want to retrieve
"stale" view responses from the fastest available shards - the
"available/available" choice - and this choice is not available with the
existing "stale" mechanism. A similar argument could be made for the
"consistent/consistent" choice.

This patch introduces two new view API keywords - "stable" and "update"
- to address concerns #1 and #2, respectively. The semantics of the
"stale" mechanism is implemented in terms of these new keywords.

COUCHDB-3063

[1]: apache/couchdb-fabric@93923fda51c714c015b8621e41f3c425bfb3e61a


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/459a548f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/459a548f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/459a548f

Branch: refs/heads/master
Commit: 459a548f269b00bf2d2ace0170c583e72fde4cb9
Parents: 3ce2864
Author: Benjamin Anderson <b@banjiewen.net>
Authored: Sun Jul 17 14:25:22 2016 -0700
Committer: Benjamin Anderson <b@banjiewen.net>
Committed: Sun Jul 17 14:42:55 2016 -0700

----------------------------------------------------------------------
 include/couch_mrview.hrl  |  3 ++-
 src/couch_mrview_http.erl | 18 ++++++++++++++++--
 src/couch_mrview_util.erl | 20 +++++++++++++-------
 3 files changed, 31 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/459a548f/include/couch_mrview.hrl
----------------------------------------------------------------------
diff --git a/include/couch_mrview.hrl b/include/couch_mrview.hrl
index 2dfd398..e74d6ec 100644
--- a/include/couch_mrview.hrl
+++ b/include/couch_mrview.hrl
@@ -77,7 +77,8 @@
     skip = 0,
     group_level = 0,
     group = undefined,
-    stale = false,
+    stable = false,
+    update = true,
     multi_get = false,
     inclusive_end = true,
     include_docs = false,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/459a548f/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 3a9aa33..5f52d08 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -504,11 +504,25 @@ parse_param(Key, Val, Args, IsDecoded) ->
         "limit" ->
             Args#mrargs{limit=parse_pos_int(Val)};
         "stale" when Val == "ok" orelse Val == <<"ok">> ->
-            Args#mrargs{stale=ok};
+            Args#mrargs{stable=true, update=false};
         "stale" when Val == "update_after" orelse Val == <<"update_after">> ->
-            Args#mrargs{stale=update_after};
+            Args#mrargs{stable=true, update=lazy};
         "stale" ->
             throw({query_parse_error, <<"Invalid value for `stale`.">>});
+        "stable" when Val == "true" orelse Val == <<"true">> ->
+            Args#mrargs{stable=true};
+        "stable" when Val == "false" orelse Val == <<"false">> ->
+            Args#mrargs{stable=false};
+        "stable" ->
+            throw({query_parse_error, <<"Invalid value for `stable`.">>});
+        "update" when Val == "true" orelse Val == <<"true">> ->
+            Args#mrargs{update=true};
+        "update" when Val == "false" orelse Val == <<"false">> ->
+            Args#mrargs{update=false};
+        "update" when Val == "lazy" orelse Val == <<"lazy">> ->
+            Args#mrargs{update=lazy};
+        "update" ->
+            throw({query_parse_error, <<"Invalid value for `update`.">>});
         "descending" ->
             case parse_boolean(Val) of
                 true -> Args#mrargs{direction=rev};

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/459a548f/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index 934dcd3..11bd0df 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -48,15 +48,15 @@ get_view(Db, DDoc, ViewName, Args0) ->
     DbUpdateSeq = couch_util:with_db(Db, fun(WDb) ->
         couch_db:get_update_seq(WDb)
     end),
-    MinSeq = case Args2#mrargs.stale of
-        ok -> 0; update_after -> 0; _ -> DbUpdateSeq
+    MinSeq = case Args2#mrargs.update of
+        false -> 0; lazy -> 0; _ -> DbUpdateSeq
     end,
     {ok, State} = case couch_index:get_state(Pid, MinSeq) of
         {ok, _} = Resp -> Resp;
         Error -> throw(Error)
     end,
     Ref = erlang:monitor(process, State#mrst.fd),
-    if Args2#mrargs.stale == update_after ->
+    if Args2#mrargs.update == lazy ->
         spawn(fun() -> catch couch_index:get_state(Pid, DbUpdateSeq) end);
         true -> ok
     end,
@@ -472,11 +472,17 @@ validate_args(Args) ->
         {map, _} -> mrverror(<<"Invalid use of grouping on a map view.">>)
     end,
 
-    case Args#mrargs.stale of
-        ok -> ok;
-        update_after -> ok;
+    case Args#mrargs.stable of
+        true -> ok;
+        false -> ok;
+        _ -> mrverror(<<"Invalid value for `stable`.">>)
+    end,
+
+    case Args#mrargs.update of
+        true -> ok;
         false -> ok;
-        _ -> mrverror(<<"Invalid value for `stale`.">>)
+        lazy -> ok;
+        _ -> mrverror(<<"Invalid value for `update`.">>)
     end,
 
     case is_boolean(Args#mrargs.inclusive_end) of


Mime
View raw message