Provide mnesia_rocksdb:backup/1,2 and restore/1,2 that pair a Mnesia
checkpoint (schema and non-RocksDB tables) with RocksDB backup engines
for open admin and standalone databases.
Restore stages RocksDB into a sibling directory and redirects mountpoints
while Mnesia fallback purges the real directory, then relocates the data
and optionally restarts. Raise the minimum OTP version to 27.
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)
in call from mrdb:index_read_/3 (~/projects/erlang/github/mnesia_rocksdb/src/mrdb.erl, line 945)
-- 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>