Skip to content

Commit be33ca3

Browse files
committed
Add node() to key ID
To distnguish between different nodes use a key id rather than random bytes. Aim is to make different nodes produce different keys - if we run basho_bench from > 1 test harness
1 parent da7756d commit be33ca3

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/basho_bench_driver_nhs.erl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
singleton_pid :: pid() | undefined,
5555
unique_key_count = 1 :: non_neg_integer(),
5656
alwaysget_key_count = 1 :: non_neg_integer(),
57-
rand_keyid = crypto:rand_bytes(4) :: binary(),
57+
keyid :: binary(),
5858
last_forceaae = os:timestamp() :: erlang:timestamp()
5959
}).
6060

@@ -125,6 +125,9 @@ new(Id) ->
125125
basho_bench_config:get(alwaysget, {1, 1, key_order}),
126126
{DocSize, DocKeyOrder} =
127127
basho_bench_config:get(unique, {8000, key_order}),
128+
129+
KeyIDint = erlang:phash2(Id) bxor erlang:phash2(node()),
130+
?INFO("Using Node ID ~w to generate ID ~w\n", [node(), KeyIDint]),
128131

129132
case riakc_pb_socket:start_link(PBTargetIp, PBTargetPort) of
130133
{ok, Pid} ->
@@ -146,7 +149,8 @@ new(Id) ->
146149
alwaysget_perworker_minkeycount = AGMinKC,
147150
alwaysget_keyorder = AGKeyOrder,
148151
unique_size = DocSize,
149-
unique_keyorder = DocKeyOrder
152+
unique_keyorder = DocKeyOrder,
153+
keyid = <<KeyIDint:32/integer>>
150154
}};
151155
{error, Reason2} ->
152156
?FAIL_MSG("Failed to connect riakc_pb_socket to ~p port ~p: ~p\n",
@@ -175,7 +179,7 @@ run(alwaysget_http, _KeyGen, _ValueGen, State) ->
175179
case AGKC > State#state.alwaysget_perworker_minkeycount of
176180
true ->
177181
KeyInt = eightytwenty_keycount(AGKC),
178-
Key = generate_uniquekey(KeyInt, State#state.rand_keyid,
182+
Key = generate_uniquekey(KeyInt, State#state.keyid,
179183
State#state.alwaysget_keyorder),
180184
URL =
181185
io_lib:format("http://~s:~p/buckets/~s/keys/~s",
@@ -200,7 +204,7 @@ run(alwaysget_pb, _KeyGen, _ValueGen, State) ->
200204
case AGKC > State#state.alwaysget_perworker_minkeycount of
201205
true ->
202206
KeyInt = eightytwenty_keycount(AGKC),
203-
Key = generate_uniquekey(KeyInt, State#state.rand_keyid,
207+
Key = generate_uniquekey(KeyInt, State#state.keyid,
204208
State#state.alwaysget_keyorder),
205209

206210
case riakc_pb_socket:get(Pid,
@@ -232,7 +236,7 @@ run(alwaysget_updatewith2i, _KeyGen, ValueGen, State) ->
232236
true ->
233237
% Expand the key count
234238
ExpansionKey =
235-
generate_uniquekey(AGKC + 1, State#state.rand_keyid,
239+
generate_uniquekey(AGKC + 1, State#state.keyid,
236240
State#state.alwaysget_keyorder),
237241
case {AGKC rem 1000, State#state.nominated_id} of
238242
{0, true} ->
@@ -247,7 +251,7 @@ run(alwaysget_updatewith2i, _KeyGen, ValueGen, State) ->
247251
false ->
248252
% update an existing key
249253
ExistingKey =
250-
generate_uniquekey(KeyInt, State#state.rand_keyid,
254+
generate_uniquekey(KeyInt, State#state.keyid,
251255
State#state.alwaysget_keyorder),
252256
{ok, Robj} =
253257
riakc_pb_socket:get(Pid,
@@ -307,7 +311,7 @@ run(put_unique, _KeyGen, _ValueGen, State) ->
307311
UKC = State#state.unique_key_count,
308312
Key =
309313
generate_uniquekey(UKC,
310-
State#state.rand_keyid,
314+
State#state.keyid,
311315
State#state.unique_keyorder),
312316

313317
Value = non_compressible_value(State#state.unique_size),
@@ -331,7 +335,7 @@ run(get_unique, _KeyGen, _ValueGen, State) ->
331335
Bucket = State#state.documentBucket,
332336
UKC = State#state.unique_key_count,
333337
Key = generate_uniquekey(random:uniform(UKC),
334-
State#state.rand_keyid,
338+
State#state.keyid,
335339
State#state.unique_keyorder),
336340
case riakc_pb_socket:get(Pid, Bucket, Key, State#state.pb_timeout) of
337341
{ok, _Obj} ->

0 commit comments

Comments
 (0)