On Feb 27, 4:37 pm, Myron Marston <[email protected]> wrote:
> > Awesome :).  I plan to play with this later today.  I'll be sure to
> > send my feedback.
>
> I've tried it out and it works as advertised :).  The one thing that
> confused me a bit was this note [1] from the docs:
>
> # Note that this extension only works with the sharded threaded
> connection
> # pool.  If you are using the sharded single connection pool, you need
> # to switch to the sharded threaded connection pool before using this
> # extension.
>
> It confused me a bit because I hadn't given previous thought to
> picking a connection pool.  I wasn't sure which one I was using, or
> how to go about ensuring I was using the sharded threaded connection
> pool.  I dug around in the sources a bit and it looks like it uses a
> threaded connection pool unless you pass :single_threaded.  To use a
> sharded connection pool, it looks like I have to pass a `:servers`
> option (even if it's just an empty hash).

That's correct.  I should probably add some documentation to
http://sequel.rubyforge.org/rdoc/files/doc/sharding_rdoc.html that
points people to the arbitrary_servers extensions and some guidelines
for use (like not using :single_threaded and passing in an
empty :servers hash to enable the sharded connection pool).

> Putting it all together, this is what my connection setup is now:
>
> https://gist.github.com/1928153
>
> Seems to be working like a charm!

That all looks good except that :default should be inside the :servers
hash (which is why it isn't being called in your example code):

DB = Sequel.connect(adapter: 'mysql2', user: 'root', servers:
{default: lambda { raise NoCurrentShardError }})

> One final thing: I specified a default proc that raises an error, but
> it doesn't seem to ever get used, as far as I can tell.  When I try to
> access the DB (without first wrapping it in `with_server`), then I get
> an error form sequel:
>
> DB[:users].count
> => Sequel::DatabaseError: Mysql2::Error: No database selected
>         from /Users/myron/.rvm/gems/ruby-1.9.3-p125@vanguard/bundler/gems/
> sequel-f1e2f3754d14/lib/sequel/adapters/mysql2.rb:85:in `query'
>         from /Users/myron/.rvm/gems/ruby-1.9.3-p125@vanguard/bundler/gems/
> sequel-f1e2f3754d14/lib/sequel/adapters/mysql2.rb:85:in `block in
> _execute'
>
> This is fine (desirable, even). Is the default proc still needed?  If
> so, what are the conditions that would trigger its use?

The :default proc will ensure an error is raised without actually
attempting to connect to the database.  Without it, the results you
get are dependent on numerous factors.  If the default connection
string is valid, it will use that.  In your case, with mysql, you can
connect, but the query raises an error (it's possible other queries
will work).  If you want to be sure an error is raised, you should use
the :default proc inside the :servers hash.

I'm glad it is working for you. Thanks for testing it and providing
feedback.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
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