[erlang-questions] Mnesia: Error on insert object with same key in Set

Tristan Sloughter tristan.sloughter@REDACTED
Mon Oct 17 16:46:03 CEST 2011


Oh great, thanks!

On Mon, Oct 17, 2011 at 2:00 AM, Ulf Wiger
<ulf.wiger@REDACTED>wrote:

>
> On 17 Oct 2011, at 08:45, Kostis Sagonas wrote:
>
> > On 10/17/11 09:40, Dan Gudmundsson wrote:
> >> This should be fixed now and thus safe to use now.
> >
> > But doesn't the code below have an obvious race condition?
> >
> > Kostis
>
> Kostis,
>
> Those functions in the mnesia API only work when called from within a
> transaction, so the race condition is managed through implicit locking.
>
> BR,
> Ulf
>
>
> >
> >> On Sun, Oct 16, 2011 at 11:29 PM, Tristan Sloughter
> >> <tristan.sloughter@REDACTED>  wrote:
> >>> I wanted to make sure there was still no way to tell Mnesia to return
> an
> >>> error if it is given a record to write that has the same key as an
> object
> >>> already stored in the table.
> >>> Reading through the docs it looks like there is no way through
> configuration
> >>> but you must simply read and then write if its not there, like I found
> when
> >>> this was asked in 2004 on this mailing list:
> >>> insert(K,V) ->
> >>>   fun() ->
> >>>   case mnesia:wread(K) of
> >>>     [Exist] ->  {abort, Exist};
> >>>     _ ->  mnesia:write(V)
> >>>   end
> >>>   end.
> >>> Which doesn't seem safe, as Ulf points on in that
> >>> thread:
> http://erlang.org/pipermail/erlang-questions/2004-May/012307.html
> >>> As well as slow.
> >>> So I was hoping maybe in 2011 there is a better way to do this? :)
> >>> Thanks,
> >>> Tristan
> >>> _______________________________________________
> >>> erlang-questions mailing list
> >>> erlang-questions@REDACTED
> >>> http://erlang.org/mailman/listinfo/erlang-questions
> >>>
> >>>
> >> _______________________________________________
> >> erlang-questions mailing list
> >> erlang-questions@REDACTED
> >> http://erlang.org/mailman/listinfo/erlang-questions
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
>
> Ulf Wiger, CTO, Erlang Solutions, Ltd.
> http://erlang-solutions.com
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111017/332d7f90/attachment.htm>


More information about the erlang-questions mailing list