[storm] Consistent multithreaded operations

James Henstridge james at jamesh.id.au
Sat Sep 6 00:46:32 BST 2008


On Sat, Sep 6, 2008 at 1:26 AM, Raphael Saint-Pierre
<rsaintpi at matrox.com> wrote:
>> Database = create_database("mysql://"+
>>
> ServerConfig.dbUser+":"+ServerConfig.dbPassword+"@"+ServerConfig.dbHost+"/"+
> ServerConfig.dbName)
>> LocalStoreHolder = threading.local()
>
>
>> def GetStore():
>>     global LocalStoreHolder
>>     global Database
>
>>     if (not hasattr(LocalStoreHolder,"store")):
>        LocalStoreHolder.store = Store(Database)
>
>>     log.msg("Returning store instance :%s for thread :
> %s"%(LocalStoreHolder.store,threading.currentThread().getName()))
>
>>     return LocalStoreHolder.store
>
>> _________________________________
>
> In this case, although you have one store per thread, you still share one
> connection to the database. Transactions are handled on a per-connection
> basis, therefore you should create one connection for each thread and then
> associate it to a new store, as Jamu suggested.

That is not correct.  The database object returned by
create_database() is a connection factory.rather than a connection
itself.  So each of the stores has its own connection.

James.



More information about the storm mailing list