0
= activerecord_dbslayer_adapter
0
-
FIX (describe your package)0
+
An ActiveRecord adapter for using the DBSlayer proxy/pooling layer. This allows you to proxy and pool connections to the MySQL backend without worrying about scaling up the front instances more than MySQL is configured to handle (the dreaded Too Many Connections error). Of course, you can also reconfigure master/slave instances on the fly in DBSlayer without having to reconfigure or restart your Rails applications. 0
+This adapter is really just a judicious subclassing of functionality in the MySQL adapter, so the documented methods might seem very sparse (I only have to override what's changed). Mainly, I swapped it out to execute queries as JSON-over-HTTP calls to DBSlayer rather than using the MySQL connection library.
0
+DBSlayer is a stateless pooling layer. This allows it to easily scale (why do you think HTTP is stateless?), but there are certain database techniques that will have to be abandoned or modified if you use it. The main problem is that each MySQL statement may execute on a different connection (and sometimes on different servers if you've set up transparent slave pooling), so you can not assume the context of one statement is available to the next.
0
+This becomes a problem with transactions. Although DBSlayer can support transactions if you use semicolons to include them all as one statement like
0
+ BEGIN TRANSACTION; more SQL; COMMIT TRANSACTION
0
+There is no readily apparent way to do that via ActiveRecord's block construction (all the adapter has are begin_transaction, commit_transaction methods). So for the moment, transactions do not throw errors but they don't actually use SQL transactions either. Sorry about that. In addition, disabling referential integrity for a connection is not allowed.
0
+The biggest problem is that Rails sets a connection variable for all MySQL connections in order to fix an error selecting null IDs (http://dev.rubyonrails.org/ticket/6778). Since DBSlayer is stateless, this fix doesn't work, but there unfortunately also doesn't seem to be a database or server setting you can alter instead. As a result, the following types of queries WILL return unexpected results when using the DBSlayer adapter:
0
+ Restaurant.find(:all, :conditions => 'id IS NULL')
0
+The problem only occurs when searching for null autoincrement primary key columns (not other columns). With the regular MySQL adapter, this would return records with an id value (normally errors). With the DBSlayer adapter, it returns the last inserted item into the table (this is the default MySQL behavior). Luckily, this is not a common idiom in Rails, but you should be aware if you attempt to use it for finding errors in your tables.
0
-* FIX (list of features or problems)
0
-
FIX (code sample of usage)0
+All of the other normal database setting like the MySQL server, username, password, etc. are specified in the dbslayer daemon's configuration.
0
-* FIX (list of requirements)
0
+* A running DBSlayer instance
0
-* FIX (sudo gem install, anything else)
0
+* gem install activerecord-dbslayer-adapter
0
+* in your rails project, add the following line at the end of config/environment.rb
0
+ Rails::Initializer.run do |config|
0
+ require 'activerecord-dbslayer-adapter'
0
Permission is hereby granted, free of charge, to any person obtaining
0
a copy of this software and associated documentation files (the
Comments
No one has commented yet.