Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting table to disc_copies empties the table #8706

Closed
Juliusan opened this issue Aug 9, 2024 · 1 comment
Closed

Converting table to disc_copies empties the table #8706

Juliusan opened this issue Aug 9, 2024 · 1 comment
Assignees
Labels
bug Issue is reported as a bug team:PS Assigned to OTP team PS

Comments

@Juliusan
Copy link

Juliusan commented Aug 9, 2024

Describe the bug
I was experimenting with RocksDB as a back-end for mnesia table (https://github.com/aeternity/mnesia_rocksdb) and I was able to convert a table to rocksdb_copies successfully, however converting it back to disc_copies emptied the table after next restart. On the other hand, converting RocksDB table to ram_copies and only then to disc_copies was successful.
I've registered an issue in mnesia_rocksdb (aeternity/mnesia_rocksdb#53), but the decision there was that mnesia is resposible for converting to disc_copies.

To Reproduce

  1. Start Erlang single node with mnesia_rocksdb in libs. Do the following:
    mnesia:start(),
    {atomic, ok} = mnesia:change_table_copy_type(schema, node(), disc_copies),
    {atomic, ok} = mnesia:create_table(?TABLE_NAME, [
        {type, set},
        {record_name, some_rec},
        {attributes, record_info(fields, some_rec)},
        {disc_copies, [node()]}
    ]),
    mnesia:activity(transaction, fun() ->
        mnesia:write(?TABLE_NAME, #some_rec{some_id = a, some_int = 1, some_string = "something" }, write),
        mnesia:write(?TABLE_NAME, #some_rec{some_id = b, some_int = 2, some_string = "anything"  }, write),
        mnesia:write(?TABLE_NAME, #some_rec{some_id = c, some_int = 3, some_string = "everything"}, write),
        mnesia:write(?TABLE_NAME, #some_rec{some_id = d, some_int = 4, some_string = "nothing"   }, write)
    end),
    {ok, rocksdb_copies} = mnesia_rocksdb:register(),
    {atomic, ok} = mnesia:change_table_copy_type(?TABLE_NAME, node(), rocksdb_copies),
    a = mnesia:dirty_first(?TABLE_NAME),
    % {atomic, ok} = mnesia:change_table_copy_type(?TABLE_NAME, node(), ram_copies),
    % a = mnesia:dirty_first(?TABLE_NAME),
    {atomic, ok} = mnesia:change_table_copy_type(?TABLE_NAME, node(), disc_copies),
    a = mnesia:dirty_first(?TABLE_NAME),
    q().

Note that after table is transformed to disc_copies, the records (at least the first one) are still in it. They are available until the node is restarted.

Also note that two lines are commented out. Uncomment them, if you want to see how converting through ram_copies works.

  1. Restart the node and do the following:
    mnesia:start(),
    ok = mnesia:wait_for_tables([schema, ?TABLE_NAME], 10000),
    a = mnesia:dirty_first(?TABLE_NAME),

The last line throws an exception: "no match of right hand side value '$end_of_table'". Therefore, the table is empty.

The definitions are as follows:

-define(TABLE_NAME, test_table).
-record(some_rec, {
    some_id     :: atom(),
    some_int    :: integer(),
    some_string :: string()
}).

Expected behavior
Table is converted to disc_copies without need to convert to ram_copies first and all the records of the table remain there.

Affected versions
I've tested on Debian Bookwork Linux on OTPs 26.1, 26.1.2, 26.2 and 27.0.1 and on Oracle Enterprise Linux 9 on OTP 26.2.1 and the bug consistently occurred. However, in the rocksdb_mnesia issue there is a mention that the bug is not reproducible on OTP 26.1.2 (I am not sure about the OS used).

@Mikaka27
Copy link
Contributor

This will be fixed in 27.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:PS Assigned to OTP team PS
Projects
None yet
Development

No branches or pull requests

4 participants