[erlang-questions] Mnesia: Error on insert object with same key in Set
Kostis Sagonas
kostis@REDACTED
Mon Oct 17 08:45:14 CEST 2011
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
> 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
More information about the erlang-questions
mailing list