Hi Olav. As you have observed the key length of the generated keys is not 
guaranteed. 
riak_core_util:unique_id_62 generates a 20 byte SHA hash and that value is 
converted to a base 62 
representation and that representation, converted to a string, becomes the key. 
The length of the 
generated key can be determined by taking the ceiling of the value of log62(X), 
where X is the integer value
of the SHA result. So the length of the key is going to be dependent on the 
magnitude of the 
value of that SHA.

That means that right now the answer is there is not a way to enforce that all 
keys generated
by Riak be of the exact same length. If that is a requirement for your 
application you will 
have to generate them on the client side. 

Cheers,
Kelly

On Nov 6, 2012, at 4:55 AM, Olav Frengstad <o...@fwt.no> wrote:

> Hey,
> 
> I'm using keys generated by Riak  and have come over some random
> failure in my test cases. I have naively assumed that the 160bit hash
> would always return a base62 encoded value with the length of 27. On
> that point I'm obviously wrong as the shell session below shows.
> 
> My question is this by design? If so is there a way to enforce certain
> size of a key WITHOUT performing generation outside Riak?
> 
> Test of riak key size:
> 
> 72> P = fun(S) -> put(S, case get(S) of undefined -> 1; X -> X+1 end) end.
> #Fun<erl_eval.6.82930912>
> 73> F = fun(X, A) when A =< 1000000 ->
> P(length(riak_core_util:unique_id_62())), X(X, A+1); (_, A) -> A end.
> #Fun<erl_eval.12.82930912>
> 74> F(F, 0).
> 1000001
> 75> erlang:process_info(self(), dictionary).
> {dictionary,[{27,982324},{26,27210},{25,461},{24,7}]}
> 
> Cheers,
> Olav
> 
> _______________________________________________
> riak-users mailing list
> riak-users@lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to