[erlang-questions] increment an int in mysql vs. mnesia

Hynek Vychodil vychodil.hynek@REDACTED
Mon Dec 3 10:23:01 CET 2007


see mnesia:dirty_update_counter

On 12/3/07, Andrew Arrow <oneone@REDACTED> wrote:
> in mysql I can say:
>
>   update company set sales=sales+1 where company_id=123
>
> and it will safely increment the value of sales by 1.
>
> In mnesia I have to first read the value, then write the value+1.
>
>   [Row] = mnesia:read({company, 123})
>   %% make Row1 = Row but with sales = sales + 1
>   mnesia:write(Row1)
>   mnesia:transaction(The_above_fun)
>
> But it's possible for two processes at the same time to write back the
> same value for sales and miss one increment.
> i.e. processA reads 100 for sales, processB also reads 100, they each
> write back 101 but it should be 102.
>
> Is there a better way to do this?  Thanks.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>


-- 
--Hynek (Pichi) Vychodil



More information about the erlang-questions mailing list