<div dir="ltr">Question about mnesia:ets/3 and direct ets calls for mnesia tables.<br><br>In case of lookup (sequence calls from same node as ram replica node), what is the benefit to use mnesia:ets instead of direct ets:lookup call?<br><br>I have single writer to DB (I have one node ram type, other replicas - disk copies just for save data to disk somewhere) and would like do something like this on ram node (sequence pseudo-code):<br><br>......<br>X = receive <br>       NewData#somerecord{id = TransID} -><br>            case <span class="gmail-s1">ets:lookup</span>(Table, TransID) of<br>                 [#somerecord{date = undefined}] = OldData -> <br>                     NewDate = erlang:system_time<span class="gmail-s1">(milli_seconds),</span><br>                     mnesia:dirty<span class="gmail-s1">_write(Old</span>Data#somerecord{date = <span class="gmail-s1">NewDate}), <br>                     {TransID, NewDate};<br>                  [#somerecord{date = Date}] -><br>                      {TransID, Date}<br>                  [] -><br>                       NewDate = erlang:system_time<span class="gmail-s1">(milli_seconds),</span><br>                       mnesia:dirty_write(NewData),<br>                       {TransID, Date}<br>            end<br>        OtherReceive -> ...blabala....<br>end,<br>some_operation_with_x(X).<br></span><div><span class="gmail-s1"><br><br><br>Or I should wrap this stuff to something like this?:<br><br>.....<br>receive<br>        NewData#somerecord{id = TransID} -><br>               mnesia:ets(fun may_update/3, [NewData, Table, TransID]);<br>         </span>       OtherReceive -> ...blabala....</div>end,<br>some_operation_with_x(X).<br><div><span class="gmail-s1"><br>may_update(NewData, Table, TransID) -><br>            case mnesia<span class="gmail-s1">:read</span>(Table, TransID) of<br>                 [#somerecord{date = undefined}] = OldData -> <br>                     NewDate = erlang:system_time<span class="gmail-s1">(milli_seconds),</span><br>                     mnesia:<span class="gmail-s1">write(Old</span>Data#somerecord{date = <span class="gmail-s1">NewDate}), <br>                     {TransID, NewDate};<br>                  [#somerecord{date = Date}] -><br>                      {TransID, Date}<br>                  [] -><br>                       NewDate = erlang:system_time<span class="gmail-s1">(milli_seconds),</span><br>                       mnesia:write(NewData),<br>                       {TransID, Date}<br>            end<br></span>). <br><br><br><br>What is the benefit to wrap it to mnesia:ets?<br><br>Best regards.<br></span><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:12.8px">Oleksii D. Semilietov</span><br></div></div></div>
</div></div>