makara 0.5.1 → 0.6.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/CI.yml +0 -4
  3. data/.rubocop_todo.yml +6 -6
  4. data/CHANGELOG.md +3 -1
  5. data/README.md +51 -51
  6. data/lib/active_record/connection_adapters/makara_abstract_adapter.rb +32 -16
  7. data/lib/makara/config_parser.rb +63 -104
  8. data/lib/makara/connection_wrapper.rb +1 -1
  9. data/lib/makara/context.rb +1 -1
  10. data/lib/makara/logging/subscriber.rb +1 -1
  11. data/lib/makara/middleware.rb +1 -1
  12. data/lib/makara/pool.rb +2 -2
  13. data/lib/makara/proxy.rb +67 -52
  14. data/lib/makara/version.rb +5 -3
  15. data/spec/active_record/connection_adapters/makara_abstract_adapter_error_handling_spec.rb +2 -2
  16. data/spec/active_record/connection_adapters/makara_abstract_adapter_spec.rb +6 -6
  17. data/spec/active_record/connection_adapters/makara_mysql2_adapter_spec.rb +28 -26
  18. data/spec/active_record/connection_adapters/makara_postgis_adapter_spec.rb +15 -15
  19. data/spec/active_record/connection_adapters/makara_postgresql_adapter_spec.rb +25 -23
  20. data/spec/config_parser_spec.rb +26 -26
  21. data/spec/connection_wrapper_spec.rb +2 -2
  22. data/spec/context_spec.rb +1 -1
  23. data/spec/middleware_spec.rb +4 -4
  24. data/spec/pool_spec.rb +9 -9
  25. data/spec/proxy_spec.rb +74 -74
  26. data/spec/spec_helper.rb +7 -0
  27. data/spec/strategies/priority_failover_spec.rb +2 -2
  28. data/spec/strategies/shard_aware_spec.rb +16 -16
  29. data/spec/support/helpers.rb +6 -6
  30. data/spec/support/mock_objects.rb +1 -1
  31. data/spec/support/mysql2_database.yml +4 -4
  32. data/spec/support/mysql2_database_with_custom_errors.yml +4 -4
  33. data/spec/support/postgis_database.yml +4 -4
  34. data/spec/support/postgresql_database.yml +4 -4
  35. data/spec/support/proxy_extensions.rb +3 -3
  36. metadata +5 -5
data/spec/spec_helper.rb CHANGED
@@ -19,6 +19,13 @@ if RUBY_VERSION >= "2.7.0"
19
19
  Warning[:deprecated] = true
20
20
  end
21
21
 
22
+ # Delete once Timecop fixes Ruby 3.1 support
23
+ Time.class_eval do
24
+ class << self
25
+ ruby2_keywords :new if Module.private_method_defined?(:ruby2_keywords)
26
+ end
27
+ end
28
+
22
29
  RSpec.configure do |config|
23
30
  config.run_all_when_everything_filtered = true
24
31
  config.filter_run :focus
@@ -2,9 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Makara::Strategies::PriorityFailover do
4
4
  let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) }
5
- let(:pool){ Makara::Pool.new('master', proxy) }
5
+ let(:pool){ Makara::Pool.new('primary', proxy) }
6
6
  let(:pool_config){ {blacklist_duration: 5} }
7
- let(:makara_config) { { master_strategy: 'failover' } }
7
+ let(:makara_config) { { primary_strategy: 'failover' } }
8
8
  let(:strategy) { pool.strategy }
9
9
 
10
10
  it 'should use the strategy' do
@@ -12,12 +12,12 @@ describe Makara::Strategies::ShardAware do
12
12
 
13
13
  describe "failover strategy with shard awareness," do
14
14
  let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) }
15
- let(:pool){ Makara::Pool.new('master', proxy) }
15
+ let(:pool){ Makara::Pool.new('primary', proxy) }
16
16
  let(:pool_config){ { blacklist_duration: 5} }
17
17
  let(:makara_config) { {
18
- master_strategy: 'failover',
19
- master_shard_aware: true,
20
- master_default_shard: 'shard2'
18
+ primary_strategy: 'failover',
19
+ primary_shard_aware: true,
20
+ primary_default_shard: 'shard2'
21
21
  } }
22
22
  let(:strategy) { pool.strategy }
23
23
 
@@ -109,12 +109,12 @@ describe Makara::Strategies::ShardAware do
109
109
 
110
110
  describe "round_robin strategy with shard awareness," do
111
111
  let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) }
112
- let(:pool){ Makara::Pool.new('master', proxy) }
112
+ let(:pool){ Makara::Pool.new('primary', proxy) }
113
113
  let(:pool_config){ { blacklist_duration: 5} }
114
114
  let(:makara_config) { {
115
- master_strategy: 'round_robin',
116
- master_shard_aware: true,
117
- master_default_shard: 'shard2'
115
+ primary_strategy: 'round_robin',
116
+ primary_shard_aware: true,
117
+ primary_default_shard: 'shard2'
118
118
  } }
119
119
  let(:strategy) { pool.strategy }
120
120
 
@@ -186,12 +186,12 @@ describe Makara::Strategies::ShardAware do
186
186
 
187
187
  describe "uses the configured failover strategy when shard_aware set to false," do
188
188
  let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) }
189
- let(:pool){ Makara::Pool.new('master', proxy) }
189
+ let(:pool){ Makara::Pool.new('primary', proxy) }
190
190
  let(:pool_config){ { blacklist_duration: 5} }
