| Module | SeamlessDatabasePool |
| In: |
lib/seamless_database_pool/connection_statistics.rb
lib/seamless_database_pool/controller_filter.rb lib/seamless_database_pool/railtie.rb lib/seamless_database_pool.rb |
This module allows setting the read pool connection type. Generally you will use one of
- use_random_read_connection - use_persistent_read_connection - use_master_connection
Each of these methods can take an optional block. If they are called with a block, they will set the read connection type only within the block. Otherwise they will set the default read connection type. If none is ever called, the read connection type will be :master.
| ADAPTER_TO_CLASS_NAME_MAP | = | {"sqlite" => "SQLite", "sqlite3" => "SQLite3", "postgresql" => "PostgreSQL"} | Adapter name to class name map. This exists because there isn‘t an obvious way to translate things like sqlite3 to SQLite3. The adapters that ship with ActiveRecord are defined here. If you use an adapter that doesn‘t translate directly to camel case, then add the mapping here in an initializer. | |
| READ_CONNECTION_METHODS | = | [:master, :persistent, :random] |
Get the connection adapter class for an adapter name. The class will be loaded from ActiveRecord::ConnectionAdapters::NameAdapter where Name is the camelized version of the name. If the adapter class does not fit this pattern (i.e. sqlite3 => SQLite3Adapter), then add the mapping to the ADAPTER_TO_CLASS_NAME_MAP Hash.
Pull out the master configuration for compatibility with such things as the Rails’ rake db:* tasks which only support known adapters.
Get the read only connection type currently in use. Will be one of :master, :random, or :persistent.
This method is provided as a way to change the persistent connection when it fails and a new one is substituted.
Call this method to use the master connection for all subsequent select statements. This method is most useful when you are doing lots of updates since it guarantees consistency if you do a select immediately after an update or insert.
The master connection will also be used for selects inside any transaction blocks. It will also be used if you pass :readonly => false to any ActiveRecord.find method.
Call this method to pick a random connection from the read pool and use it for all subsequent select statements. This provides consistency from one select statement to the next. This method should always be called with a block otherwise you can end up with an imbalanced read pool. This method is best if you have lots of processes which have a relatively few select statements or a slow replication mechanism. Generally this is the best method to use for web applications.
Call this method to use a random connection from the read pool for every select statement. This method is good if your replication is very fast. Otherwise there is a chance you could get inconsistent results from one request to the next. This can result in mysterious failures if your code selects a value in one statement and then uses in another statement. You can wind up trying to use a value from one server that hasn‘t been replicated to another one yet. This method is best if you have few processes which generate a lot of queries and you have fast replication.