maria_db_cluster_pool 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,16 @@
1
- == Database Cluster
1
+ # Database Cluster [![Build Status](https://travis-ci.org/renemadsen/maria_db_cluster_pool.png)](https://travis-ci.org/renemadsen/maria_db_cluster_pool)
2
2
 
3
3
  MariaDB Cluster Pool gem is designed for usage with Maria DB Galera Cluster, so this gem will only support a master/master setup
4
4
 
5
- = Configuration
5
+ # Configuration
6
6
 
7
- == The pool configuration
7
+ ## The pool configuration
8
8
 
9
9
  The cluster connections are configured in database.yml using the maria_db_cluster_pool adapter. Any properties you configure for the connection will be inherited by all connections in the pool. In this way, you can configure ports, usernames, etc. once instead of for each connection. One exception is that you can set the pool_adapter property which each connection will inherit as the adapter property. Each connection in the pool uses all the same configuration properties as normal for the adapters.
10
10
 
11
- == Example configuration
11
+ ### Example configuration
12
12
 
13
+ ```ruby
13
14
  development:
14
15
  adapter: maria_db_cluster_pool
15
16
  database: mydb_development
@@ -23,22 +24,27 @@ The cluster connections are configured in database.yml using the maria_db_cluste
23
24
  pool_weight: 1
24
25
  - host: read-db-2.example.com
25
26
  pool_weight: 2
27
+ ```
26
28
 
27
- == Rails 2.3.x
29
+ ## Rails 2.3.x
28
30
 
29
31
  To make rake db:migrate, rake db:seed work, remember to put:
30
32
 
31
- config.gem 'maria_db_cluster_pool'
33
+ ```ruby
34
+ config.gem 'maria_db_cluster_pool'
35
+ ```
32
36
 
33
37
  in the environment.rb
34
38
 
35
- == Known issues:
39
+ ## Known issues:
36
40
 
37
- rake db:test:clone
41
+ ```ruby
42
+ rake db:test:clone
43
+ ```
38
44
 
39
45
  will not work.
40
46
 
41
- == License
47
+ ## License
42
48
 
43
49
  This software is a derived work of https://github.com/bdurand/seamless_database_pool the parts which derives from that codes is copyrighted by Brian Durand
44
50
 
data/Rakefile CHANGED
@@ -11,49 +11,49 @@ begin
11
11
  desc 'Run the unit tests'
12
12
  RSpec::Core::RakeTask.new(:test)
13
13
 
