mysql_replication_adapter 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.txt CHANGED
@@ -1,3 +1,70 @@
1
- README for mysql_replication_adapter
2
- ====================================
1
+ MysqlReplicationAdapter
2
+ =======================
3
3
 
4
+ MysqlReplicationAdapter is an ActiveRecord database adapter that is designed to help applications connect to a single write master database and several read-only slave databases in a MySQL master-slave replication setup. This should allow much easier scaling of read volume by allowing read-only queries to be directed to a slave, leaving the master more room to breathe.
5
+
6
+ Configuration
7
+ ================
8
+ 1. Install the gem.
9
+ -------------------
10
+ Download from Rubyforge or "gem install mysql_replication_adapter".
11
+
12
+ 2. Edit your environment.rb.
13
+ -------------------
14
+ Because of the way that Rails loads database adapters, you must put the "require mysql_replication_adapter" *above* the Initializer block. Otherwise, it won't work.
15
+
16
+ 3. Add slaves to your database.yml.
17
+ -------------------
18
+ Slaves are configured on a by-environment basis, so pick any of your existing environments (development, production, etc.). Change the "driver" entry to "mysql_replication". Then, add a clones section like the one seen below.
19
+
20
+ development:
21
+ host: masterdb
22
+ port: 3306
23
+ username: writeuser
24
+ password: yourwritepassword
25
+ database: yourapp_development
26
+ clones:
27
+ - host: slavedb1
28
+ port: 3306
29
+ username: user
30
+ password: yourpassword
31
+ database: database
32
+ - host: slavedb2
33
+ port: 3306
34
+ username: user
35
+ password: yourpassword
36
+ database: database
37
+
38
+ And so on. Add as many slaves as you'd like. There are no built-in limits.
39
+
40
+ And that's it. It's configured now.
41
+
42
+ Usage
43
+ ================
44
+ There are three ways to make use of the MysqlReplicationAdapter's slave-balancing capabilities. The simplest way is to pass a new option to ActiveRecord::Base#find. The option is called :use_slave, and it should => true when you want to send the query to a slave. For instance:
45
+
46
+ class Author < ActiveRecord::Base; end;
47
+
48
+ Author.find(:all, :use_slave => true)
49
+
50
+ This will choose a random slave and send it the query.
51
+
52
+ The other way to slave balance a query is to use block syntax. The ActiveRecord::Base#connection object now has a method called load_balance_query that requires a block. It will select a slave connection behind the scenes, and then any read queries you execute will be sent to that database for the duration of the block. For example:
53
+
54
+ ActiveRecord::Base.connection.load_balance_query do
55
+ Author.find(:all) # will be load balanced, even though not specified to find
56
+ end
57
+
58
+ Note: if you use the block syntax and cause a write query to be generated somehow, then you will receive an exception. The adapter explicitly stops you from writing to any database but the master.
59
+
60
+ Finally, I'm sure there are those of you saying, "But I use find_by_sql and that doesn't take an options hash!" Well, good news! There is now an optional second parameter to find_by_sql. If you pass true as that second parameter, it will select a random database and load balance that individual query. Snazzy! Example:
61
+
62
+ Author.find_by_sql("SELECT * FROM authors WHERE name = 'bryan';", true) # will be load balanced
63
+
64
+ Limitations
65
+ ================
66
+ - MysqlReplicationAdapter has no idea of slave database currency. That is, if for some reason your slave dbs are way behind, and you send a query to a slave database, you could get back some out of date data. It's up to you to deal with this. My suggestion is to only load balance queries that you know you can get out-of-date data from and not be hurt. So, stick to authenticating people against the master database.
67
+
68
+ - MysqlReplicationAdapter doesn't do any sort of clever load balancing, it just selects a random slave from its set of slaves.
69
+
70
+ - MysqlReplicationAdapter doesn't partition your writes across multiple databases, and it isn't going to.
@@ -2,7 +2,7 @@ module MysqlReplicationAdapter #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>mysql_replication_adapter</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/mysql_replication_adapter"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/mysql_replication_adapter" class="numbers">0.1.0</a>
36
+ <a href="http://rubyforge.org/projects/mysql_replication_adapter" class="numbers">0.1.1</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;mysql_replication_adapter&#8217;</h1>
39
39
 
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: mysql_replication_adapter
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
6
+ version: 0.1.1
7
7
  date: 2007-07-23 00:00:00 -07:00
8
8
  summary: An ActiveRecord database adapter that allows you to specify a single write master and multiple read-only slaves.
9
9
  require_paths: