<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sat, Aug 22, 2015 at 4:37 AM jim rosenblum <<a href="mailto:jim.rosenblum@gmail.com">jim.rosenblum@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Dear List<div><div><div><br></div><div>So, now to my questions:</div><div>1. If I am trying to transactionally protect this sequence table, do I need to use sync_transaction or will async_transaction work. I don't understand what an ACID transaction means when there are more than 1 node and a transaction context which is async. If two Puts are happening on two different nodes, will one block until the other completes EVEN when in async mode?</div></div></div></div></blockquote><div><br></div><div>In the normal case async should be fine, if you do not mix transactions and dirty operations, and do not cause an overload on mnesia_tm.</div><div><br></div><div>In the async case a message to commit the transaction is broadcasted,</div><div>and when one reply is received the transaction returns to user code.</div><div>I.e. the transaction does not (as in the sync case) wait on every node to return a result, which is ok since no other transaction can get a write-lock on that record anyway until all nodes have commited the data and released the lock.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>2. is the magnitude of the performance hit seem "normal"?</div></div></div></div></blockquote><div><br></div><div>The difference between dirty and transaction are huge, dirty is</div><div>a couple of ets read and ets write and a message send if remote table.</div><div><br></div><div>Transactions grabs locks, for write on every involved node so you have communication internally and over the network.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>3. Is there a better way to achieve what I am looking for then the above?</div><div><br></div><div><br></div><div>Thanks very much... and some code if it helps...</div><div><br></div><div><br></div><div><div>put(Key, Value, SeqNo) -></div><div> F = fun() -></div><div><span style="white-space:pre-wrap"> </span>case mnesia:wread(seq, global) of</div><div><span style="white-space:pre-wrap"> </span> [] -></div><div><span style="white-space:pre-wrap"> </span>simple_put(Key, Value),</div><div><span style="white-space:pre-wrap"> </span>mnesia:write(#seq{key=global, value = SeqNo});</div><div><span style="white-space:pre-wrap"> </span> [#seq{value = Old}=S] when SeqNo > Old -></div><div><span style="white-space:pre-wrap"> </span>simple_put(Key, Value),</div><div><span style="white-space:pre-wrap"> </span>mnesia:write(S#seq{value = SeqNo});</div><div><span style="white-space:pre-wrap"> </span> [#seq{value = Old}] -></div><div><span style="white-space:pre-wrap"> </span>lager:warning("~p: out of order put. Map: ~p, Old: ~p, New: ~p.", </div><div><span style="white-space:pre-wrap"> </span> [?MODULE, Old, SeqNo]),</div><div><span style="white-space:pre-wrap"> </span>{out_of_seq, {put, Key, Old, SeqNo}}</div><div><span style="white-space:pre-wrap"> </span>end</div><div><span style="white-space:pre-wrap"> </span>end,</div><div> case mnesia:sync_transaction(F) of</div><div><span style="white-space:pre-wrap"> </span>{atomic, {out_of_seq, _}} = R -></div><div><span style="white-space:pre-wrap"> </span> R;</div><div><span style="white-space:pre-wrap"> </span>{atomic, Result} -></div><div><span style="white-space:pre-wrap"> </span> Result;</div><div><span style="white-space:pre-wrap"> </span>{aborted, Reason} -></div><div><span style="white-space:pre-wrap"> </span> {error, Reason}</div></div><div> end.</div><div><br></div><div><br></div><div><br></div><div><br></div><div>e</div></div></div></div>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div></div>