Skip to content

Commit ce270d6

Browse files
committed
fix: Force load of ?rlog_sync table
1 parent c4beb62 commit ce270d6

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

src/mria_mnesia.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%%--------------------------------------------------------------------
2-
%% Copyright (c) 2019-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
2+
%% Copyright (c) 2019-2026 EMQ Technologies Co., Ltd. All Rights Reserved.
33
%%
44
%% Licensed under the Apache License, Version 2.0 (the "License");
55
%% you may not use this file except in compliance with the License.
@@ -264,7 +264,7 @@ copy_table(Name, Storage) ->
264264
-spec wait_for_tables([mria:table()]) -> ok | {error, _Reason}.
265265
wait_for_tables(Tables) ->
266266
?tp(mria_wait_for_tables, #{tables => Tables}),
267-
case mnesia:wait_for_tables(Tables, 30000) of
267+
case mnesia:wait_for_tables(Tables, 5_000) of
268268
ok ->
269269
?tp(mria_wait_for_tables_done, #{result => ok}),
270270
ok;

src/mria_schema.erl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
%%--------------------------------------------------------------------
2-
%% Copyright (c) 2021-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
2+
%% Copyright (c) 2021-2026 EMQ Technologies Co., Ltd. All Rights Reserved.
33
%%
44
%% Licensed under the Apache License, Version 2.0 (the "License");
55
%% you may not use this file except in compliance with the License.
@@ -343,9 +343,9 @@ bootstrap() ->
343343
%% Ensure replicas are available before starting copy:
344344
%% If we've managed to sync only mnesia schema up to this point, `copy_table/2` may
345345
%% fail if other nodes suddenly become unavailable.
346-
ok = mria_mnesia:wait_for_tables([?rlog_sync]),
347346
ok = mria_mnesia:copy_table(?rlog_sync, null_copies),
348-
mria_mnesia:wait_for_tables([?schema, ?rlog_sync]),
347+
%% Contents of this table are irrelevant, so force load:
348+
force_load(?rlog_sync),
349349
%% Seed the table with the metadata:
350350
{atomic, _} = mnesia:transaction(fun mnesia:write/3, [?schema, MetaSpec, write], infinity),
351351
{atomic, _} = mnesia:transaction(fun mnesia:write/3, [?schema, RlogSyncSpec, write], infinity),
@@ -386,3 +386,12 @@ notify_change(Shard, Entry, Subscribers) ->
386386
-spec create_table(entry()) -> ok | _.
387387
create_table(#?schema{mnesia_table = Table, storage = Storage, config = Config}) ->
388388
mria_lib:ensure_tab(mnesia:create_table(Table, [{Storage, [node()]} | Config])).
389+
390+
%% @doc Force load a table. Note: mnesia waits for table implicitly.
391+
force_load(Table) ->
392+
case mnesia:force_load_table(Table) of
393+
yes ->
394+
ok;
395+
Other ->
396+
logger:error("Failed to force loading table ~p: ~p", [Table, Other])
397+
end.

test/mria_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ t_full_cluster_restart(_) ->
12501250
ok = ?ON(N1, mria:dirty_write(tab1, {tab1, foo, bar})),
12511251
ok = ?ON(N2, mria:dirty_write(tab2, {tab2, foo, bar})),
12521252
ok = ?ON(N3, mria:dirty_write(tab3, {tab3, foo, bar})),
1253-
%% Restart nodes simulataneously:
1253+
%% Restart nodes simultaneously:
12541254
?tp(notice, test_restart_nodes, #{}),
12551255
[ok = slave:stop(N) || N <- Nodes],
12561256
[mria_ct:start_slave(mria, CN) || CN <- Cluster],
@@ -1262,7 +1262,7 @@ t_full_cluster_restart(_) ->
12621262
end,
12631263
[]).
12641264

1265-
%% This function creates an an inter-dependent table load order that
1265+
%% This function creates an inter-dependent table load order that
12661266
%% simulates startup sequence of a release containing multiple OTP
12671267
%% applications with complex dependencies:
12681268
full_restart_load_chain() ->

test/mria_autoclean_SUITE.erl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,21 @@ t_autoclean(_) ->
4343
?check_trace(
4444
begin
4545
MaxDownSecs = 10,
46-
Cluster = mria_ct:cluster([core, core], []),
46+
Cluster = mria_ct:cluster([core, core, replicant], mria_mnesia_test_util:common_env()),
4747
try
4848
%% Prepare cluster:
49-
[N0, N1] = mria_ct:start_cluster(mria, Cluster),
49+
[N0, N1, N3] = mria_ct:start_cluster(mria, Cluster),
5050
?assertMatch(
51-
[N0, N1],
51+
[N0, N1, N3],
5252
erpc:call(N0, mria, info, [running_nodes])
5353
),
54+
timer:sleep(1000),
55+
%% Create a table to simulate more realistic conditions:
56+
ok = erpc:call(N0, mria, create_table,
57+
[?MODULE, [ {type, set}
58+
, {storage, disc_copies}
59+
, {rlog_shard, ?MODULE}
60+
]]),
5461
%% Shut down one node:
5562
mria_ct:stop_slave(N1),
5663
%% Reconfigure autoclean in the runtime to make sure autoclean
@@ -60,7 +67,7 @@ t_autoclean(_) ->
6067
%% The remaining node must eventually drop the peer:
6168
?assertMatch(
6269
{ok, T} when T >= MaxDownSecs,
63-
wait_down(N0, N1, MaxDownSecs * 2)
70+
wait_down(N3, N1, MaxDownSecs * 2)
6471
)
6572
after
6673
mria_ct:teardown_cluster(Cluster)

test/mria_mnesia_test_util.erl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,5 @@ common_env() ->
7070
[ {mria, db_backend, rlog}
7171
, {mria, rlog_startup_shards, [test_shard]}
7272
, {mria, strict_mode, true}
73-
, {mria, rpc_module, gen_rpc}
7473
, {mria, lb_poll_interval, 100}
7574
].

0 commit comments

Comments
 (0)