<div dir="ltr">Hi,<br>thanks for you answer, i'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("mysql://"+<div dir="ltr">ServerConfig.dbUser+":"+ServerConfig.dbPassword+"@"+ServerConfig.dbHost+"/"+ServerConfig.dbName)<br>
LocalStoreHolder = threading.local()<br><br><br>def GetStore():<br> global LocalStoreHolder<br> global Database<br> <br> if (not hasattr(LocalStoreHolder,"store")):<br> LocalStoreHolder.store = Store(Database)<br>
<br> log.msg("Returning store instance :%s for thread : %s"%(LocalStoreHolder.store,threading.currentThread().getName()))<br><br> 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'is handled with running the
query with "SELECT ... FOR UPDATE" or "SELECT ... LOCK IN SHARE MODE"<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"><<a href="mailto:jkakar@kakar.ca">jkakar@kakar.ca</a>></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'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>
def bankOperation():<br>
<br>
account = store.find(BankAccount,BankAccount.id == 1).one()<br>
if account == None:<br>
return<br>
<br>
#Simulate some processing<br>
waittime = random.random()*4<br>
time.sleep(waittime)<br>
<br>
account.value = account.value + 100<br>
<br>
store.flush() store.commit()<br>
<br>
==> 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. Something like<br>
this (untested) code should work:<br>
<br>
def bank_operation(store, id):<br>
account = store.find(BankAccount, BankAccount.id == id).one()<br>
if account:<br>
account.value += 100<br>
<br>
<br>
def run_thread():<br>
store = Store(create_database(...))<br>
try:<br>
bank_operation(store, 1)<br>
except:<br>
store.rollback()<br>
raise<br>
else:<br>
store.commit()<br>
<br>
Storm automatically uses transactions, so you shouldn'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>