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.
Files changed (109) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +46 -0
  5. data/.rubocop_todo.yml +56 -0
  6. data/.travis.yml +7 -12
  7. data/Appraisals +11 -4
  8. data/Gemfile +1 -1
  9. data/README.mkdn +138 -63
  10. data/Rakefile +23 -16
  11. data/ar-octopus.gemspec +23 -20
  12. data/gemfiles/rails42.gemfile +7 -0
  13. data/gemfiles/{rails32.gemfile → rails5.gemfile} +2 -2
  14. data/gemfiles/{rails4.gemfile → rails51.gemfile} +2 -2
  15. data/gemfiles/rails52.gemfile +7 -0
  16. data/lib/ar-octopus.rb +1 -1
  17. data/lib/octopus/{rails3/abstract_adapter.rb → abstract_adapter.rb} +4 -15
  18. data/lib/octopus/association.rb +8 -99
  19. data/lib/octopus/association_shard_tracking.rb +74 -0
  20. data/lib/octopus/collection_association.rb +17 -0
  21. data/lib/octopus/collection_proxy.rb +16 -0
  22. data/lib/octopus/exception.rb +4 -0
  23. data/lib/octopus/finder_methods.rb +8 -0
  24. data/lib/octopus/load_balancing/round_robin.rb +20 -0
  25. data/lib/octopus/load_balancing.rb +4 -0
  26. data/lib/octopus/{rails3/log_subscriber.rb → log_subscriber.rb} +6 -2
  27. data/lib/octopus/migration.rb +187 -110
  28. data/lib/octopus/model.rb +151 -131
  29. data/lib/octopus/persistence.rb +45 -0
  30. data/lib/octopus/proxy.rb +297 -232
  31. data/lib/octopus/proxy_config.rb +251 -0
  32. data/lib/octopus/query_cache_for_shards.rb +24 -0
  33. data/lib/octopus/railtie.rb +1 -3
  34. data/lib/octopus/relation_proxy.rb +70 -0
  35. data/lib/octopus/result_patch.rb +19 -0
  36. data/lib/octopus/scope_proxy.rb +54 -36
  37. data/lib/octopus/shard_tracking/attribute.rb +22 -0
  38. data/lib/octopus/shard_tracking/dynamic.rb +11 -0
  39. data/lib/octopus/shard_tracking.rb +46 -0
  40. data/lib/octopus/singular_association.rb +9 -0
  41. data/lib/octopus/slave_group.rb +13 -0
  42. data/lib/octopus/version.rb +1 -1
  43. data/lib/octopus.rb +125 -33
  44. data/lib/tasks/octopus.rake +2 -2
  45. data/sample_app/Gemfile +3 -3
  46. data/sample_app/autotest/discover.rb +2 -2
  47. data/sample_app/config/application.rb +1 -1
  48. data/sample_app/config/boot.rb +1 -1
  49. data/sample_app/config/environments/test.rb +1 -1
  50. data/sample_app/config/initializers/session_store.rb +1 -1
  51. data/sample_app/config/initializers/wrap_parameters.rb +1 -1
  52. data/sample_app/config/routes.rb +1 -1
  53. data/sample_app/db/migrate/20100720210335_create_sample_users.rb +2 -2
  54. data/sample_app/db/schema.rb +10 -10
  55. data/sample_app/db/seeds.rb +3 -3
  56. data/sample_app/features/step_definitions/seeds_steps.rb +4 -4
  57. data/sample_app/features/step_definitions/web_steps.rb +3 -4
  58. data/sample_app/features/support/env.rb +3 -4
  59. data/sample_app/features/support/paths.rb +4 -4
  60. data/sample_app/lib/tasks/cucumber.rake +43 -44
  61. data/sample_app/spec/spec_helper.rb +3 -3
  62. data/spec/config/shards.yml +78 -0
  63. data/spec/migrations/10_create_users_using_replication.rb +4 -4
  64. data/spec/migrations/11_add_field_in_all_slaves.rb +4 -4
  65. data/spec/migrations/12_create_users_using_block.rb +8 -8
  66. data/spec/migrations/13_create_users_using_block_and_using.rb +5 -5
  67. data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +3 -3
  68. data/spec/migrations/15_create_user_on_shards_of_default_group_with_versions.rb +3 -3
  69. data/spec/migrations/1_create_users_on_master.rb +4 -4
  70. data/spec/migrations/2_create_users_on_canada.rb +4 -4
  71. data/spec/migrations/3_create_users_on_both_shards.rb +4 -4
  72. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +4 -4
  73. data/spec/migrations/5_create_users_on_multiples_groups.rb +3 -3
  74. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +4 -4
  75. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +4 -4
  76. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +4 -4
  77. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +5 -5
  78. data/spec/octopus/association_shard_tracking_spec.rb +1036 -0
  79. data/spec/octopus/collection_proxy_spec.rb +16 -0
  80. data/spec/octopus/load_balancing/round_robin_spec.rb +15 -0
  81. data/spec/octopus/log_subscriber_spec.rb +5 -5
  82. data/spec/octopus/migration_spec.rb +83 -49
  83. data/spec/octopus/model_spec.rb +544 -292
  84. data/spec/octopus/octopus_spec.rb +64 -31
  85. data/spec/octopus/proxy_spec.rb +145 -141
  86. data/spec/octopus/query_cache_for_shards_spec.rb +40 -0
  87. data/spec/octopus/relation_proxy_spec.rb +132 -0
  88. data/spec/octopus/replicated_slave_grouped_spec.rb +91 -0
  89. data/spec/octopus/replication_spec.rb +140 -65
  90. data/spec/octopus/scope_proxy_spec.rb +90 -10
  91. data/spec/octopus/sharded_replicated_slave_grouped_spec.rb +55 -0
  92. data/spec/octopus/sharded_spec.rb +10 -10
  93. data/spec/spec_helper.rb +8 -6
  94. data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +1 -3
  95. data/spec/support/database_connection.rb +2 -2
  96. data/spec/support/database_models.rb +18 -17
  97. data/spec/support/octopus_helper.rb +32 -25
  98. data/spec/support/query_count.rb +1 -3
  99. data/spec/support/shared_contexts.rb +3 -3
  100. data/spec/tasks/octopus.rake_spec.rb +10 -10
  101. metadata +112 -70
  102. data/.ruby-version +0 -1
  103. data/init.rb +0 -1
  104. data/lib/octopus/association_collection.rb +0 -49
  105. data/lib/octopus/has_and_belongs_to_many_association.rb +0 -17
  106. data/lib/octopus/rails3/persistence.rb +0 -39
  107. data/lib/octopus/rails3/singular_association.rb +0 -34
  108. data/rails/init.rb +0 -1
  109. data/spec/octopus/association_spec.rb +0 -712