14
- #namespace :test do
15
- # desc "Run all tests including for all database adapters"
16
- # task :all do
17
- # save_val = ENV['TEST_ADAPTERS']
18
- # begin
19
- # ENV['TEST_ADAPTERS'] = YAML.load_file(File.expand_path("../spec/database.yml", __FILE__)).keys.join(' ')
20
- # Rake::Task["test"].execute
21
- # ensure
22
- # ENV['TEST_ADAPTERS'] = save_val
23
- # end
24
- # end
25
- #
26
- # desc "Test all database adapters defined in database.yml or just the one specified in TEST_ADAPTERS"
27
- # task :adapters do
28
- # save_val = ENV['TEST_ADAPTERS']
29
- # begin
30
- # ENV['TEST_ADAPTERS'] ||= YAML.load_file(File.expand_path("../spec/database.yml", __FILE__)).keys.join(' ')
31
- # Rake::Task["test:adapters:specified"].execute
32
- # ensure
33
- # ENV['TEST_ADAPTERS'] = save_val
34
- # end
35
- # end
36
- #
37
- # namespace :adapters do
38
- # desc "Internal task to run database adapter tests"
39
- # RSpec::Core::RakeTask.new(:specified) do |t|
40
- # t.pattern = FileList.new('spec/connection_adapters_spec.rb')
41
- # end
42
- #
43
- # YAML.load_file(File.expand_path("../spec/database.yml", __FILE__)).keys.each do |adapter_name|
44
- # desc "Test the #{adapter_name} database adapter"
45
- # task adapter_name do
46
- # save_val = ENV['TEST_ADAPTERS']
47
- # begin
48
- # ENV['TEST_ADAPTERS'] = adapter_name
49
- # Rake::Task["test:adapters:specified"].execute
50
- # ensure
51
- # ENV['TEST_ADAPTERS'] = save_val
52
- # end
53
- # end
54
- # end
55
- # end
56
- #end
14
+ namespace :test do
15
+ desc "Run all tests including for all database adapters"
16
+ task :all do
17
+ save_val = ENV['TEST_ADAPTERS']
18
+ begin
19
+ ENV['TEST_ADAPTERS'] = YAML.load_file(File.expand_path("../spec/database.yml", __FILE__)).keys.join(' ')
20
+ Rake::Task["test"].execute
21
+ ensure
22
+ ENV['TEST_ADAPTERS'] = save_val
23
+ end
24
+ end
25
+
26
+ desc "Test all database adapters defined in database.yml or just the one specified in TEST_ADAPTERS"
27
+ task :adapters do
28
+ save_val = ENV['TEST_ADAPTERS']
29
+ begin
30
+ ENV['TEST_ADAPTERS'] ||= YAML.load_file(File.expand_path("../spec/database.yml", __FILE__)).keys.join(' ')
31
+ Rake::Task["test:adapters:specified"].execute
32
+ ensure
33
+ ENV['TEST_ADAPTERS'] = save_val
34
+ end
35
+ end
36
+
37
+ namespace :adapters do
38
+ desc "Internal task to run database adapter tests"
39
+ RSpec::Core::RakeTask.new(:specified) do |t|
40
+ t.pattern = FileList.new('spec/connection_adapters_spec.rb')
41
+ end
42
+
43
+ YAML.load_file(File.expand_path("../spec/database.yml", __FILE__)).keys.each do |adapter_name|
44
+ desc "Test the #{adapter_name} database adapter"
45
+ task adapter_name do
46
+ save_val = ENV['TEST_ADAPTERS']
47
+ begin
48
+ ENV['TEST_ADAPTERS'] = adapter_name
49
+ Rake::Task["test:adapters:specified"].execute
50
+ ensure
51
+ ENV['TEST_ADAPTERS'] = save_val
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
57
  rescue LoadError
58
58
  task :test do
59
59
  STDERR.puts "You must have rspec >= 2.0 to run the tests"
@@ -1,5 +1,3 @@
1
- require 'maria_db_cluster_pool/connect_timeout'
2
-
3
1
  module ActiveRecord
4
2
  class Base
5
3
  class << self
@@ -18,7 +16,7 @@ module ActiveRecord
18
16
  begin
19
17
  establish_adapter(server_config[:adapter])
20
18
  conn = send("#{server_config[:adapter]}_connection".to_sym, server_config)
21
- conn.class.send(:include, MariaDBClusterPool::ConnectTimeout) unless conn.class.include?(MariaDBClusterPool::ConnectTimeout)
19
+ conn.class.send(:include, MariaDbClusterPool::ConnectTimeout) unless conn.class.include?(MariaDbClusterPool::ConnectTimeout)
22
20
  conn.connect_timeout = server_config[:connect_timeout]
23
21
  pool_connections << conn
24
22
  pool_weights[conn] = server_config[:pool_weight]
@@ -33,7 +31,7 @@ module ActiveRecord
33
31
  @maria_db_cluster_pool_classes ||= {}
34
32
  klass = @maria_db_cluster_pool_classes[pool_connections[0].class]
35
33
  unless klass
36
- klass = ActiveRecord::ConnectionAdapters::MariaDBClusterPoolAdapter.adapter_class(pool_connections[0])
34
+ klass = ActiveRecord::ConnectionAdapters::MariaDbClusterPoolAdapter.adapter_class(pool_connections[0])
37
35
  @maria_db_cluster_pool_classes[pool_connections[0].class] = klass
38
36
  end
