Created
March 12, 2014 16:10
-
-
Save kellymclaughlin/9510156 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(cs_manifest_siblings). | |
-compile(export_all). | |
start() -> | |
start(1). | |
%% @doc Trace to determine the number of siblings of Riak CS manifest | |
%% objects. The `Threshold' parameter is used to limit the output to | |
%% manifest objects whose sibling count is >= to `Threshold'. | |
start(Threshold) -> | |
dbg:tracer(process, {fun trace/2, {orddict:new(), {threshold, Threshold}}}), | |
dbg:p(all, call), | |
dbg:tpl(riak_cs_utils, get_manifests, 3, [{'_', [], [{return_trace}]}]). | |
stop() -> dbg:stop_clear(). | |
trace({trace, Pid, call, {riak_cs_utils, get_manifests, [_, Bucket, Key]}}, | |
{D, Threshold}) -> | |
D2 = orddict:store({Pid, riak_cs_utils, get_manifests}, {Bucket, Key}, D), | |
{D2, Threshold}; | |
trace({trace, Pid, return_from, {riak_cs_utils, get_manifests, _}, Result}, Acc={D, {threshold, Threshold}}) -> | |
case orddict:find({Pid, riak_cs_utils, get_manifests}, D) of | |
{ok, {Bucket, Key}} -> | |
case Result of | |
{ok, RiakObj, _} -> | |
ValueCount = riakc_obj:value_count(RiakObj), | |
case ValueCount >= Threshold of | |
true -> | |
lager:log(info, Pid, "The manifest object for ~p:~p has ~p siblings\n", | |
[Bucket, Key, ValueCount]); | |
false -> | |
ok | |
end; | |
_ -> | |
ok | |
end, | |
D2 = orddict:erase(Key, D), | |
{D2, {threshold, Threshold}}; | |
error -> Acc | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment