ar-octopus 0.8.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +1 -0
- data/.rspec +1 -1
- data/.rubocop.yml +46 -0
- data/.rubocop_todo.yml +56 -0
- data/.travis.yml +7 -12
- data/Appraisals +11 -4
- data/Gemfile +1 -1
- data/README.mkdn +138 -63
- data/Rakefile +23 -16
- data/ar-octopus.gemspec +23 -20
- data/gemfiles/rails42.gemfile +7 -0
- data/gemfiles/{rails32.gemfile → rails5.gemfile} +2 -2
- data/gemfiles/{rails4.gemfile → rails51.gemfile} +2 -2
- data/gemfiles/rails52.gemfile +7 -0
- data/lib/ar-octopus.rb +1 -1
- data/lib/octopus/{rails3/abstract_adapter.rb → abstract_adapter.rb} +4 -15
- data/lib/octopus/association.rb +8 -99
- data/lib/octopus/association_shard_tracking.rb +74 -0
- data/lib/octopus/collection_association.rb +17 -0
- data/lib/octopus/collection_proxy.rb +16 -0
- data/lib/octopus/exception.rb +4 -0
- data/lib/octopus/finder_methods.rb +8 -0
- data/lib/octopus/load_balancing/round_robin.rb +20 -0
- data/lib/octopus/load_balancing.rb +4 -0
- data/lib/octopus/{rails3/log_subscriber.rb → log_subscriber.rb} +6 -2
- data/lib/octopus/migration.rb +187 -110
- data/lib/octopus/model.rb +151 -131
- data/lib/octopus/persistence.rb +45 -0
- data/lib/octopus/proxy.rb +297 -232
- data/lib/octopus/proxy_config.rb +251 -0
- data/lib/octopus/query_cache_for_shards.rb +24 -0
- data/lib/octopus/railtie.rb +1 -3
- data/lib/octopus/relation_proxy.rb +70 -0
- data/lib/octopus/result_patch.rb +19 -0
- data/lib/octopus/scope_proxy.rb +54 -36
- data/lib/octopus/shard_tracking/attribute.rb +22 -0
- data/lib/octopus/shard_tracking/dynamic.rb +11 -0
- data/lib/octopus/shard_tracking.rb +46 -0
- data/lib/octopus/singular_association.rb +9 -0
- data/lib/octopus/slave_group.rb +13 -0
- data/lib/octopus/version.rb +1 -1
- data/lib/octopus.rb +125 -33
- data/lib/tasks/octopus.rake +2 -2
- data/sample_app/Gemfile +3 -3
- data/sample_app/autotest/discover.rb +2 -2
- data/sample_app/config/application.rb +1 -1
- data/sample_app/config/boot.rb +1 -1
- data/sample_app/config/environments/test.rb +1 -1
- data/sample_app/config/initializers/session_store.rb +1 -1
- data/sample_app/config/initializers/wrap_parameters.rb +1 -1
- data/sample_app/config/routes.rb +1 -1
- data/sample_app/db/migrate/20100720210335_create_sample_users.rb +2 -2
- data/sample_app/db/schema.rb +10 -10
- data/sample_app/db/seeds.rb +3 -3
- data/sample_app/features/step_definitions/seeds_steps.rb +4 -4
- data/sample_app/features/step_definitions/web_steps.rb +3 -4
- data/sample_app/features/support/env.rb +3 -4
- data/sample_app/features/support/paths.rb +4 -4
- data/sample_app/lib/tasks/cucumber.rake +43 -44
- data/sample_app/spec/spec_helper.rb +3 -3
- data/spec/config/shards.yml +78 -0
- data/spec/migrations/10_create_users_using_replication.rb +4 -4
- data/spec/migrations/11_add_field_in_all_slaves.rb +4 -4
- data/spec/migrations/12_create_users_using_block.rb +8 -8
- data/spec/migrations/13_create_users_using_block_and_using.rb +5 -5
- data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +3 -3
- data/spec/migrations/15_create_user_on_shards_of_default_group_with_versions.rb +3 -3
- data/spec/migrations/1_create_users_on_master.rb +4 -4
- data/spec/migrations/2_create_users_on_canada.rb +4 -4
- data/spec/migrations/3_create_users_on_both_shards.rb +4 -4
- data/spec/migrations/4_create_users_on_shards_of_a_group.rb +4 -4
- data/spec/migrations/5_create_users_on_multiples_groups.rb +3 -3
- data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +4 -4
- data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +4 -4
- data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +4 -4
- data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +5 -5
- data/spec/octopus/association_shard_tracking_spec.rb +1036 -0
- data/spec/octopus/collection_proxy_spec.rb +16 -0
- data/spec/octopus/load_balancing/round_robin_spec.rb +15 -0
- data/spec/octopus/log_subscriber_spec.rb +5 -5
- data/spec/octopus/migration_spec.rb +83 -49
- data/spec/octopus/model_spec.rb +544 -292
- data/spec/octopus/octopus_spec.rb +64 -31
- data/spec/octopus/proxy_spec.rb +145 -141
- data/spec/octopus/query_cache_for_shards_spec.rb +40 -0
- data/spec/octopus/relation_proxy_spec.rb +132 -0
- data/spec/octopus/replicated_slave_grouped_spec.rb +91 -0
- data/spec/octopus/replication_spec.rb +140 -65
- data/spec/octopus/scope_proxy_spec.rb +90 -10
- data/spec/octopus/sharded_replicated_slave_grouped_spec.rb +55 -0
- data/spec/octopus/sharded_spec.rb +10 -10
- data/spec/spec_helper.rb +8 -6
- data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +1 -3
- data/spec/support/database_connection.rb +2 -2
- data/spec/support/database_models.rb +18 -17
- data/spec/support/octopus_helper.rb +32 -25
- data/spec/support/query_count.rb +1 -3
- data/spec/support/shared_contexts.rb +3 -3
- data/spec/tasks/octopus.rake_spec.rb +10 -10
- metadata +112 -70
- data/.ruby-version +0 -1
- data/init.rb +0 -1
- data/lib/octopus/association_collection.rb +0 -49
- data/lib/octopus/has_and_belongs_to_many_association.rb +0 -17
- data/lib/octopus/rails3/persistence.rb +0 -39
- data/lib/octopus/rails3/singular_association.rb +0 -34
- data/rails/init.rb +0 -1
- data/spec/octopus/association_spec.rb +0 -712
data/spec/config/shards.yml
CHANGED
@@ -3,6 +3,12 @@ mysql: &mysql
|
|
3
3
|
username: <%= ENV['MYSQL_USER'] || 'root' %>
|
4
4
|
host: localhost
|
5
5
|
|
6
|
+
mysql_unavailable: &mysql_unavailable
|
7
|
+
adapter: mysql2
|
8
|
+
username: <%= ENV['MYSQL_USER'] || 'root' %>
|
9
|
+
host: 192.0.2.1
|
10
|
+
connect_timeout: 3
|
11
|
+
|
6
12
|
octopus: &octopus
|
7
13
|
shards:
|
8
14
|
alone_shard:
|
@@ -80,6 +86,18 @@ production_replicated:
|
|
80
86
|
<<: *mysql
|
81
87
|
|
82
88
|
|
89
|
+
production_fully_replicated:
|
90
|
+
replicated: true
|
91
|
+
fully_replicated: true
|
92
|
+
|
93
|
+
shards:
|
94
|
+
slave1:
|
95
|
+
database: octopus_shard_2
|
96
|
+
<<: *mysql
|
97
|
+
slave2:
|
98
|
+
database: octopus_shard_3
|
99
|
+
<<: *mysql
|
100
|
+
|
83
101
|
replicated_with_one_slave:
|
84
102
|
replicated: true
|
85
103
|
shards:
|
@@ -87,6 +105,13 @@ replicated_with_one_slave:
|
|
87
105
|
database: octopus_shard_2
|
88
106
|
<<: *mysql
|
89
107
|
|
108
|
+
replicated_with_one_slave_unavailable:
|
109
|
+
replicated: true
|
110
|
+
shards:
|
111
|
+
slave1:
|
112
|
+
database: octopus_shard_2
|
113
|
+
<<: *mysql_unavailable
|
114
|
+
|
90
115
|
|
91
116
|
production_fully_replicated:
|
92
117
|
replicated: true
|
@@ -142,6 +167,59 @@ not_entire_sharded:
|
|
142
167
|
database: octopus_shard_5
|
143
168
|
<<: *mysql
|
144
169
|
|
170
|
+
sharded_replicated_slave_grouped:
|
171
|
+
replicated: true
|
172
|
+
fully_replicated: true
|
173
|
+
shards:
|
174
|
+
russia:
|
175
|
+
database: octopus_shard_1
|
176
|
+
<<: *mysql
|
177
|
+
slaves1:
|
178
|
+
russia_slave11:
|
179
|
+
database: octopus_shard_1
|
180
|
+
<<: *mysql
|
181
|
+
russia_slave21:
|
182
|
+
database: octopus_shard_2
|
183
|
+
<<: *mysql
|
184
|
+
slaves2:
|
185
|
+
russia_slave21:
|
186
|
+
database: octopus_shard_3
|
187
|
+
<<: *mysql
|
188
|
+
russia_slave22:
|
189
|
+
database: octopus_shard_1
|
190
|
+
<<: *mysql
|
191
|
+
europe:
|
192
|
+
database: octopus_shard_2
|
193
|
+
<<: *mysql
|
194
|
+
slaves1:
|
195
|
+
europe_slave11:
|
196
|
+
database: octopus_shard_3
|
197
|
+
<<: *mysql
|
198
|
+
slaves2:
|
199
|
+
europe_slave21:
|
200
|
+
database: octopus_shard_1
|
201
|
+
<<: *mysql
|
202
|
+
|
203
|
+
replicated_slave_grouped:
|
204
|
+
replicated: true
|
205
|
+
fully_replicated: true
|
206
|
+
shards:
|
207
|
+
slaves1:
|
208
|
+
slave11:
|
209
|
+
database: octopus_shard_2
|
210
|
+
<<: *mysql
|
211
|
+
slaves2:
|
212
|
+
slave21:
|
213
|
+
database: octopus_shard_1
|
214
|
+
<<: *mysql
|
215
|
+
slaves3:
|
216
|
+
slave31:
|
217
|
+
database: octopus_shard_1
|
218
|
+
<<: *mysql
|
219
|
+
slave32:
|
220
|
+
database: octopus_shard_2
|
221
|
+
<<: *mysql
|
222
|
+
|
145
223
|
modify_config:
|
146
224
|
replicated: true
|
147
225
|
shards:
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class CreateUsersUsingReplication <
|
1
|
+
class CreateUsersUsingReplication < BaseOctopusMigrationClass
|
2
2
|
def self.up
|
3
|
-
Cat.create!(:name =>
|
3
|
+
Cat.create!(:name => 'Replication')
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.down
|
7
|
-
Cat.delete_all
|
7
|
+
Cat.delete_all
|
8
8
|
end
|
9
|
-
end
|
9
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class AddFieldInAllSlaves <
|
1
|
+
class AddFieldInAllSlaves < BaseOctopusMigrationClass
|
2
2
|
using(:slave1, :slave2, :slave3, :slave4)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
Cat.create!(:name =>
|
5
|
+
Cat.create!(:name => 'Slaves')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
Cat.delete_all
|
9
|
+
Cat.delete_all
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
class CreateUsersUsingBlock <
|
1
|
+
class CreateUsersUsingBlock < BaseOctopusMigrationClass
|
2
2
|
def self.up
|
3
3
|
Octopus.using(:brazil) do
|
4
|
-
User.create!(:name =>
|
5
|
-
User.create!(:name =>
|
4
|
+
User.create!(:name => 'UsingBlock1')
|
5
|
+
User.create!(:name => 'UsingBlock2')
|
6
6
|
end
|
7
7
|
|
8
8
|
Octopus.using(:canada) do
|
9
|
-
User.create!(:name =>
|
10
|
-
User.create!(:name =>
|
9
|
+
User.create!(:name => 'UsingCanada')
|
10
|
+
User.create!(:name => 'UsingCanada2')
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.down
|
15
15
|
Octopus.using(:brazil) do
|
16
|
-
User.delete_all
|
16
|
+
User.delete_all
|
17
17
|
end
|
18
18
|
|
19
19
|
Octopus.using(:canada) do
|
20
|
-
User.delete_all
|
20
|
+
User.delete_all
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
class CreateUsersUsingBlockAndUsing <
|
1
|
+
class CreateUsersUsingBlockAndUsing < BaseOctopusMigrationClass
|
2
2
|
using(:brazil)
|
3
3
|
|
4
4
|
def self.up
|
5
5
|
Octopus.using(:canada) do
|
6
|
-
User.create!(:name =>
|
6
|
+
User.create!(:name => 'Canada')
|
7
7
|
end
|
8
8
|
|
9
|
-
User.create!(:name =>
|
9
|
+
User.create!(:name => 'Brazil')
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.down
|
13
|
-
User.delete_all
|
13
|
+
User.delete_all
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreateUsersOnShardsOfAGroupWithVersions <
|
1
|
+
class CreateUsersOnShardsOfAGroupWithVersions < BaseOctopusMigrationClass
|
2
2
|
using_group(:country_shards)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
5
|
+
User.create!(:name => 'Group')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
User.delete_all
|
9
|
+
User.delete_all
|
10
10
|
end
|
11
11
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class CreateUserOnShardsOfDefaultGroupWithVersions <
|
1
|
+
class CreateUserOnShardsOfDefaultGroupWithVersions < BaseOctopusMigrationClass
|
2
2
|
def self.up
|
3
|
-
User.create!(:name =>
|
3
|
+
User.create!(:name => 'Default Group')
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.down
|
7
|
-
User.delete_all
|
7
|
+
User.delete_all
|
8
8
|
end
|
9
9
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class CreateUsersOnMaster <
|
1
|
+
class CreateUsersOnMaster < BaseOctopusMigrationClass
|
2
2
|
def self.up
|
3
|
-
User.create!(:name =>
|
3
|
+
User.create!(:name => 'Master')
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.down
|
7
|
-
User.delete_all
|
7
|
+
User.delete_all
|
8
8
|
end
|
9
|
-
end
|
9
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreateUsersOnCanada <
|
1
|
+
class CreateUsersOnCanada < BaseOctopusMigrationClass
|
2
2
|
using(:canada)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
5
|
+
User.create!(:name => 'Sharding')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
User.delete_all
|
9
|
+
User.delete_all
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreateUsersOnBothShards <
|
1
|
+
class CreateUsersOnBothShards < BaseOctopusMigrationClass
|
2
2
|
using(:brazil, :canada)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
5
|
+
User.create!(:name => 'Both')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
User.delete_all
|
9
|
+
User.delete_all
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreateUsersOnShardsOfAGroup <
|
1
|
+
class CreateUsersOnShardsOfAGroup < BaseOctopusMigrationClass
|
2
2
|
using_group(:country_shards)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
5
|
+
User.create!(:name => 'Group')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
User.delete_all
|
9
|
+
User.delete_all
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class CreateUsersOnMultiplesGroups <
|
1
|
+
class CreateUsersOnMultiplesGroups < BaseOctopusMigrationClass
|
2
2
|
using_group('country_shards', 'history_shards')
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
5
|
+
User.create!(:name => 'MultipleGroup')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
User.delete_all
|
9
|
+
User.delete_all
|
10
10
|
end
|
11
11
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class RaiseExceptionWithInvalidShardName <
|
1
|
+
class RaiseExceptionWithInvalidShardName < BaseOctopusMigrationClass
|
2
2
|
using(:amazing_shard)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
5
|
+
User.create!(:name => 'Error')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
User.delete_all
|
9
|
+
User.delete_all
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class RaiseExceptionWithInvalidMultipleShardNames <
|
1
|
+
class RaiseExceptionWithInvalidMultipleShardNames < BaseOctopusMigrationClass
|
2
2
|
using(:brazil, :invalid_shard)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
5
|
+
User.create!(:name => 'Error')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
User.delete_all
|
9
|
+
User.delete_all
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class RaiseExceptionWithInvalidGroupName <
|
1
|
+
class RaiseExceptionWithInvalidGroupName < BaseOctopusMigrationClass
|
2
2
|
using_group(:invalid_group)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
5
|
+
User.create!(:name => 'Error')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
User.delete_all
|
9
|
+
User.delete_all
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
class RaiseExceptionWithMultipleInvalidGroupNames <
|
2
|
-
using_group(:country_shards
|
1
|
+
class RaiseExceptionWithMultipleInvalidGroupNames < BaseOctopusMigrationClass
|
2
|
+
using_group(:country_shards, :invalid_group)
|
3
3
|
|
4
4
|
def self.up
|
5
|
-
User.create!(:name =>
|
5
|
+
User.create!(:name => 'Error')
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.down
|
9
|
-
User.delete_all
|
9
|
+
User.delete_all
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|