Secondary indexes not working with Erlang Riak client
SserwangaV opened this issue · 6 comments
On Riak-KV 3.0.3, Erlang client secondary indexes functions no working.
Any more context - e.g. using HTTP, or PBC, which version of the riak erlang client etc. What error are you getting back?
I will fire up a fresh instance and check now. The standard riak_test suite we use before release does check 2i via the riak erlang client though (both HTTP and PB) so I would not have expected a bug to slip through.
I've done a fresh local install of riak 3.0.3, and double-checked basic 2i functionality. All was OK for me.
I'm using PBC, I've tried https://github.com/basho/riak-erlang-client/tree/riak_kv-3.0.1. It does not show any error but just returns as if there no matching objects. I'm running this package riak_3.0.3-OTP22.3_amd64.deb for Ubuntu Xenial got from https://files.tiot.jp/riak/kv/3.0/3.0.3/ubuntu/xenial64/
I build riak 3.0.3 from source on OSX. Then did rebar3 shell
in a riak-erlang-client repo (using develop-3.0
branch).
Here's how I tested with that client:
3> {ok, P} = riakc_pb_socket:start('127.0.0.1',8087).
{ok,<0.462.0>}
4> riakc_pb_socket:get_index_range(P, <<"test">>, <<"field1_bin">>, <<"A">>, <<"B">>).
{ok,{index_results_v1,[],undefined,undefined}}
5> O1 = riakc_obj:new(<<"test">>, <<"K1">>, <<"test_value">>).
{riakc_obj,<<"test">>,<<"K1">>,undefined,[],undefined,
<<"test_value">>}
6> MD1 = riakc_obj:get_metadata(O1).
{dict,0,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}}
9> MD2 = riakc_obj:add_secondary_index(MD1, [{{binary_index, <<"field1">>}, [<<"A">>, <<"A0">>, <<"C">>]}]).
{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
{{[],[],[],[],[],[],[],[],[],[],[],
[[<<"index">>,
{<<"field1_bin">>,<<"A">>},
{<<"field1_b"...>>,<<"A0">>},
{<<"fiel"...>>,<<...>>}]],
[],[],[],[]}}}
10> O2 = riakc_obj:update_metadata(O1, MD2).
{riakc_obj,<<"test">>,<<"K1">>,undefined,[],
{dict,1,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],[],[[...]],[],...}}},
<<"test_value">>}
11> riakc_pb_socket:put(P, O2).
ok
12> riakc_pb_socket:get_index_range(P, <<"test">>, <<"field1_bin">>, <<"A">>, <<"B">>).
{ok,{index_results_v1,[<<"K1">>,<<"K1">>],
undefined,undefined}}
16> riakc_pb_socket:get_index_range(P, <<"test">>, <<"field1_bin">>, <<"A">>, <<"A">>).
{ok,{index_results_v1,[<<"K1">>],undefined,undefined}}
Do you have a failure with this trivial example?
Sorry, the backend was left to the default bitcast. I changed to leveldb and it is now working properly.
OK, that's good to know. To be fair, I made the same mistake when trying to run the trivial test earlier!
BTW, you should have got a more helpful error message:
riakc_pb_socket:get_index_range(P, <<"test">>, <<"field1_bin">>, <<"A">>, <<"B">>).
{error,<<"{error,{indexes_not_supported,riak_kv_bitcask_backend}}">>}