From a77e95f64cce417710897d9dee0c62d5169a44a3 Mon Sep 17 00:00:00 2001 From: Russell Branca Date: Fri, 12 Apr 2013 16:48:14 -0400 Subject: [PATCH] Moving shard maps _membership endpoint to _shards db handler --- src/mem3_httpd.erl | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/mem3_httpd.erl b/src/mem3_httpd.erl index dc42924..2331e95 100644 --- a/src/mem3_httpd.erl +++ b/src/mem3_httpd.erl @@ -12,7 +12,7 @@ -module(mem3_httpd). --export([handle_membership_req/1]). +-export([handle_membership_req/1, handle_shards_req/2]). %% includes -include_lib("mem3/include/mem3.hrl"). @@ -26,27 +26,25 @@ handle_membership_req(#httpd{method='GET', couch_httpd:send_json(Req, {[ {all_nodes, lists:sort([node()|nodes()])}, {cluster_nodes, lists:sort(ClusterNodes)} - ]}); -handle_membership_req(#httpd{method='GET', - path_parts=[<<"_membership">>, DbName]} = Req) -> - ClusterNodes = try mem3:nodes() - catch _:_ -> {ok,[]} end, + ]}). + +handle_shards_req(#httpd{method='GET', + path_parts=[_DbName, <<"_shards">>]} = Req, Db) -> + DbName = mem3:dbname(Db#db.name), Shards = mem3:shards(DbName), JsonShards = json_shards(Shards, dict:new()), couch_httpd:send_json(Req, {[ - {all_nodes, lists:sort([node()|nodes()])}, - {cluster_nodes, lists:sort(ClusterNodes)}, - {partitions, JsonShards} + {shards, JsonShards} ]}); -handle_membership_req(#httpd{method='GET', - path_parts=[<<"_membership">>, DbName, DocId]} = Req) -> +handle_shards_req(#httpd{method='GET', + path_parts=[_DbName, <<"_shards">>, DocId]} = Req, Db) -> + DbName = mem3:dbname(Db#db.name), Shards = mem3:shards(DbName, DocId), {[{Shard, Dbs}]} = json_shards(Shards, dict:new()), couch_httpd:send_json(Req, {[ {range, Shard}, {nodes, Dbs} ]}). - %% %% internal %%