Skip to content

Commit cef725e

Browse files
committed
Add counter ops to pb driver
1 parent 7a5decc commit cef725e

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{erl_opts, [{src_dirs, [src]},
3333
{parse_transform, lager_transform}]}.
3434

35-
{escript_incl_apps, [lager, getopt, bear, folsom, ibrowse, riakc, mochiweb, protobuffs, velvet]}.
35+
{escript_incl_apps, [lager, getopt, bear, folsom, ibrowse, riakc, riak_pb, mochiweb, protobuffs, velvet]}.
3636

3737
{escript_emu_args, "%%! +K true\n"}.
3838
%% Use this for the Java client bench driver

src/basho_bench_driver_riakc_pb.erl

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@
3131
-record(state, { pid,
3232
bucket,
3333
r,
34+
pr,
3435
w,
3536
dw,
37+
pw,
3638
rw,
3739
keylist_length,
3840
preloaded_keys,
@@ -75,6 +77,8 @@ new(Id) ->
7577
W = basho_bench_config:get(riakc_pb_w, Replies),
7678
DW = basho_bench_config:get(riakc_pb_dw, Replies),
7779
RW = basho_bench_config:get(riakc_pb_rw, Replies),
80+
PW = basho_bench_config:get(riakc_pb_pw, Replies),
81+
PR = basho_bench_config:get(riakc_pb_pr, Replies),
7882
Bucket = basho_bench_config:get(riakc_pb_bucket, <<"test">>),
7983
KeylistLength = basho_bench_config:get(riakc_pb_keylist_length, 1000),
8084
PreloadedKeys = basho_bench_config:get(
@@ -90,9 +94,11 @@ new(Id) ->
9094
{ok, #state { pid = Pid,
9195
bucket = Bucket,
9296
r = R,
97+
pr = PR,
9398
w = W,
9499
dw = DW,
95100
rw = RW,
101+
pw = PW,
96102
keylist_length = KeylistLength,
97103
preloaded_keys = PreloadedKeys,
98104
timeout_general = get_timeout_general(),
@@ -234,8 +240,32 @@ run(mr_keylist_erlang, KeyGen, _ValueGen, State) ->
234240
mapred(State, Keylist, ?ERLANG_MR);
235241
run(mr_keylist_js, KeyGen, _ValueGen, State) ->
236242
Keylist = make_keylist(State#state.bucket, KeyGen,
237-
State#state.keylist_length),
238-
mapred(State, Keylist, ?JS_MR).
243+
State#state.keylist_length),
244+
mapred(State, Keylist, ?JS_MR);
245+
run(counter_incr, KeyGen, ValueGen, State) ->
246+
Amt = ValueGen(),
247+
Key = KeyGen(),
248+
case riakc_pb_socket:counter_incr(State#state.pid, State#state.bucket, Key, Amt,
249+
[{w, State#state.w},
250+
{dw, State#state.dw},
251+
{pw, State#state.pw}]) of
252+
ok ->
253+
{ok, State};
254+
{error, Reason} ->
255+
{error, Reason, State}
256+
end;
257+
run(counter_val, KeyGen, _ValueGen, State) ->
258+
Key = KeyGen(),
259+
case riakc_pb_socket:counter_val(State#state.pid, State#state.bucket, Key,
260+
[{r, State#state.r}, {pr, State#state.pr}]) of
261+
{ok, _N} ->
262+
{ok, State};
263+
{error, notfound} ->
264+
{ok, State};
265+
{error, Reason} ->
266+
{error, Reason, State}
267+
end.
268+
239269

240270
%% ====================================================================
241271
%% Internal functions

src/basho_bench_valgen.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ new({function, Module, Function, Args}, Id) ->
5252
_Error ->
5353
?FAIL_MSG("Could not find valgen function: ~p:~p\n", [Module, Function])
5454
end;
55+
new({random_int, MaxSize}, _Id) ->
56+
fun() -> random:uniform(MaxSize) end;
5557
new(Other, _Id) ->
5658
?FAIL_MSG("Unsupported value generator requested: ~p\n", [Other]).
5759

0 commit comments

Comments
 (0)