Skip to content

Commit

Permalink
Make vbucket listing reusable in mc_tap.
Browse files Browse the repository at this point in the history
Change-Id: I4d86de520169e96b06b403fbebbbe8ea8510f5cc
  • Loading branch information
dustin committed Jun 14, 2011
1 parent db848a9 commit 1e78a3c
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/mc_couch_vbucket.erl
Expand Up @@ -4,7 +4,8 @@
set_vbucket/3,
handle_delete/2,
handle_stats/3,
handle_set_state/3]).
handle_set_state/3,
list_vbuckets/1]).

-include("couch_db.hrl").
-include("mc_constants.hrl").
Expand Down Expand Up @@ -40,24 +41,29 @@ handle_delete(VBucket, State) ->
couch_server:delete(DbName, []),
#mc_response{}.

handle_stats(Socket, Opaque, State) ->
list_vbuckets(State) ->
{ok, DBs} = couch_server:all_databases(),
DBPrefix = mc_daemon:db_prefix(State),
Len = size(DBPrefix),
lists:foreach(fun(DBName) ->
case (catch binary:split(DBName, <<$/>>,
[{scope, {Len,size(DBName)-Len}}])) of
[DBPrefix, VB] ->
VBStr = binary_to_list(VB),
VBInt = list_to_integer(VBStr),
StatKey = io_lib:format("vb_~p", [VBInt]),
StatVal = get_state(VBInt, State),
mc_connection:respond(Socket, ?STAT, Opaque,
mc_couch_stats:mk_stat(StatKey,
StatVal));
_ -> ok
end
end, DBs),
lists:filter(fun is_tuple/1,
lists:map(fun(DBName) ->
case (catch binary:split(DBName, <<$/>>,
[{scope, {Len,size(DBName)-Len}}])) of
[DBPrefix, VB] ->
VBStr = binary_to_list(VB),
VBInt = list_to_integer(VBStr),
StatKey = io_lib:format("vb_~p", [VBInt]),
StatVal = get_state(VBInt, State),
{StatKey, StatVal};
_ -> ignore
end
end, DBs)).

handle_stats(Socket, Opaque, State) ->
lists:foreach(fun({N, V}) ->
mc_connection:respond(Socket, ?STAT, Opaque,
mc_couch_stats:mk_stat(N, V))
end, list_vbuckets(State)),
mc_connection:respond(Socket, ?STAT, Opaque,
mc_couch_stats:mk_stat("", "")).

Expand Down

0 comments on commit 1e78a3c

Please sign in to comment.