191
191
  let(:makara_config) { {
192
- master_strategy: 'failover',
193
- master_shard_aware: false,
194
- master_default_shard: 'shard2'
192
+ primary_strategy: 'failover',
193
+ primary_shard_aware: false,
194
+ primary_default_shard: 'shard2'
195
195
  } }
196
196
  let(:strategy) { pool.strategy }
197
197
 
@@ -202,12 +202,12 @@ describe Makara::Strategies::ShardAware do
202
202
 
203
203
  describe "uses the configured roundrobin strategy when shard_aware set to false," do
204
204
  let(:proxy){ FakeProxy.new({makara: pool_config.merge(makara_config).merge(connections: [])}) }
205
- let(:pool){ Makara::Pool.new('master', proxy) }
205
+ let(:pool){ Makara::Pool.new('primary', proxy) }
206
206
  let(:pool_config){ { blacklist_duration: 5} }
207
207
  let(:makara_config) { {
208
- master_strategy: 'round_robin',
209
- master_shard_aware: false,
210
- master_default_shard: 'shard2'
208
+ primary_strategy: 'round_robin',
209
+ primary_shard_aware: false,
210
+ primary_default_shard: 'shard2'
211
211
  } }
212
212
  let(:strategy) { pool.strategy }
213
213
 
@@ -3,20 +3,20 @@ module SpecHelpers
3
3
  connection = ActiveRecord::Base.establish_connection(config)
4
4
 
5
5
  # make sure these are all reset to not be blacklisted
6
- ActiveRecord::Base.connection.slave_pool.connections.each(&:_makara_whitelist!)
7
- ActiveRecord::Base.connection.master_pool.connections.each(&:_makara_whitelist!)
6
+ ActiveRecord::Base.connection.replica_pool.connections.each(&:_makara_whitelist!)
7
+ ActiveRecord::Base.connection.primary_pool.connections.each(&:_makara_whitelist!)
8
8
 
9
9
  ActiveRecord::Base.connection
10
10
  end
11
11
 
12
- def config(masters = 1, slaves = 2)
12
+ def config(primaries = 1, replicas = 2)
13
13
  connections = []
14
- masters.times{ connections << {role: 'master'} }
15
- slaves.times{ connections << {role: 'slave'} }
14
+ primaries.times{ connections << {role: 'primary'} }
15
+ replicas.times{ connections << {role: 'replica'} }
16
16
  {
17
17
  makara: {
18
18
  # Defaults:
19
- # :master_ttl => 5,
19
+ # :primary_ttl => 5,
20
20
  # :blacklist_duration => 30,
21
21
  # :sticky => true
22
22
  id: 'mock_mysql',
@@ -56,7 +56,7 @@ class FakeProxy < Makara::Proxy
56
56
  FakeConnection.new(config)
57
57
  end
58
58
 
59
- def needs_master?(method_name, args)
59
+ def needs_primary?(method_name, args)
60
60
  return false if args.first =~ /^select/
61
61
 
62
62
  true
@@ -11,8 +11,8 @@ test:
11
11
 
12
12
  makara:
13
13
  blacklist_duration: 2
14
- master_ttl: 5
14
+ primary_ttl: 5
15
15
  connections:
16
- - role: master
17
- - role: slave
18
- - role: slave
16
+ - role: primary
17
+ - role: replica
18
+ - role: replica
@@ -11,11 +11,11 @@ test:
11
11
 
12
12
  makara:
13
13
  blacklist_duration: 2
14
- master_ttl: 5
14
+ primary_ttl: 5
15
15
  connections:
16
- - role: master
17
- - role: slave
18
- - role: slave
16
+ - role: primary
17
+ - role: replica
18
+ - role: replica
19
19
  connection_error_matchers:
20
20
  - !ruby/regexp '/^ActiveRecord::StatementInvalid: Mysql2::Error: Unknown command1:/'
21
21
  - "/^ActiveRecord::StatementInvalid: Mysql2::Error: Unknown command2:/i"
@@ -8,8 +8,8 @@ test:
8
8
 
9
9
  makara:
10
10
  blacklist_duration: 2
11
- master_ttl: 5
11
+ primary_ttl: 5
12
12
  connections:
13
- - role: master
14
- - role: slave
15
- - role: slave
13
+ - role: primary
14
+ - role: replica
15
+ - role: replica
@@ -6,8 +6,8 @@ test:
6
6
 
7
7
  makara:
8
8
  blacklist_duration: 2
9
- master_ttl: 5
9
+ primary_ttl: 5
10
10
  connections:
11
- - role: master
12
- - role: slave
13
- - role: slave
11
+ - role: primary
12
+ - role: replica
13
+ - role: replica
@@ -1,8 +1,8 @@
1
1
  module ProxyExtensions
2
- attr_reader :master_pool, :slave_pool, :id
2
+ attr_reader :primary_pool, :replica_pool, :id
3
3
 
4
- def master_for?(sql)
5
- pool_for(sql) == master_pool
4
+ def primary_for?(sql)
5
+ pool_for(sql) == primary_pool
6
6
  end
7
7
 
8
8
  def would_stick?(sql)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: makara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-04 00:00:00.000000000 Z
11
+ date: 2021-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -268,11 +268,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
268
268
  version: 2.5.0
269
269
  required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  requirements:
271
- - - ">="
271
+ - - ">"
272
272
  - !ruby/object:Gem::Version
273
- version: '0'
273
+ version: 1.3.1
274
274
  requirements: []
275
- rubygems_version: 3.2.15
275
+ rubygems_version: 3.2.3
276
276
  signing_key:
277
277
  specification_version: 4
278
278
  summary: Read-write split your DB yo