[storm] Consistent multithreaded operations

NeedBenzyn NeedBenzyn needbenzyn at gmail.com
Thu Sep 4 17:18:16 BST 2008


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/storm/attachments/20080904/018d64f7/attachment.htm 


More information about the storm mailing list