@@ -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 < ActiveRecord::Migration
1
+ class CreateUsersUsingReplication < BaseOctopusMigrationClass
2
2
  def self.up
3
- Cat.create!(:name => "Replication")
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 < ActiveRecord::Migration
1
+ class AddFieldInAllSlaves < BaseOctopusMigrationClass
2
2
  using(:slave1, :slave2, :slave3, :slave4)
3
3
 
4
4
  def self.up
5
- Cat.create!(:name => "Slaves")
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 < ActiveRecord::Migration
1
+ class CreateUsersUsingBlock < BaseOctopusMigrationClass
2
2
  def self.up
3
3
  Octopus.using(:brazil) do
4
- User.create!(:name => "UsingBlock1")
5
- User.create!(:name => "UsingBlock2")
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 => "UsingCanada")
10
- User.create!(:name => "UsingCanada2")
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 < ActiveRecord::Migration
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 => "Canada")
6
+ User.create!(:name => 'Canada')
7
7
  end
8
8
 
9
- User.create!(:name => "Brazil")
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 < ActiveRecord::Migration
1
+ class CreateUsersOnShardsOfAGroupWithVersions < BaseOctopusMigrationClass
2
2
  using_group(:country_shards)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Group")
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 < ActiveRecord::Migration
1
+ class CreateUserOnShardsOfDefaultGroupWithVersions < BaseOctopusMigrationClass
2
2
  def self.up
3
- User.create!(:name => "Default Group")
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 < ActiveRecord::Migration
1
+ class CreateUsersOnMaster < BaseOctopusMigrationClass
2
2
  def self.up
3
- User.create!(:name => "Master")
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 < ActiveRecord::Migration
1
+ class CreateUsersOnCanada < BaseOctopusMigrationClass
2
2
  using(:canada)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Sharding")
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 < ActiveRecord::Migration
1
+ class CreateUsersOnBothShards < BaseOctopusMigrationClass
2
2
  using(:brazil, :canada)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Both")
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 < ActiveRecord::Migration
1
+ class CreateUsersOnShardsOfAGroup < BaseOctopusMigrationClass
2
2
  using_group(:country_shards)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Group")
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 < ActiveRecord::Migration
1
+ class CreateUsersOnMultiplesGroups < BaseOctopusMigrationClass
2
2
  using_group('country_shards', 'history_shards')
3
3
 
4
4
  def self.up
5
- User.create!(:name => "MultipleGroup")
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 < ActiveRecord::Migration
1
+ class RaiseExceptionWithInvalidShardName < BaseOctopusMigrationClass
2
2
  using(:amazing_shard)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Error")
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 < ActiveRecord::Migration
1
+ class RaiseExceptionWithInvalidMultipleShardNames < BaseOctopusMigrationClass
2
2
  using(:brazil, :invalid_shard)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Error")
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 < ActiveRecord::Migration
1
+ class RaiseExceptionWithInvalidGroupName < BaseOctopusMigrationClass
2
2
  using_group(:invalid_group)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Error")
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 < ActiveRecord::Migration
2
- using_group(:country_shards,:invalid_group)
1
+ class RaiseExceptionWithMultipleInvalidGroupNames < BaseOctopusMigrationClass
2
+ using_group(:country_shards, :invalid_group)
3
3
 
4
4
  def self.up
5
- User.create!(:name => "Error")
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