activerecord-shard_for 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +22 -0
- data/.travis.yml +11 -3
- data/Appraisals +9 -1
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/gemfiles/.bundle/config +2 -1
- data/gemfiles/ar_5.0.gemfile +2 -2
- data/gemfiles/ar_5.1.gemfile +7 -0
- data/gemfiles/ar_5.2.gemfile +7 -0
- data/gemfiles/rails_edge.gemfile +3 -3
- data/lib/activerecord/shard_for/all_shards_in_parallel.rb +4 -2
- data/lib/activerecord/shard_for/database_tasks.rb +1 -1
- data/lib/activerecord/shard_for/model.rb +12 -2
- data/lib/activerecord/shard_for/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18b127f1099df390fc67db8548a308d1dc66cded
|
4
|
+
data.tar.gz: 25f90de3cad7a5824d1f164370e6b146589614b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0b5fc995889395482558bc950bc113a2692e21f8dc7a5ef0d75de8a1cb172e0c100cfeb28c77fc05536df4243513c5a4a54316d94d34299e7605cc9044fd764
|
7
|
+
data.tar.gz: 15dda5d854a5191a9559b020722a1fc6c960f8412479fda3d53a4fe6beeb2e6a738d0f948f29c5eb942ed31058e7bd474851b26bb79c3cee6e39c843d21112fb
|
data/.rubocop.yml
CHANGED
@@ -8,6 +8,18 @@ AllCops:
|
|
8
8
|
- vendor/bundle/**/*
|
9
9
|
DisplayCopNames: true
|
10
10
|
|
11
|
+
Style/StderrPuts:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Naming/UncommunicativeMethodParamName:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/ExpandPathArguments:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/PercentLiteralDelimiters:
|
21
|
+
Enabled: false
|
22
|
+
|
11
23
|
Style/FrozenStringLiteralComment:
|
12
24
|
Enabled: false
|
13
25
|
|
@@ -20,9 +32,19 @@ Metrics/LineLength:
|
|
20
32
|
Style/EmptyCaseCondition:
|
21
33
|
Enabled: false
|
22
34
|
|
35
|
+
Layout/EmptyLineAfterMagicComment:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Layout/FileName:
|
39
|
+
Exclude:
|
40
|
+
- Appraisals
|
41
|
+
|
23
42
|
Metrics/MethodLength:
|
24
43
|
Max: 15
|
25
44
|
|
45
|
+
Metrics/AbcSize:
|
46
|
+
Max: 20
|
47
|
+
|
26
48
|
Style/ParallelAssignment:
|
27
49
|
Enabled: false
|
28
50
|
|
data/.travis.yml
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
rvm:
|
4
|
-
- 2.2.
|
5
|
-
- 2.3.
|
6
|
-
- 2.4.
|
4
|
+
- 2.2.7
|
5
|
+
- 2.3.4
|
6
|
+
- 2.4.1
|
7
7
|
branches:
|
8
8
|
only:
|
9
9
|
- master
|
@@ -18,10 +18,18 @@ script:
|
|
18
18
|
- CODECLIMATE_REPO_TOKEN=dfc951e2d70b56ee62ffe989eb6286a6f21bf57209ccbd111bd336c372d8d06e bundle exec codeclimate-test-reporter
|
19
19
|
gemfile:
|
20
20
|
- gemfiles/ar_5.0.gemfile
|
21
|
+
- gemfiles/ar_5.1.gemfile
|
22
|
+
- gemfiles/ar_5.2.gemfile
|
21
23
|
- gemfiles/rails_edge.gemfile
|
22
24
|
matrix:
|
23
25
|
allow_failures:
|
24
26
|
- gemfile: gemfiles/rails_edge.gemfile
|
27
|
+
# rails_edge required ruby version over 2.4.1
|
28
|
+
exclude:
|
29
|
+
- rvm: 2.2.7
|
30
|
+
gemfile: gemfiles/rails_edge.gemfile
|
31
|
+
- rvm: 2.3.4
|
32
|
+
gemfile: gemfiles/rails_edge.gemfile
|
25
33
|
notifications:
|
26
34
|
slack:
|
27
35
|
secure: S1W/Lw+dH3wb8FfkMIWPZmr6M4Q6S2WMkSlanpKva1HM7K5QL7hXdmUl2yBUxJE26BHSsb1ScozMEzadyda2+i/W34UvZ7LXgKeHkUKEdjy/AmsSJPK1ZjMfgnv10tVgbEIusNb4bF/sSuChdZKK3ILwOlqIPDlQNdMwF1xRA2xt5J7tb26UgyIzoCI4P3bJYMULWsEkk+UwHiJH0YO9ulkTZI/j0N+hLXQLJTZPjmKtMk/tE0NbBmFVL4md89hUcR5gKTGGrNzEMJ58K+zqeDG/DubkcIbA5ZuqKv+oE5m0pDODZExxnC+oeENTvq/VfYwOfD0pTDrBNYjj+Bm3YiyGDzQAgov9XPDG8g/fKEs/LNAT79UZXkZlFO99Yn/vrYH9o5DKpOE9smENUXylb55MgLTUiYe17CTp7pB3trbJl3wwIbLjSmTjAdSUNgPv8qDP4uk3K4U32mknXCDDkU9EI7f6F731ocdoxsGarEBcPcgjs73Y84iwDteQp847Gigtgo4Y4TCWH657uzLolR2O8NSw+vWT0VNI9qtR5PZD7iVYtSp1qHtPAKowCztodewY2Nu+Ds9Z95udf4GPUkFg/SNEJPTPrQFLiiJZ8UYP8NJEuA+IP1tc2zG3zU/ADrjenRC1ZiupQG7OMH82y11408U6PcHFSlF+7NuDkac=
|
data/Appraisals
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# vim: set ft=ruby
|
2
2
|
|
3
3
|
appraise 'ar-5.0' do
|
4
|
-
gem 'activerecord', '~> 5.0.
|
4
|
+
gem 'activerecord', '~> 5.0.7'
|
5
|
+
end
|
6
|
+
|
7
|
+
appraise 'ar-5.1' do
|
8
|
+
gem 'activerecord', '~> 5.1.6'
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise 'ar-5.2' do
|
12
|
+
gem 'activerecord', '~> 5.2.1'
|
5
13
|
end
|
6
14
|
|
7
15
|
appraise 'rails-edge' do
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# CHANGELOG for activerecord-shard_for
|
2
2
|
|
3
|
+
## 0.6.1
|
4
|
+
|
5
|
+
- Allow settings `thread_pool_base_size` and command executor. [#18](https://github.com/yuemori/activerecord-shard_for/pull/18)
|
6
|
+
- Bump up supporeted rails versions. [#19](https://github.com/yuemori/activerecord-shard_for/pull/19)
|
7
|
+
- Add rails 5.2
|
8
|
+
|
3
9
|
## 0.6.0
|
4
10
|
|
5
11
|
- Support same connection to connect for same shard. [#15](https://github.com/yuemori/activerecord-shard_for/pull/15)
|
data/README.md
CHANGED
@@ -76,7 +76,7 @@ class User < ActiveRecord::Base
|
|
76
76
|
end
|
77
77
|
```
|
78
78
|
|
79
|
-
Use `.get` to
|
79
|
+
Use `.get` to retrieve single record which is connected to proper database node. Use .put! to create new record to proper database node.
|
80
80
|
|
81
81
|
`.all_shards` returns each model class which is connected to proper database node. You can query with these models and aggregate result.
|
82
82
|
|
data/gemfiles/.bundle/config
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
---
|
1
|
+
---
|
2
|
+
BUNDLE_RETRY: "1"
|
data/gemfiles/ar_5.0.gemfile
CHANGED
data/gemfiles/rails_edge.gemfile
CHANGED
@@ -4,8 +4,10 @@ module ActiveRecord
|
|
4
4
|
module ShardFor
|
5
5
|
class AllShardsInParallel
|
6
6
|
# @param [Array<Class>] An array of shard model class
|
7
|
-
|
7
|
+
# @param [Expeditor::Service] service
|
8
|
+
def initialize(shards, service:)
|
8
9
|
@shards = shards
|
10
|
+
@service = service
|
9
11
|
end
|
10
12
|
|
11
13
|
# @yield [Class] A shard model class
|
@@ -16,7 +18,7 @@ module ActiveRecord
|
|
16
18
|
return [] unless block_given?
|
17
19
|
|
18
20
|
commands = @shards.map do |m|
|
19
|
-
Expeditor::Command.new { m.connection_pool.with_connection { yield m } }
|
21
|
+
Expeditor::Command.new(service: @service) { m.connection_pool.with_connection { yield m } }
|
20
22
|
end
|
21
23
|
commands.each(&:start)
|
22
24
|
commands.map(&:get)
|
@@ -130,7 +130,7 @@ module ActiveRecord
|
|
130
130
|
return cluster_name if cluster_name
|
131
131
|
|
132
132
|
$stderr.puts <<-MSG
|
133
|
-
Missing cluster_name. Find cluster_name via `rake activerecord:shard_for:info` then call `rake "activerecord:shard_for:#{name}[$cluster_name]"`.
|
133
|
+
Missing cluster_name. Find cluster_name via `rake activerecord:shard_for:info` then call `rake "activerecord:shard_for:#{name}[$cluster_name]"`.
|
134
134
|
MSG
|
135
135
|
exit_with_error
|
136
136
|
end
|
@@ -10,6 +10,7 @@ module ActiveRecord
|
|
10
10
|
class_attribute :shard_repository, instance_writer: false
|
11
11
|
class_attribute :replication_mapping, instance_writer: false
|
12
12
|
class_attribute :distkey, instance_writer: false
|
13
|
+
class_attribute :service, instance_writer: false
|
13
14
|
|
14
15
|
include ActiveRecord::ShardFor::Patch
|
15
16
|
end
|
@@ -17,11 +18,20 @@ module ActiveRecord
|
|
17
18
|
module ClassMethods
|
18
19
|
# The cluster config must be defined before `use_cluster`
|
19
20
|
# @param [Symbol] name A cluster name which is set by ActiveRecord::ShardFor.configure
|
20
|
-
def use_cluster(name, router_name)
|
21
|
+
def use_cluster(name, router_name, thread_pool_size_base: 3)
|
21
22
|
cluster_config = ActiveRecord::ShardFor.config.fetch_cluster_config(name)
|
22
23
|
connection_router_class = ActiveRecord::ShardFor.config.fetch_connection_router(router_name)
|
23
24
|
self.connection_router = connection_router_class.new(cluster_config)
|
24
25
|
self.shard_repository = ActiveRecord::ShardFor::ShardRepository.new(cluster_config, self)
|
26
|
+
thread_size = (shard_repository.all.size * thread_pool_size_base)
|
27
|
+
self.service = Expeditor::Service.new(
|
28
|
+
executor: Concurrent::ThreadPoolExecutor.new(
|
29
|
+
min_threads: thread_size,
|
30
|
+
max_threads: thread_size,
|
31
|
+
max_queue: shard_repository.all.size,
|
32
|
+
fallback_policy: :abort
|
33
|
+
)
|
34
|
+
)
|
25
35
|
self.abstract_class = true
|
26
36
|
end
|
27
37
|
|
@@ -124,7 +134,7 @@ module ActiveRecord
|
|
124
134
|
# @example
|
125
135
|
# User.all_shards_in_parallel.map {|m| m.where.find_by(name: 'Alice') }.compact
|
126
136
|
def all_shards_in_parallel
|
127
|
-
AllShardsInParallel.new(all_shards)
|
137
|
+
AllShardsInParallel.new(all_shards, service: service)
|
128
138
|
end
|
129
139
|
alias_method :parallel, :all_shards_in_parallel
|
130
140
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-shard_for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yuemori
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -243,6 +243,8 @@ files:
|
|
243
243
|
- bin/setup
|
244
244
|
- gemfiles/.bundle/config
|
245
245
|
- gemfiles/ar_5.0.gemfile
|
246
|
+
- gemfiles/ar_5.1.gemfile
|
247
|
+
- gemfiles/ar_5.2.gemfile
|
246
248
|
- gemfiles/rails_edge.gemfile
|
247
249
|
- lib/activerecord/shard_for.rb
|
248
250
|
- lib/activerecord/shard_for/abstract_shard_repository.rb
|
@@ -283,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
283
285
|
version: '0'
|
284
286
|
requirements: []
|
285
287
|
rubyforge_project:
|
286
|
-
rubygems_version: 2.6.
|
288
|
+
rubygems_version: 2.6.13
|
287
289
|
signing_key:
|
288
290
|
specification_version: 4
|
289
291
|
summary: Database sharding library for ActiveRecord
|