Merge pull request #27 from aeternity/uw-accept-repeated-create

Ignore certain mnesia_dumper close_table requests
This commit is contained in:
Ulf Wiger 2022-08-03 09:49:58 +02:00 committed by GitHub
commit d1177b6ad4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 25 deletions

View File

@ -1,11 +1,4 @@
%% -*- erlang-mode -*- %% -*- erlang-mode -*-
case os:getenv("ERLANG_ROCKSDB_OPTS") of
false ->
true = os:putenv("ERLANG_ROCKSDB_OPTS", "-DWITH_BUNDLE_LZ4=ON");
_ ->
%% If manually set, we assume it's throught through
skip
end.
case os:getenv("DEBUG") of case os:getenv("DEBUG") of
"true" -> "true" ->
Opts = proplists:get_value(erl_opts, CONFIG, []), Opts = proplists:get_value(erl_opts, CONFIG, []),

View File

@ -346,14 +346,11 @@ semantics(_Alias, index_fun) -> fun index_f/4;
semantics(_Alias, _) -> undefined. semantics(_Alias, _) -> undefined.
is_index_consistent(Alias, {Tab, index, PosInfo}) -> is_index_consistent(Alias, {Tab, index, PosInfo}) ->
case info(Alias, Tab, {index_consistent, PosInfo}) of mnesia_rocksdb_admin:read_info(Alias, Tab, {index_consistent, PosInfo}, false).
true -> true;
_ -> false
end.
index_is_consistent(_Alias, {Tab, index, PosInfo}, Bool) index_is_consistent(Alias, {Tab, index, PosInfo}, Bool)
when is_boolean(Bool) -> when is_boolean(Bool) ->
mrdb:write_info(Tab, {index_consistent, PosInfo}, Bool). mnesia_rocksdb_admin:write_info(Alias, Tab, {index_consistent, PosInfo}, Bool).
%% PRIVATE FUN %% PRIVATE FUN
@ -454,8 +451,13 @@ close_table(Alias, Tab) ->
error -> error ->
ok; ok;
_ -> _ ->
ok = mnesia_rocksdb_admin:prep_close(Alias, Tab), case get(mnesia_dumper_dets) of
close_table_(Alias, Tab) undefined ->
ok = mnesia_rocksdb_admin:prep_close(Alias, Tab),
close_table_(Alias, Tab);
_ ->
ok
end
end. end.
close_table_(Alias, Tab) -> close_table_(Alias, Tab) ->
@ -798,7 +800,7 @@ handle_call({create_table, Tab, Props}, _From,
exit:{aborted, Error} -> exit:{aborted, Error} ->
{reply, {aborted, Error}, St} {reply, {aborted, Error}, St}
end; end;
handle_call({load_table, _LoadReason, Props}, _From, handle_call({load_table, _LoadReason, Props}, {Pid,_},
#st{alias = Alias, tab = Tab} = St) -> #st{alias = Alias, tab = Tab} = St) ->
{ok, _Ref} = mnesia_rocksdb_admin:load_table(Alias, Tab, Props), {ok, _Ref} = mnesia_rocksdb_admin:load_table(Alias, Tab, Props),
{reply, ok, St#st{status = active}}; {reply, ok, St#st{status = active}};
@ -826,7 +828,7 @@ handle_call({delete, Key}, _From, St) ->
handle_call({match_delete, Pat}, _From, #st{tab = Tab} = St) -> handle_call({match_delete, Pat}, _From, #st{tab = Tab} = St) ->
Res = mrdb:match_delete(get_ref(Tab), Pat), Res = mrdb:match_delete(get_ref(Tab), Pat),
{reply, Res, St}; {reply, Res, St};
handle_call(close_table, _From, #st{alias = Alias, tab = Tab} = St) -> handle_call(close_table, {Pid,_}, #st{alias = Alias, tab = Tab} = St) ->
_ = mnesia_rocksdb_admin:close_table(Alias, Tab), _ = mnesia_rocksdb_admin:close_table(Alias, Tab),
{reply, ok, St#st{status = undefined}}; {reply, ok, St#st{status = undefined}};
handle_call(delete_table, _From, #st{alias = Alias, tab = Tab} = St) -> handle_call(delete_table, _From, #st{alias = Alias, tab = Tab} = St) ->

View File

@ -280,9 +280,12 @@ write_info(Alias, Tab, K, V) ->
write_info_(get_ref({admin, Alias}), Tab, K, V). write_info_(get_ref({admin, Alias}), Tab, K, V).
write_info_(Ref, Tab, K, V) -> write_info_(Ref, Tab, K, V) ->
write_info_encv(Ref, Tab, K, term_to_binary(V)).
write_info_encv(Ref, Tab, K, V) ->
EncK = mnesia_rocksdb_lib:encode_key({info,Tab,K}, sext), EncK = mnesia_rocksdb_lib:encode_key({info,Tab,K}, sext),
maybe_write_standalone_info(Ref, K, V), maybe_write_standalone_info(Ref, K, V),
mrdb:rdb_put(Ref, EncK, term_to_binary(V), []). mrdb:rdb_put(Ref, EncK, V, []).
maybe_write_standalone_info(Ref, K, V) -> maybe_write_standalone_info(Ref, K, V) ->
case Ref of case Ref of
@ -510,12 +513,17 @@ intersection(A, B) ->
-spec handle_req(alias(), req(), backend(), st()) -> gen_server_reply(). -spec handle_req(alias(), req(), backend(), st()) -> gen_server_reply().
handle_req(Alias, {create_table, Name, Props}, Backend, St) -> handle_req(Alias, {create_table, Name, Props}, Backend, St) ->
case create_trec(Alias, Name, Props, Backend, St) of case find_cf(Alias, Name, Backend, St) of
{ok, NewCf} -> {ok, TRec} ->
St1 = update_cf(Alias, Name, NewCf, St), {reply, {ok, TRec}, St};
{reply, {ok, NewCf}, St1}; error ->
{error, _} = Error -> case create_trec(Alias, Name, Props, Backend, St) of
{reply, Error, St} {ok, NewCf} ->
St1 = update_cf(Alias, Name, NewCf, St),
{reply, {ok, NewCf}, St1};
{error, _} = Error ->
{reply, Error, St}
end
end; end;
handle_req(Alias, {load_table, Name, Props}, Backend, St) -> handle_req(Alias, {load_table, Name, Props}, Backend, St) ->
try try
@ -1223,7 +1231,18 @@ load_info_(Res, I, ARef, Tab) ->
DecK = mnesia_rocksdb_lib:decode_key(K), DecK = mnesia_rocksdb_lib:decode_key(K),
case read_info_(ARef, Tab, DecK, undefined) of case read_info_(ARef, Tab, DecK, undefined) of
undefined -> undefined ->
write_info_(ARef, Tab, DecK, V); write_info_encv(ARef, Tab, DecK, V);
<<131,_/binary>> = Value ->
%% Due to a previous bug, info values could be double-encoded with binary_to_term()
try binary_to_term(Value) of
_DecVal ->
%% We haven't been storing erlang-term encoded data as info,
%% so assume this is double-encoded and correct
write_info_encv(ARef, Tab, DecK, Value)
catch
error:_ ->
skip
end;
_ -> _ ->
skip skip
end, end,