Skip to content

Commit

Permalink
Implementing riak_kv_bitcask_backend:key_counts() for bz://863
Browse files Browse the repository at this point in the history
  • Loading branch information
dizzyd committed Nov 4, 2010
1 parent 0eda2a8 commit d4c6930
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/riak_kv_bitcask_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
-author('Andy Gross <andy@basho.com>').
-author('Dave Smith <dizzyd@basho.com>').

%% KV Backend API
-export([start/2,
stop/1,
get/2,
Expand All @@ -38,6 +39,9 @@
is_empty/1,
callback/3]).

%% Helper API
-export([key_counts/0]).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
Expand Down Expand Up @@ -203,10 +207,29 @@ callback({Ref, BitcaskRoot}, Ref, merge_check) when is_reference(Ref) ->
callback(_State, _Ref, _Msg) ->
ok.

key_counts() ->
case application:get_env(bitcask, data_root) of
{ok, RootDir} ->
[begin
{Keys, _} = status(filename:join(RootDir, Dir)),
{Dir, Keys}
end || Dir <- element(2, file:list_dir(RootDir))];
{error, Reason} ->
{error, Reason}
end.

%% ===================================================================
%% Internal functions
%% ===================================================================

%% @private
%% Invoke bitcask:status/1 for a given directory
status(Dir) ->
Ref = bitcask:open(Dir),
Status = bitcask:status(Ref),
bitcask:close(Ref),
Status.

%% @private
%% Schedule sync (if necessary)
maybe_schedule_sync(Ref) when is_reference(Ref) ->
Expand Down

2 comments on commit d4c6930

@beerriot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like key_counts/0 is node-global, not vnode-local, is that correct, and intended? (Bringing this up specifically because the other functions in this module operate in a vnode-local manner.)

@dizzyd
Copy link
Contributor Author

@dizzyd dizzyd commented on d4c6930 Nov 7, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's meant purely as a diagnostic tool for the running bitcasks on a given node.

Please sign in to comment.