[Kai-commits] SF.net SVN: kai:[136] trunk
Kai is a distributed key-value datastore
Status: Beta
Brought to you by:
takemaru
From: <shi...@us...> - 2009-03-24 02:38:32
|
Revision: 136 http://kai.svn.sourceforge.net/kai/?rev=136&view=rev Author: shino_shun Date: 2009-03-24 02:38:28 +0000 (Tue, 24 Mar 2009) Log Message: ----------- add: kai_unreconciled_get property for STATS command Modified Paths: -------------- trunk/src/kai_stat.erl trunk/test/kai_memcache_SUITE.erl trunk/test/kai_stat_SUITE.erl Modified: trunk/src/kai_stat.erl =================================================================== --- trunk/src/kai_stat.erl 2009-03-22 05:54:05 UTC (rev 135) +++ trunk/src/kai_stat.erl 2009-03-24 02:38:28 UTC (rev 136) @@ -15,7 +15,7 @@ -export([start_link/0, stop/0]). -export([all/0, incr_cmd_get/0, incr_cmd_set/0, add_bytes_read/1, - add_bytes_write/1]). + add_bytes_write/1, incr_unreconciled_get/1]). -export([ init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3 @@ -23,8 +23,9 @@ -include("kai.hrl"). -record(state, { - boot_time, cmd_get, cmd_set, bytes_read, bytes_write, - node, quorum, number_of_buckets, number_of_virtual_nodes, store + boot_time, cmd_get, cmd_set, bytes_read, bytes_write, + unreconciled_get, node, quorum, + number_of_buckets, number_of_virtual_nodes, store }). -define(SERVER, ?MODULE). @@ -46,6 +47,8 @@ cmd_set = 0, bytes_read = 0, bytes_write = 0, + unreconciled_get = array:new([{size,2}, {fixed, false}, + {default, [0,0]}]), node = LocalNode, quorum = Quorum, number_of_buckets = NumberOfBuckets, @@ -69,8 +72,15 @@ Addr = join(".", [integer_to_list(X) || X <- [A1,A2,A3,A4]]), Addr ++ ":" ++ integer_to_list(Port). +format_unreconciled_get(UnreconciledGet) -> + join(" ", + array:foldr( + fun(_Index, [UnReconciled, InternalNum], Acc) -> + [io_lib:format("~B(~B)", [UnReconciled, InternalNum]) | Acc] + end, [], UnreconciledGet)). + stat(Name, State) -> - case Name of + case Name of uptime -> {Msec, Sec, _Usec} = now(), Uptime = 1000000 * Msec + Sec - State#state.boot_time, @@ -120,6 +130,9 @@ {node_list, Nodes} = kai_hash:node_list(), NodesInList = lists:sort([node_to_list(N) || N <- Nodes]), {kai_curr_nodes, join(" ", NodesInList)}; + kai_unreconciled_get -> + {kai_unreconciled_get, + format_unreconciled_get(State#state.unreconciled_get)}; % kai_curr_buckets -> % {buckets, Buckets} = kai_hash:buckets(), % {kai_curr_buckets, join(" ", [integer_to_list(B) || B <- Buckets])}; @@ -139,11 +152,12 @@ bytes_read, bytes_write, kai_node, kai_quorum, kai_number_of_buckets, kai_number_of_virtual_nodes, kai_store, kai_curr_nodes, + kai_unreconciled_get, %kai_curr_buckets, erlang_procs, erlang_version] ), {reply, Stats, State}. - + incr_cmd_get(State) -> State2 = State#state{cmd_get = State#state.cmd_get + 1}, {noreply, State2}. @@ -152,6 +166,19 @@ State2 = State#state{cmd_set = State#state.cmd_set + 1}, {noreply, State2}. +incr_unreconciled_get(InternalNum, Reconciled, State) -> + Old = State#state.unreconciled_get, + Index = InternalNum -2, % index is 0: two versions, 1: three, etc. + [Unreconciled, Internal] = array:get(Index, Old), + New = array:set(InternalNum -2, + case Reconciled of + true -> [Unreconciled, Internal + 1]; + _ -> [Unreconciled + 1, Internal + 1] + end, + Old), + State2 = State#state{unreconciled_get = New}, + {noreply, State2}. + add_bytes_read(Data, State) -> Bytes = lists:sum([byte_size(D#data.value) || D <- Data]), State2 = State#state{bytes_read = State#state.bytes_read + Bytes}, @@ -173,7 +200,9 @@ handle_cast({add_bytes_read, Data}, State) -> add_bytes_read(Data, State); handle_cast({add_bytes_write, Data}, State) -> - add_bytes_write(Data, State). + add_bytes_write(Data, State); +handle_cast({incr_unreconciled_get, {InternalNum, Reconciled}}, State) -> + incr_unreconciled_get(InternalNum, Reconciled, State). handle_info(_Info, State) -> {noreply, State}. code_change(_OldVsn, State, _Extra) -> @@ -191,3 +220,5 @@ gen_server:cast(?SERVER, {add_bytes_read, Data}). add_bytes_write(Data) -> gen_server:cast(?SERVER, {add_bytes_write, Data}). +incr_unreconciled_get(Data) -> + gen_server:cast(?SERVER, {incr_unreconciled_get, Data}). Modified: trunk/test/kai_memcache_SUITE.erl =================================================================== --- trunk/test/kai_memcache_SUITE.erl 2009-03-22 05:54:05 UTC (rev 135) +++ trunk/test/kai_memcache_SUITE.erl 2009-03-24 02:38:28 UTC (rev 136) @@ -117,6 +117,7 @@ {ok, NumberOfVirtualNodes} = gen_tcp:recv(MemcacheSocket, 0), {ok, Store } = gen_tcp:recv(MemcacheSocket, 0), {ok, Nodes } = gen_tcp:recv(MemcacheSocket, 0), + {ok, UnreconciledGet } = gen_tcp:recv(MemcacheSocket, 0), % {ok, Buckets } = gen_tcp:recv(MemcacheSocket, 0), {ok, ErlangProcs } = gen_tcp:recv(MemcacheSocket, 0), {ok, ErlangVersion } = gen_tcp:recv(MemcacheSocket, 0), @@ -136,6 +137,7 @@ {match, _Sd, _Ld} = regexp:match(binary_to_list(NumberOfVirtualNodes), "kai_number_of_virtual_nodes"), {match, _Se, _Le} = regexp:match(binary_to_list(Store), "kai_store"), {match, _Sf, _Lf} = regexp:match(binary_to_list(Nodes), "kai_curr_nodes"), + {match, _Sk, _Lk} = regexp:match(binary_to_list(UnreconciledGet), "kai_unreconciled_get"), % {match, _Sg, _Lg} = regexp:match(binary_to_list(Buckets), "kai_curr_buckets"), {match, _Sh, _Lh} = regexp:match(binary_to_list(ErlangProcs), "erlang_procs"), {match, _Si, _Li} = regexp:match(binary_to_list(ErlangVersion), "erlang_version"), Modified: trunk/test/kai_stat_SUITE.erl =================================================================== --- trunk/test/kai_stat_SUITE.erl 2009-03-22 05:54:05 UTC (rev 135) +++ trunk/test/kai_stat_SUITE.erl 2009-03-24 02:38:28 UTC (rev 136) @@ -41,6 +41,10 @@ Data = #data{value = (<<"value-1">>)}, kai_stat:add_bytes_read([Data, Data]), kai_stat:add_bytes_write(Data), + lists:map(fun(Arg) -> + kai_stat:incr_unreconciled_get(Arg) + end, + [{2, true},{2, true},{2, false},{3,true},{5,false}]), [{uptime, Uptime }, {time, Time }, @@ -58,6 +62,7 @@ {kai_number_of_virtual_nodes, NumberOfVirtualNodes}, {kai_store, Store }, {kai_curr_nodes, Nodes }, + {kai_unreconciled_get, UnreconciledGet }, % {kai_curr_buckets, Buckets }, {erlang_procs, ErlangProcs }, {erlang_version, ErlangVersion }] = kai_stat:all(), @@ -77,6 +82,7 @@ ?assertEqual("2", NumberOfVirtualNodes), ?assertEqual("ets", Store ), ?assertEqual("127.0.0.1:11011", Nodes ), + ?assertEqual("1(3) 0(1) 0(0) 1(1)", lists:flatten(UnreconciledGet)), % ?assertEqual("0 1 2 3 4 5 6 7", Buckets ), {match, _S5, _L5} = regexp:match(ErlangProcs, "[0-9]+"), {match, _S6, _L6} = regexp:match(ErlangVersion, "[.0-9]+"), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |