Inadvertently intercepts Mnesia transactional attempts with attempts / capture of results in all kinds of weirdness

So, I had all kinds of problems with CRUD operations on recordsets in one transaction. This led me to post 2 questions here, Problem and MoreTrouble . However , I think that those problems were created as follows: in my transactions, I included my mnesia: writes, reads, etc. into try / catch blocks that everyone caught, including mnesia aborted transactions as part of its deadlock avoidance algorithm. I.e.

insert(Key, Value) -> F = fun() -> case sc_store:lookup(Key) of {ok, _Value} -> sc_store:replace(Key, Value); {error, not_found} -> sc_store:insert(Key,Value) end end, try case mnesia:transaction(F) of {atomic, Result} -> Result; {aborted, Reason} -> ... end catch Error:Reason -> ... end 

end

sc: lookup / 1, for example, looked like this:

 lookup(Key) -> try case mnesia:read(key_to_value, Key) of [#key_to_value{type = Type, scope = Scope, value = Value}] -> {ok, {Value, Type, Scope}}; [] -> {error, not_found} end catch _Err:Reason -> {error, Reason} end. 

I think I must have "hooked" / caught the mnesia deadlock avoidance algorithm instead of letting him try again.

Is it possible? If yes, then it (& ^ & thechch-for beginners like me. If not, any ideas why this code caused so many problems for me, but removing try / catch from mnesia: reading, etc. functions cleared everything my problems?

+2
source share
1 answer

Yes, I'm not sure if this is properly documented anywhere, but you should not mask exceptions in mnesia operations. If you do, it looks like mnesia, how your transaction pleasure worked as intended, although some operations did not actually work at all.

+4
source

Source: https://habr.com/ru/post/900372/


All Articles