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):
def bankOperation():
account = store.find(BankAccount,BankAccount.id == 1).one()
if account == None:
return
#Simulate some processing
waittime = random.random()*4
time.sleep(waittime)
account.value = account.value + 100
store.flush()
store.commit()
==> If I have more than one thread executing that code data become
inconsistent.
The better way I found to do it is something which i believe is not elegant
and not efficient :
def bankOperation():
store.execute("LOCK TABLE bankaccount WRITE")
account = store.find(BankAccount,BankAccount.id == 1).one()
if account == None:
store.execute("UNLOCK TABLES")
return
#Simulate some processing
waittime = random.random()*4
time.sleep(waittime)
account.value = account.value + 100
store.flush()
store.commit()
store.execute("UNLOCK TABLES")
Any help would be greatly appreciated.
Lucas.
--
storm mailing list
[email protected]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/storm