<div dir="ltr">Hi,<br>thanks for you answer, i&#39;m sorry I forgot to notice that my
store object is retrieved from an helper function which handle one
store instance by thread :<br><br>Database = create_database(&quot;mysql://&quot;+<div dir="ltr">ServerConfig.dbUser+&quot;:&quot;+ServerConfig.dbPassword+&quot;@&quot;+ServerConfig.dbHost+&quot;/&quot;+ServerConfig.dbName)<br>

LocalStoreHolder = threading.local()<br><br><br>def GetStore():<br>&nbsp;&nbsp;&nbsp; global LocalStoreHolder<br>&nbsp;&nbsp;&nbsp; global Database<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; if (not hasattr(LocalStoreHolder,&quot;store&quot;)):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LocalStoreHolder.store = Store(Database)<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; log.msg(&quot;Returning store instance :%s for thread : %s&quot;%(LocalStoreHolder.store,threading.currentThread().getName()))<br><br>&nbsp;&nbsp;&nbsp; return LocalStoreHolder.store<br><br>The
problem I think is there is no lock put on the selected row after the
first thread has read it - On Mysql it&#39;is handled with running the
query with &quot;SELECT ... FOR UPDATE&quot;&nbsp; or &quot;SELECT ... LOCK IN SHARE MODE&quot;<br>
<br>Any idea on how to make storm using this behaviour ?<br><br>Thanks</div><br><br><div class="gmail_quote">2008/9/4 Jamu Kakar <span dir="ltr">&lt;<a href="mailto:jkakar@kakar.ca">jkakar@kakar.ca</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<div class="Ih2E3d"><br>
<br>
NeedBenzyn NeedBenzyn wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I&#39;d like to know what would be the proper way in storm to execute that kind of code on a multithreaded server (acessing MySql server InnoDb tables):<br>
<br>
 &nbsp; &nbsp;def bankOperation():<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;account = store.find(BankAccount,BankAccount.id == 1).one()<br>
 &nbsp; &nbsp; &nbsp; &nbsp;if account == None:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;#Simulate some processing<br>
 &nbsp; &nbsp; &nbsp; &nbsp;waittime = random.random()*4<br>
 &nbsp; &nbsp; &nbsp; &nbsp;time.sleep(waittime)<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;account.value = account.value + 100<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;store.flush() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;store.commit()<br>
<br>
==&gt; If I have more than one thread executing that code data become inconsistent.<br>
</blockquote>
<br></div>
You need to make sure you use one Store per-thread. &nbsp;Something like<br>
this (untested) code should work:<br>
<br>
def bank_operation(store, id):<br>
 &nbsp; &nbsp;account = store.find(BankAccount, BankAccount.id == id).one()<br>
 &nbsp; &nbsp;if account:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;account.value += 100<br>
<br>
<br>
def run_thread():<br>
 &nbsp; &nbsp;store = Store(create_database(...))<br>
 &nbsp; &nbsp;try:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;bank_operation(store, 1)<br>
 &nbsp; &nbsp;except:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;store.rollback()<br>
 &nbsp; &nbsp; &nbsp; &nbsp;raise<br>
 &nbsp; &nbsp;else:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;store.commit()<br>
<br>
Storm automatically uses transactions, so you shouldn&#39;t have to<br>
worry about locking tables and such (though this may not be true for<br>
SQLite).<br>
<br>
Thanks,<br><font color="#888888">
J.<br>
</font></blockquote></div><br></div>