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

fix: Don't modify where_to_read for the tables during bootstrap #162

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/mria_bootstrapper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ push_batch({Node, Pid}, Batch = {_, _, _}) ->
complete({Node, Pid}, Server, Checkpoint) ->
mria_lib:rpc_call_nothrow(Node, ?MODULE, do_complete, [Pid, Server, Checkpoint]).

handle_batch(Server, Table, ?clear_table) ->
handle_batch(_Server, Table, ?clear_table) ->
mria_schema:ensure_local_table(Table),
mria_mnesia:set_where_to_read(node(Server), Table),
{atomic, ok} = mnesia:clear_table(Table),
ok;
handle_batch(_Server, Table, Records) ->
Expand Down
1 change: 1 addition & 0 deletions src/mria_rlog_replica.erl
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ format_data(D) ->
maps:from_list([{Field, Val} || {Field, Val} <- lists:zip(FieldNames, Fields),
Field =/= replayq]).

%% TODO: Remove me in the next major release
-spec set_where_to_read(mria_rlog:shard(), node()) -> ok.
set_where_to_read(Shard, Node) ->
[mria_mnesia:set_where_to_read(Node, Tab) || Tab <- mria_schema:tables_of_shard(Shard)],
Expand Down
44 changes: 27 additions & 17 deletions test/mria_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
-compile(export_all).
-compile(nowarn_export_all).
-compile(nowarn_underscore_match).
-compile(nowarn_deprecated_function). %% Silence the warnings about slave module

-include_lib("eunit/include/eunit.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
Expand Down Expand Up @@ -843,31 +844,17 @@ t_dirty_reads(_) ->
?check_trace(
#{timetrap => 10000},
try
%% Delay shard startup:
?force_ordering(#{?snk_kind := read1},
#{?snk_kind := state_change, to := local_replay, shard := test_shard}),
[N1, N2] = mria_ct:start_cluster(mria_async, Cluster),
mria_mnesia_test_util:wait_tables([N1]),
mria_mnesia_test_util:wait_tables([N1, N2]),
%% Insert data:
ok = rpc:call(N1, mria, dirty_write, [{test_tab, Key, Val}]),
%% Ensure that the replicant still reads the correct value by doing an RPC to the core node:
?block_until(#{?snk_kind := rlog_read_from, source := N1, table := test_tab}),
?assertEqual([{test_tab, Key, Val}], rpc:call(N2, mnesia, dirty_read, [test_tab, Key])),
%% Now allow the shard to start:
?tp(read1, #{}),
?block_until(#{?snk_kind := rlog_read_from, source := N2, table := test_tab}),
%% Ensure that the replicant still reads the correct value locally:
timer:sleep(1000),
?assertEqual([{test_tab, Key, Val}], rpc:call(N2, mnesia, dirty_read, [test_tab, Key]))
after
mria_ct:teardown_cluster(Cluster)
end,
fun(Trace) ->
?assert(
?strict_causality( #{?snk_kind := read1}
, #{?snk_kind := state_change, to := normal, shard := test_shard}
, Trace
))
end).
[]).

%% Test adding tables to the schema:
t_rlog_schema(_) ->
Expand Down Expand Up @@ -1173,6 +1160,29 @@ t_cluster_nodes(_) ->
end,
[]).

schema_merge(_) -> %% TODO: this is a testcase, enable it after merging the patch to OTP
Cluster = [C1, C2, C3] = mria_ct:cluster([core, core, core], mria_mnesia_test_util:common_env()),
?check_trace(
#{timetrap => 30000},
try
%% Start mria on C1 and C2:
[_, N2, _] = Nodes = mria_ct:start_cluster(node, Cluster),
_ = mria_ct:start_mria(C1),
_ = mria_ct:start_mria(C2),
%% Stop C2 and start C3 (it should join C3):
ok = slave:stop(N2),
timer:sleep(5000),
_ = mria_ct:start_mria(C3),
%% Restart C2:
_ = mria_ct:start_slave(mria, C2),
?retry(1000, 20,
?assertMatch({[[], [], []], []},
rpc:multicall(Nodes, mria, info, [stopped_nodes])))
after
ok = mria_ct:teardown_cluster(Cluster)
end,
[]).

t_join_each_other_simultaneously(_) ->
Cluster = [maps:remove(join_to, Spec)
|| Spec <- mria_ct:cluster([core, core], mria_mnesia_test_util:common_env())],
Expand Down
Loading