Fix wrong index preparation in mrdb:index_read_/3 #1
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "uw-catchup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In the case when index is of type {_}, index is returned as is
instead of putting it into a tuple {Ix, ordered}.
An example
Given the following index plugin implementation:
-module(key6).
-record(cgh, {key, val}).
-export([k6/3
, add_index/0
, create_table/0
, tst_bad_type/0
]).
k6(_, _, #cgh{key = {Name, K8, _Cid, _Vn}}) ->
[list_to_binary([atom_to_binary(Name),
list_to_binary(lists:sublist(K8, 6))])].
add_index() ->
mnesia_schema:add_index_plugin({k6}, key6, k6).
create_table() ->
mnesia:create_table(cgh,
[{attributes, record_info(fields, cgh)},
{type, ordered_set},
{index, [{k6}]},
{rocksdb_copies, [node()]},
{local_content, true}]).
tst_bad_type() ->
E1 = #cgh{key = {n1, "u1vgrjkh",{ecgi,238,6,213020,50},3}, val = ok},
mnesia:dirty_write(E1),
Index1 = list_to_binary([atom_to_binary(n1),
list_to_binary(lists:sublist("u1vgrjkh", 6))]),
mrdb:index_read(cgh, Index1, {k6}).
-- testing --
Eshell V14.2.2 (press Ctrl+G to abort, type help(). for help)
(rock@bang)2> mnesia:create_schema([node()]).
ok
(rock@bang)3> mnesia:start().
ok
(rock@bang)4> mnesia_rocksdb:register().
{ok,rocksdb_copies}
(rock@bang)5> l(key6).
{module,key6}
(rock@bang)6> key6:add_index().
{atomic,ok}
(rock@bang)7> key6:create_table().
{atomic,ok}
(rock@bang)8> key6:tst_bad_type().
** exception exit: {aborted,{bad_type,{cgh,index,{k6}}}}
in function mnesia:abort/1 (mnesia.erl, line 362)
in call from mrdb:ensure_ref/1 (
/projects/erlang/github/mnesia_rocksdb/src/mrdb.erl, line 609)/projects/erlang/github/mnesia_rocksdb/src/mrdb.erl, line 945)in call from mrdb:index_read_/3 (
-- after patch --
(rock@bang)9> c(mrdb).
Recompiling ~/projects/erlang/github/mnesia_rocksdb/src/mrdb.erl
{ok,mrdb}
(rock@bang)10> key6:tst_bad_type().
[{cgh,{n1,"u1vgrjkh",{ecgi,238,6,213020,50},3},ok}]
(rock@bang)11>
requested review from @zxq9, @dimitar.p.ivanov, and @hans_sv
assigned to @uwiger
mentioned in commit
d9d82d7ead