On Jun 14, 7:00 am, Joe Holt <[EMAIL PROTECTED]> wrote:
> I'm writing a threaded Ruby app and I've determined that some of the
> threads need their own exclusive persistent connection to the
> database. I'm about to patch ConnectionPool to make acquire() public,
> so that I can do this...
>
> Thread.new do
>    db.pool.acquire Thread.current
>    ...
> end
>
> And then taking advantage of the existing logic that ConnectionPool
> has of using the existing connection on subsequent hold() calls. I
> might make release() public so that I can bracket sections of code
> with exclusivity.
>
> Is this reasonable? Is the community interested in this functionality?
> In my case, the reason I need this is that I'm using "LOCK TABLES" in
> MySQL and I can't have the connection re-used or shared by other
> threads while the lock is held.
>
> I'm using sequel 1.5.1. If I were using 2.0 I'd also need to
> set :pool_reuse_connections to :always at init.

Is there a problem with just using a transaction?  Inside a
transaction, you should only be using a single database connection.
I'm not sure well this works unless :pool_reuse_connections=>:always,
though.  If it doesn't work correctly without :always, the connection
pool code should be changed to take into account transactions, and
always yield the connection related to the transaction inside the
transaction.  Admittedly, this isn't something I thought about when
adding the :pool_reuse_connections option, it was added mainly to
prevent MySQL raising an error with "DB[:items].each{|x|
DB[:nodes].each{|y| ...}}".  It might be best to eliminate the option
altogether, and force the MySQL users to use "DB[:items].all{|x|
DB[:nodes].each{|y| ...}}".  As far as I know, the MySQL adapter is
the only one affected.

Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to sequel-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to