39
37
 
@@ -65,7 +63,7 @@ module ActiveRecord
65
63
  end
66
64
 
67
65
  module ConnectionAdapters
68
- class MariaDBClusterPoolAdapter < AbstractAdapter
66
+ class MariaDbClusterPoolAdapter < AbstractAdapter
69
67
 
70
68
  attr_reader :connections # The total sum of connections
71
69
  attr_reader :master_connection # The current connection in use
@@ -109,7 +107,7 @@ module ActiveRecord
109
107
  # visitor. There is a note in the code indicating the method signatures should be updated.
110
108
  config = pool.spec.config.with_indifferent_access
111
109
  adapter = config[:master][:adapter] || config[:pool_adapter]
112
- MariaDBClusterPool.adapter_class_for(adapter).visitor_for(pool)
110
+ MariaDbClusterPool.adapter_class_for(adapter).visitor_for(pool)
113
111
  end
114
112
  end
115
113
 
@@ -221,8 +219,8 @@ module ActiveRecord
221
219
  a.reconnect!
222
220
  rescue => e
223
221
  a.expires = 30.seconds.from_now
224
- @logger.warn("Failed to reconnect to database when adding connection back to the pool")
225
- @logger.warn(e)
222
+ @logger.warn("Failed to reconnect to database when adding connection back to the pool") if @logger
223
+ @logger.warn(e) if @logger
226
224
  end
227
225
  end
228
226
  end
@@ -281,7 +279,9 @@ module ActiveRecord
281
279
  rescue ArgumentError
282
280
  connection.send(method)
283
281
  end
284
- rescue
282
+ rescue ActiveRecord::RecordInvalid => e
283
+ throw e
284
+ rescue => e
285
285
  # If the statement was a read statement and it wasn't forced against the master connection
286
286
  # try to reconnect if the connection is dead and then re-run the statement.
287
287
  unless connection.active?
@@ -1,7 +1,7 @@
1
1
  module Arel
2
2
  module SqlCompiler
3
3
  # Hook into arel to use the compiler used by the master connection.
4
- class MariaDBClusterPoolCompiler < GenericCompiler
4
+ class MariaDbClusterPoolCompiler < GenericCompiler
5
5
  def self.new(relation)
6
6
  @compiler_classes ||= {}
7
7
  master_adapter = relation.engine.connection.master_connection.adapter_name
@@ -1,6 +1,6 @@
1
1
  require 'timeout'
2
2
 
3
- module MariaDBClusterPool
3
+ module MariaDbClusterPool
4
4
  # This module is mixed into connection adapters to allow the reconnect! method to timeout if the
5
5
  # IP address becomes unreachable. The default timeout is 1 second, but you can change it by setting
6
6
  # the connect_timeout parameter in the adapter configuration.
@@ -14,7 +14,7 @@ $LOAD_PATH << File.dirname(__FILE__) unless $LOAD_PATH.include?(File.dirname(__F
14
14
  # will set the read connection type only within the block. Otherwise they will set the default
15
15
  # read connection type. If none is ever called, the read connection type will be :master.
16
16
 
17
- module MariaDBClusterPool
17
+ module MariaDbClusterPool
18
18
 
19
19
  # Adapter name to class name map. This exists because there isn't an obvious way to translate things like
20
20
  # sqlite3 to SQLite3. The adapters that ship with ActiveRecord are defined here. If you use
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maria_db_cluster_pool
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Ren\xC3\xA9 Schultz Madsen"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-04-10 00:00:00 +02:00
18
+ date: 2013-07-18 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -86,10 +86,10 @@ extensions: []
86
86
 
87
87
  extra_rdoc_files:
88
88
  - MIT-LICENSE
89
- - README.rdoc
89
+ - README.md
90
90
  files:
91
91
  - MIT-LICENSE
92
- - README.rdoc
92
+ - README.md
93
93
  - Rakefile
94
94
  - lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb
95
95
  - lib/maria_db_cluster_pool.rb