Skip to content

Commit

Permalink
Another try
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikaka27 committed Nov 13, 2024
1 parent 01615b2 commit b99bf9a
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 86 deletions.
4 changes: 0 additions & 4 deletions lib/mnesia/src/mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2815,22 +2815,18 @@ remote_dirty_match_object(Tab, Pat) ->
Key = element(2, Pat),
case has_var(Key) of
false ->
io:fwrite("remote_dirty_match_object, Tab: ~p, Pat: ~p, has_var: ~p~n", [Tab, Pat, false]),
mnesia_lib:db_match_object(Tab, Pat);
true ->
PosList = regular_indexes(Tab),
io:fwrite("remote_dirty_match_object, Tab: ~p, Pat: ~p, PosList: ~p, has_var: ~p~n", [Tab, Pat, PosList, true]),
remote_dirty_match_object(Tab, Pat, PosList)
end.
remote_dirty_match_object(Tab, Pat, [Pos | Tail]) when Pos =< tuple_size(Pat) ->
IxKey = element(Pos, Pat),
case has_var(IxKey) of
false ->
io:fwrite("remote_dirty_match_object, Tab: ~p, Pat: ~p, Pos: ~p, Tail: ~p, has_var: ~p~n", [Tab, Pat, Pos, Tail, false]),
mnesia_index:dirty_match_object(Tab, Pat, Pos);
true ->
io:fwrite("remote_dirty_match_object, Tab: ~p, Pat: ~p, Pos: ~p, Tail: ~p, has_var: ~p~n", [Tab, Pat, Pos, Tail, true]),
remote_dirty_match_object(Tab, Pat, Tail)
end;
remote_dirty_match_object(Tab, Pat, []) ->
Expand Down
2 changes: 1 addition & 1 deletion lib/mnesia/src/mnesia.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
-define(ets_prev(Tab, Key), ets:prev(Tab, Key)).
-define(ets_slot(Tab, Pos), ets:slot(Tab, Pos)).
-define(ets_new_table(Tab, Props), _ = ets:new(Tab, Props)).
-define(ets_delete_table(Tab), fun() -> io:fwrite("In ets_delete_table, IsTable: ~p~n", [Tab == ets:whereis(table)]), ets:delete(Tab) end()).
-define(ets_delete_table(Tab), ets:delete(Tab)).
-define(ets_fixtable(Tab, Bool), ets:fixtable(Tab, Bool)).


Expand Down
16 changes: 1 addition & 15 deletions lib/mnesia/src/mnesia_bup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,6 @@ do_fallback_start(true, false) ->

