makara 0.5.1 → 0.6.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/CI.yml +0 -4
- data/.rubocop_todo.yml +6 -6
- data/CHANGELOG.md +3 -1
- data/README.md +51 -51
- data/lib/active_record/connection_adapters/makara_abstract_adapter.rb +32 -16
- data/lib/makara/config_parser.rb +63 -104
- data/lib/makara/connection_wrapper.rb +1 -1
- data/lib/makara/context.rb +1 -1
- data/lib/makara/logging/subscriber.rb +1 -1
- data/lib/makara/middleware.rb +1 -1
- data/lib/makara/pool.rb +2 -2
- data/lib/makara/proxy.rb +67 -52
- data/lib/makara/version.rb +5 -3
- data/spec/active_record/connection_adapters/makara_abstract_adapter_error_handling_spec.rb +2 -2
- data/spec/active_record/connection_adapters/makara_abstract_adapter_spec.rb +6 -6
- data/spec/active_record/connection_adapters/makara_mysql2_adapter_spec.rb +28 -26
- data/spec/active_record/connection_adapters/makara_postgis_adapter_spec.rb +15 -15
- data/spec/active_record/connection_adapters/makara_postgresql_adapter_spec.rb +25 -23
- data/spec/config_parser_spec.rb +26 -26
- data/spec/connection_wrapper_spec.rb +2 -2
- data/spec/context_spec.rb +1 -1
- data/spec/middleware_spec.rb +4 -4
- data/spec/pool_spec.rb +9 -9
- data/spec/proxy_spec.rb +74 -74
- data/spec/spec_helper.rb +7 -0
- data/spec/strategies/priority_failover_spec.rb +2 -2
- data/spec/strategies/shard_aware_spec.rb +16 -16
- data/spec/support/helpers.rb +6 -6
- data/spec/support/mock_objects.rb +1 -1
- data/spec/support/mysql2_database.yml +4 -4
- data/spec/support/mysql2_database_with_custom_errors.yml +4 -4
- data/spec/support/postgis_database.yml +4 -4
- data/spec/support/postgresql_database.yml +4 -4
- data/spec/support/proxy_extensions.rb +3 -3
- 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('
|
5
|
+
let(:pool){ Makara::Pool.new('primary', proxy) }
|
6
6
|
let(:pool_config){ {blacklist_duration: 5} }
|
7
|
-
let(:makara_config) { {
|
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('
|
15
|
+
let(:pool){ Makara::Pool.new('primary', proxy) }
|
16
16
|
let(:pool_config){ { blacklist_duration: 5} }
|
17
17
|
let(:makara_config) { {
|
18
|
-
|
19
|
-
|
20
|
-
|
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('
|
112
|
+
let(:pool){ Makara::Pool.new('primary', proxy) }
|
113
113
|
let(:pool_config){ { blacklist_duration: 5} }
|
114
114
|
let(:makara_config) { {
|
115
|
-
|
116
|
-
|
117
|
-
|
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('
|
189
|
+
let(:pool){ Makara::Pool.new('primary', proxy) }
|
190
190
|
let(:pool_config){ { blacklist_duration: 5} }
|
191
191
|
let(:makara_config) { {
|
192
|
-
|
193
|
-
|
194
|
-
|
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('
|
205
|
+
let(:pool){ Makara::Pool.new('primary', proxy) }
|
206
206
|
let(:pool_config){ { blacklist_duration: 5} }
|
207
207
|
let(:makara_config) { {
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
|
data/spec/support/helpers.rb
CHANGED
@@ -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.
|
7
|
-
ActiveRecord::Base.connection.
|
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(
|
12
|
+
def config(primaries = 1, replicas = 2)
|
13
13
|
connections = []
|
14
|
-
|
15
|
-
|
14
|
+
primaries.times{ connections << {role: 'primary'} }
|
15
|
+
replicas.times{ connections << {role: 'replica'} }
|
16
16
|
{
|
17
17
|
makara: {
|
18
18
|
# Defaults:
|
19
|
-
# :
|
19
|
+
# :primary_ttl => 5,
|
20
20
|
# :blacklist_duration => 30,
|
21
21
|
# :sticky => true
|
22
22
|
id: 'mock_mysql',
|
@@ -11,11 +11,11 @@ test:
|
|
11
11
|
|
12
12
|
makara:
|
13
13
|
blacklist_duration: 2
|
14
|
-
|
14
|
+
primary_ttl: 5
|
15
15
|
connections:
|
16
|
-
- role:
|
17
|
-
- role:
|
18
|
-
- role:
|
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"
|
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.
|
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-
|
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:
|
273
|
+
version: 1.3.1
|
274
274
|
requirements: []
|
275
|
-
rubygems_version: 3.2.
|
275
|
+
rubygems_version: 3.2.3
|
276
276
|
signing_key:
|
277
277
|
specification_version: 4
|
278
278
|
summary: Read-write split your DB yo
|