More dets-like load/close behavior
This commit is contained in:
parent
296abb23bb
commit
dfc0125800
@ -162,6 +162,7 @@
|
|||||||
, type
|
, type
|
||||||
, status
|
, status
|
||||||
, on_error
|
, on_error
|
||||||
|
, loaders = []
|
||||||
}).
|
}).
|
||||||
|
|
||||||
-type data_tab() :: atom().
|
-type data_tab() :: atom().
|
||||||
@ -795,10 +796,10 @@ 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, loaders = [Pid|St#st.loaders]}};
|
||||||
handle_call({write_info, Key, Value}, _From, #st{tab = Tab} = St) ->
|
handle_call({write_info, Key, Value}, _From, #st{tab = Tab} = St) ->
|
||||||
mrdb:write_info(get_ref(Tab), Key, Value),
|
mrdb:write_info(get_ref(Tab), Key, Value),
|
||||||
{reply, ok, St};
|
{reply, ok, St};
|
||||||
@ -823,9 +824,14 @@ 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, loaders = Ls} = St) ->
|
||||||
_ = mnesia_rocksdb_admin:close_table(Alias, Tab),
|
case Ls -- [Pid] of
|
||||||
{reply, ok, St#st{status = undefined}};
|
[] ->
|
||||||
|
_ = mnesia_rocksdb_admin:close_table(Alias, Tab),
|
||||||
|
{reply, ok, St#st{status = undefined, loaders = []}};
|
||||||
|
Ls1 ->
|
||||||
|
{reply, ok, St#st{loaders = Ls1}}
|
||||||
|
end;
|
||||||
handle_call(delete_table, _From, #st{alias = Alias, tab = Tab} = St) ->
|
handle_call(delete_table, _From, #st{alias = Alias, tab = Tab} = St) ->
|
||||||
ok = mnesia_rocksdb_admin:delete_table(Alias, Tab),
|
ok = mnesia_rocksdb_admin:delete_table(Alias, Tab),
|
||||||
{stop, normal, ok, St#st{status = undefined}}.
|
{stop, normal, ok, St#st{status = undefined}}.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user