5454 % ID 1 is nominated to do special work
5555 singleton_pid :: pid () | undefined ,
5656 unique_key_count = 1 :: non_neg_integer (),
57+ unique_key_lowcount = 1 :: non_neg_integer (),
5758 alwaysget_key_count = 1 :: non_neg_integer (),
5859 keyid :: binary (),
5960 last_forceaae = os :timestamp () :: erlang :timestamp ()
@@ -432,7 +433,8 @@ run(get_unique, _KeyGen, _ValueGen, State) ->
432433 Pid = State # state .pb_pid ,
433434 Bucket = State # state .documentBucket ,
434435 UKC = State # state .unique_key_count ,
435- Key = generate_uniquekey (random :uniform (UKC ),
436+ LKC = State # state .unique_key_lowcount ,
437+ Key = generate_uniquekey (LKC + random :uniform (UKC - LKC ),
436438 State # state .keyid ,
437439 State # state .unique_keyorder ),
438440 case riakc_pb_socket :get (Pid , Bucket , Key , State # state .pb_timeout ) of
@@ -443,6 +445,28 @@ run(get_unique, _KeyGen, _ValueGen, State) ->
443445 {error , Reason } ->
444446 {error , Reason , State }
445447 end ;
448+ run (delete_unique , _KeyGen , _ValueGen , State ) ->
449+ % % Delete one of the unique keys, assuming that the deletions have not
450+ % % caught up with the PUTs
451+ Pid = State # state .pb_pid ,
452+ B = State # state .documentBucket ,
453+ UKC = State # state .unique_key_count ,
454+ LKC = State # state .unique_key_lowcount ,
455+ case LKC < UKC of
456+ true ->
457+ Key = generate_uniquekey (LKC ,
458+ State # state .keyid ,
459+ State # state .unique_keyorder ),
460+ R = riakc_pb_socket :delete (Pid , B , Key , State # state .pb_timeout ),
461+ case R of
462+ ok ->
463+ {ok , State # state {unique_key_lowcount = LKC + 1 }};
464+ {error , Reason } ->
465+ {error , Reason , State # state {unique_key_lowcount = LKC + 1 }}
466+ end ;
467+ false ->
468+ {ok , State }
469+ end ;
446470
447471% % Query results via the HTTP interface.
448472run (postcodequery_http , _KeyGen , _ValueGen , State ) ->
0 commit comments