restore_tables(All=[Rec | Recs], Header, Schema, Ext,
State={local, LocalTabs, LT}) ->
io:fwrite("restore_tables, Rec: ~p, Header: ~p, Schema: ~p, Ext: ~p, State: ~p~n", [Rec, Header, Schema, Ext, State]),
Tab = element(1, Rec),
if
Tab =:= LT#local_tab.name ->
Expand All @@ -775,29 +774,23 @@ restore_tables(All=[Rec | Recs], Header, Schema, Ext,
restore_tables(All, Header, Schema, Ext, NewState)
end;
restore_tables(All=[Rec | Recs], Header, Schema, Ext, {new, LocalTabs}) ->
io:fwrite("restore_tables, Rec: ~p, Header: ~p, Schema: ~p, Ext: ~p, State: {new, ~p}~n", [Rec, Header, Schema, Ext, LocalTabs]),
Tab = element(1, Rec),
case ?ets_lookup(LocalTabs, Tab) of
[] ->
State = {not_local, LocalTabs, Tab},
restore_tables(Recs, Header, Schema, Ext, State);
[LT] when is_record(LT, local_tab) ->
State = {local, LocalTabs, LT},
true = (ets:whereis(LT#local_tab.name) =:= undefined),
io:fwrite("After check table before open, table: ~p~n", [Tab]),
case LT#local_tab.opened of
true -> ignore;
false ->
(LT#local_tab.open)(Tab, LT),
true = (ets:whereis(LT#local_tab.name) =:= undefined),
io:fwrite("After check table after open, table: ~p~n", [Tab]),
?ets_insert(LocalTabs,LT#local_tab{opened=true})
end,
restore_tables(All, Header, Schema, Ext, State)
end;
restore_tables(All=[Rec | Recs], Header, Schema, Ext,
S = {not_local, LocalTabs, PrevTab}) ->
io:fwrite("restore_tables, Rec: ~p, Header: ~p, Schema: ~p, Ext: ~p, State: ~p~n", [Rec, Header, Schema, Ext, S]),
Tab = element(1, Rec),
if
Tab =:= PrevTab ->
Expand All @@ -807,21 +800,14 @@ restore_tables(All=[Rec | Recs], Header, Schema, Ext,
restore_tables(All, Header, Schema, Ext, State)
end;
restore_tables(Recs, Header, Schema, Ext, {start, LocalTabs}) ->
io:fwrite("restore_tables, Recs: ~p, Header: ~p, Schema: ~p, Ext: ~p, State: {start, ~p}~n", [Recs, Header, Schema, Ext, LocalTabs]),
try
Dir = mnesia_lib:dir(),
OldDir = filename:join([Dir, "OLD_DIR"]),
mnesia_schema:purge_dir(OldDir, []),
mnesia_schema:purge_dir(Dir, [fallback_name()]),
init_dat_files(Schema, Ext, LocalTabs),
State = {new, LocalTabs},
restore_tables(Recs, Header, Schema, Ext, State)
catch C : R : S ->
io:fwrite("catch: ~p : ~p : ~p~n", [C, R, S]),
erlang:raise(C, R, S)
end;
restore_tables(Recs, Header, Schema, Ext, State);
restore_tables([], _Header, _Schema, _Ext, State) ->
io:fwrite("restore_tables, Recs: [], Header: ~p, Schema: ~p, Ext: ~p, State: ~p~n", [_Header, _Schema, _Ext, State]),
State.

%% Creates all necessary dat files and inserts
Expand Down
11 changes: 0 additions & 11 deletions lib/mnesia/src/mnesia_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,6 @@ try_schedule_late_disc_load(Tabs, Reason, MsgTag) ->
mnesia:lock({global, Item, Nodes}, write),
case multicall(Nodes -- [node()], disc_load_intents) of
{Replies, []} ->
Stack = try throw(42) catch _:42:S -> S end,
io:fwrite("try_schedule_late_disc_load, MsgTag: ~p, Tabs: ~p, Reason: ~p, Replies: ~p~nStack: ~p~n", [MsgTag, Tabs, Reason, Replies, Stack]),
call({MsgTag, Tabs, Reason, Replies}),
done;
{_, BadNodes} ->
Expand Down Expand Up @@ -577,13 +575,6 @@ schema_is_merged() ->
try_schedule_late_disc_load(SafeLoads, initial, MsgTag).


cast({disc_load, Tab, Reason} = Msg) ->
Stack = try throw(42) catch _:42:S -> S end,
io:fwrite("In cast:disc_load, Tab: ~p, Reason: ~p, Stack: ~p~n", [Tab, Reason, Stack]),
case whereis(?SERVER_NAME) of
undefined -> ok;
Pid -> gen_server:cast(Pid, Msg)
end;
cast(Msg) ->
case whereis(?SERVER_NAME) of
undefined -> ok;
Expand Down Expand Up @@ -2116,8 +2107,6 @@ opt_start_loader(State = #state{loader_queue = LoaderQ}) ->
true ->
opt_start_loader(State#state{loader_queue = Rest});
false ->
Stack = try throw(42) catch _:42:S -> S end,
io:fwrite("In opt_start_loader, State: ~p~nStack: ~p~n", [State, Stack]),
Pid = load_and_reply(self(), Worker),
State#state{loader_pid=[{Pid,Worker}|get_loaders(State)],
loader_queue = Rest}
Expand Down
6 changes: 1 addition & 5 deletions lib/mnesia/src/mnesia_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1143,15 +1143,11 @@ db_put({ext, Alias, Mod}, Tab, Val) ->
db_match_object(Tab, Pat) ->
db_match_object(val({Tab, storage_type}), Tab, Pat).
db_match_object(Storage, Tab, Pat) ->
io:fwrite("db_match_object, Storage: ~p, Tab: ~p, Pat: ~p~n", [Storage, Tab, Pat]),
db_fixtable(Storage, Tab, true),
try
case Storage of
disc_only_copies -> dets:match_object(Tab, Pat);
{ext, Alias, Mod} ->
Res = Mod:select(Alias, Tab, [{Pat, [], ['$_']}]),
io:fwrite("db_match_object, Res: ~p~n", [Res]),
Res;
{ext, Alias, Mod} -> Mod:select(Alias, Tab, [{Pat, [], ['$_']}]);
_ -> ets:match_object(Tab, Pat)
end
after
Expand Down
4 changes: 0 additions & 4 deletions lib/mnesia/src/mnesia_monitor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ mnesia_down(From, Node) ->
cast({mnesia_down, From, Node}).

mktab(Tab, Args) ->
Stack = try throw(42) catch _:42:S -> S end,
io:fwrite("In mktab, Tab: ~p, Args: ~p~nStack: ~p~n", [Tab, Args, Stack]),
unsafe_call({mktab, Tab, Args}).
unsafe_mktab(Tab, Args) ->
unsafe_call({unsafe_mktab, Tab, Args}).
Expand Down Expand Up @@ -412,7 +410,6 @@ handle_call({unsafe_close_log, Name}, _From, State) ->
{reply, ok, State};

handle_call({unsafe_create_external, Tab, Alias, Mod, Cs}, _From, State) ->
io:fwrite("In unsafe_create_external, Tab: ~p, Alias: ~p, Mod: ~p, Cs: ~p~n", [Tab, Alias, Mod, mnesia_schema:cs2list(Cs)]),
case ?CATCH(Mod:create_table(Alias, Tab, mnesia_schema:cs2list(Cs))) of
{'EXIT', ExitReason} ->
{reply, {error, ExitReason}, State};
Expand Down Expand Up @@ -625,7 +622,6 @@ process_q(State = #state{mq=[{call,From,Msg}|R]}) ->
%% Returns: any (ignored by gen_server)
%%----------------------------------------------------------------------
terminate(Reason, State) ->
io:fwrite("Mnesia monitor terminate, Reason: ~p, State: ~p~n", [Reason, State]),
terminate_proc(?MODULE, Reason, State).

%%----------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion lib/mnesia/src/mnesia_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,6 @@ do_multi_create_table(TabDef) ->

do_create_table(TabDef) when is_list(TabDef) ->
Cs = api_list2cs(TabDef),
io:fwrite("do_create_table, TabDef: ~p~nCs: ~p~n", [TabDef, Cs]),
case Cs#cstruct.frag_properties of
[] ->
do_create_table_1(Cs);
Expand Down
17 changes: 0 additions & 17 deletions lib/mnesia/src/mnesia_tm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,18 @@ init(Parent) ->
%% Initialize the schema
IgnoreFallback = mnesia_monitor:get_env(ignore_fallback_at_startup),
mnesia_bup:tm_fallback_start(IgnoreFallback),
true = (ets:whereis(table) =:= undefined),
mnesia_schema:init(IgnoreFallback),
true = (ets:whereis(table) =:= undefined),

%% Handshake and initialize transaction recovery
mnesia_recover:init(),
true = (ets:whereis(table) =:= undefined),
Early = mnesia_monitor:init(),
true = (ets:whereis(table) =:= undefined),
AllOthers = mnesia_lib:uniq(Early ++ mnesia_lib:all_nodes()) -- [node()],
true = (ets:whereis(table) =:= undefined),
set(original_nodes, AllOthers),
mnesia_recover:connect_nodes(AllOthers),
true = (ets:whereis(table) =:= undefined),

%% Recover transactions, may wait for decision
case mnesia_monitor:use_dir() of
true ->
true = (ets:whereis(table) =:= undefined),
P = mnesia_dumper:opt_dump_log(startup), % previous log
L = mnesia_dumper:opt_dump_log(startup), % latest log
Msg = "Initial dump of log during startup: ~p~n",
Expand All @@ -118,11 +111,8 @@ init(Parent) ->
end,

mnesia_schema:purge_tmp_files(),
true = (ets:whereis(table) =:= undefined),
mnesia_recover:next_garb(),
true = (ets:whereis(table) =:= undefined),
mnesia_recover:next_check_overload(),
true = (ets:whereis(table) =:= undefined),

?eval_debug_fun({?MODULE, init}, [{nodes, AllOthers}]),

Expand Down Expand Up @@ -873,10 +863,8 @@ insert_objs([], _Tab) ->
ok.

execute_transaction(Fun, Args, Factor, Retries, Type) ->
io:fwrite("execute_transaction, Fun: ~p, Args: ~p, Factor: ~p, Retries: ~p, Type: ~p~n", [Fun, Args, Factor, Retries, Type]),
try apply_fun(Fun, Args, Type) of
{atomic, Value} ->
io:fwrite("Res: {atomic, ~p}~n", [Value]),
mnesia_lib:incr_counter(trans_commits),
erase(mnesia_activity_state),
%% no need to clear locks, already done by commit ...
Expand All @@ -885,21 +873,16 @@ execute_transaction(Fun, Args, Factor, Retries, Type) ->
?SAFE(unlink(whereis(?MODULE))),
{atomic, Value};
{do_abort, Reason} ->
io:fwrite("Res: {do_abort, ~p}~n", [Reason]),
check_exit(Fun, Args, Factor, Retries, {aborted, Reason}, Type);
{nested_atomic, Value} ->
io:fwrite("Res: {nested_atomic, ~p}~n", [Value]),
mnesia_lib:incr_counter(trans_commits),
{atomic, Value}
catch throw:Value -> %% User called throw
io:fwrite("Catch: throw : ~p~n", [Value]),
Reason = {aborted, {throw, Value}},
return_abort(Fun, Args, Reason);
error:Reason:ST ->
io:fwrite("Catch: error : ~p : ~p~n", [Reason, ST]),
check_exit(Fun, Args, Factor, Retries, {Reason,ST}, Type);
_:Reason ->
io:fwrite("Catch: _ : ~p~n", [Reason]),
check_exit(Fun, Args, Factor, Retries, Reason, Type)
end.

Expand Down
29 changes: 3 additions & 26 deletions lib/mnesia/test/ext_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ create_table(ext_disc_only_copies, Tag={_Tab, retainer, {ChkPNumber, Node}}, _Op
ok.

delete_table(ext_ram_copies, Tab) ->
Stack = try throw(42) catch _:42:S -> S end,
io:fwrite("In delete_table, Tab: ~p~nStack: ~p~n", [tab_to_list(Tab), Stack]),
try
ets:delete(mnesia_lib:val({?MODULE, Tab})),
mnesia_lib:unset({?MODULE, Tab}),
Expand All @@ -189,10 +187,7 @@ delete_table(ext_ram_copies, Tab) ->
ok
end;
delete_table(ext_disc_only_copies, Tab) ->
Stack = try throw(42) catch _:42:S -> S end,
io:fwrite("In delete_table, Tab: ~p~nStack: ~p~n", [tab_to_list(Tab), Stack]),
try
ok = dets:close(mnesia_lib:val({?MODULE, Tab})),
file:delete(tab_to_filename(Tab)),
mnesia_lib:unset({?MODULE, Tab}),
ok
Expand Down Expand Up @@ -247,13 +242,7 @@ fixtable(ext_ram_copies, Tab, Bool) ->
ets:safe_fixtable(mnesia_lib:val({?MODULE, Tab}), Bool);
fixtable(ext_disc_only_copies, Tab, Bool) ->
?DBG({Tab,Bool}),
io:fwrite("Val: ~p~n", [mnesia_lib:val({?MODULE, Tab})]),
try
dets:safe_fixtable(mnesia_lib:val({?MODULE, Tab}), Bool)
catch C : R : S ->
io:fwrite("fixtable, ~p : ~p : ~p~n", [C, R, S]),
erlang:raise(C, R, S)
end.
dets:safe_fixtable(mnesia_lib:val({?MODULE, Tab}), Bool).

info(ext_ram_copies, Tab, Type) ->
?DBG({Tab,Type}),
Expand Down Expand Up @@ -344,13 +333,8 @@ select({ext_ram_copies, C}) -> ets:select(C);
select({ext_disc_only_copies, C}) -> dets:select(C).

select(Alias, Tab, Ms) ->
try
Res = select(Alias, Tab, Ms, 100000),
select_1(Alias, Res)
catch C : R : S ->
io:fwrite("select, ~p : ~p : ~p~n", [C, R, S]),
erlang:raise(C, R, S)
end.
select_1(Alias, Res).

select_1(_Alias, '$end_of_table') -> [];
select_1(ext_ram_copies, {Acc, C}) ->
Expand All @@ -369,14 +353,7 @@ select_1(ext_disc_only_copies, {Acc, C}) ->
select(ext_ram_copies, Tab, Ms, Limit) when is_integer(Limit); Limit =:= infinity ->
ets:select(mnesia_lib:val({?MODULE, Tab}), Ms, Limit);
select(ext_disc_only_copies, Tab, Ms, Limit) when is_integer(Limit); Limit =:= infinity ->
try
io:fwrite("select, Tab: ~p, Ms: ~p, Limit: ~p, Val: ~p~n", [tab_to_list(Tab), Ms, Limit, catch mnesia_lib:val({?MODULE, Tab})]),
Res = dets:select(mnesia_lib:val({?MODULE, Tab}), Ms, Limit),
io:fwrite("select, Tab: ~p, Ms: ~p, Limit: ~p, Val: ~p~nRes: ~p~n", [tab_to_list(Tab), Ms, Limit, mnesia_lib:val({?MODULE, Tab}), Res]),
Res
catch C : R : S ->
io:fwrite("catch select, Tab: ~p, Ms: ~p, Limit: ~p, Val: ~p~n", [tab_to_list(Tab), Ms, Limit, mnesia_lib:val({?MODULE, Tab})])
end.
dets:select(mnesia_lib:val({?MODULE, Tab}), Ms, Limit).

repair_continuation(Cont, Ms) ->
case element(1, Cont) of
Expand Down
2 changes: 0 additions & 2 deletions lib/mnesia/test/mnesia_external_backend_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ backup_and_restore_fails_with_external_backend(Config) when is_list(Config) ->

?match(ok, load_backup("bup1.BUP")),
Expected1 = sets:from_list(Data1),
Res = mnesia:dirty_match_object(table, #some_rec{_ = '_'}),
io:fwrite("backup_and_restore_fails_with_external_backend, Res: ~p~n", [Res]),
?match(Expected1, sets:from_list(mnesia:dirty_match_object(table, #some_rec{_ = '_'}))).
% [#some_rec{some_id = b, some_int = 2, some_string = "2"}] = mnesia:dirty_index_read(table, 2, #some_rec.some_int),

Expand Down

0 comments on commit b99bf9a

Please sign in to comment.