couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [08/50] [abbrv] couchdb-mango git commit: Allow the specification of w=3
Date Tue, 03 Feb 2015 15:13:15 GMT
Allow the specification of w=3

We removed the hardcoded w=3 but still want to use it for tests. This
enables us to specify w=3 for creating and deleting indexes and updates
the tests to use it.


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

Branch: refs/heads/master
Commit: c33efa3205b4405a3ac24bb4a3e8cc903d5ad399
Parents: 116227c
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Tue Jun 24 15:51:36 2014 -0500
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Tue Jun 24 15:51:36 2014 -0500

----------------------------------------------------------------------
 src/mango_httpd.erl | 25 +++++++++++++++++++++++--
 src/mango_opts.erl  |  2 +-
 test/mango.py       |  5 +++--
 3 files changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/c33efa32/src/mango_httpd.erl
----------------------------------------------------------------------
diff --git a/src/mango_httpd.erl b/src/mango_httpd.erl
index 68bced0..fa6817f 100644
--- a/src/mango_httpd.erl
+++ b/src/mango_httpd.erl
@@ -49,7 +49,8 @@ handle_index_req(#httpd{method='POST', path_parts=[_, _]}=Req, Db) ->
         {ok, DDoc} ->
             <<"exists">>;
         {ok, NewDDoc} ->
-            case mango_crud:insert(Db, NewDDoc, Opts) of
+            CreateOpts = get_idx_create_opts(Opts),
+            case mango_crud:insert(Db, NewDDoc, CreateOpts) of
                 {ok, [{RespProps}]} ->
                     case lists:keyfind(error, 1, RespProps) of
                         {error, Reason} ->
@@ -91,7 +92,8 @@ handle_index_req(#httpd{method='DELETE',
                 _ ->
                     NewDDoc
             end,
-            case mango_crud:insert(Db, FinalDDoc, []) of
+            DelOpts = get_idx_del_opts(Req),
+            case mango_crud:insert(Db, FinalDDoc, DelOpts) of
                 {ok, _} ->
                     chttpd:send_json(Req, {[{ok, true}]});
                 _ ->
@@ -120,6 +122,25 @@ set_user_ctx(#httpd{user_ctx=Ctx}, Db) ->
     Db#db{user_ctx=Ctx}.
 
 
+get_idx_create_opts(Opts) ->
+    case lists:keyfind(w, 1, Opts) of
+        {w, N} when is_integer(N), N > 0 ->
+            [{w, integer_to_list(N)}];
+        _ ->
+            [{w, "2"}]
+    end.
+
+
+get_idx_del_opts(Req) ->
+    try
+        WStr = chttpd:qs_value(Req, "w", "2"),
+        _ = list_to_integer(WStr),
+        [{w, WStr}]
+    catch _:_ ->
+        [{w, "2"}]
+    end.
+
+
 start_find_resp(Req) ->
     chttpd:start_delayed_json_response(Req, 200, [], "{\"docs\":[").
 

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/c33efa32/src/mango_opts.erl
----------------------------------------------------------------------
diff --git a/src/mango_opts.erl b/src/mango_opts.erl
index 9affbd0..cb42011 100644
--- a/src/mango_opts.erl
+++ b/src/mango_opts.erl
@@ -51,7 +51,7 @@ validate_idx_create({Props}) ->
             {tag, w},
             {optional, true},
             {default, 2},
-            {validator, fun is_non_neg_integer/1}
+            {validator, fun is_pos_integer/1}
         ]}
     ],
     validate(Props, Opts).

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/c33efa32/test/mango.py
----------------------------------------------------------------------
diff --git a/test/mango.py b/test/mango.py
index 92c2a2c..fc201d6 100644
--- a/test/mango.py
+++ b/test/mango.py
@@ -65,7 +65,8 @@ class Database(object):
             "index": {
                 "fields": fields
             },
-            "type": idx_type
+            "type": idx_type,
+            "w": 3
         }
         if name is not None:
             body["name"] = name
@@ -83,7 +84,7 @@ class Database(object):
 
     def delete_index(self, ddocid, name, idx_type="json"):
         path = ["_index", ddocid, idx_type, name]
-        r = self.sess.delete(self.path(path))
+        r = self.sess.delete(self.path(path), params={"w":"3"})
         r.raise_for_status()
 
     def find(self, selector, limit=25, skip=0, sort=None, fields=None,


Mime
View raw message