activerecord-turntable 2.0.0.rc1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/lib/active_record/turntable/active_record_ext/abstract_adapter.rb +1 -0
- data/lib/active_record/turntable/active_record_ext/activerecord_import_ext.rb +2 -0
- data/lib/active_record/turntable/active_record_ext/acts_as_archive_extension.rb +2 -1
- data/lib/active_record/turntable/active_record_ext/association.rb +2 -0
- data/lib/active_record/turntable/active_record_ext/association_preloader.rb +1 -0
- data/lib/active_record/turntable/active_record_ext/connection_handler_extension.rb +1 -0
- data/lib/active_record/turntable/active_record_ext/locking_optimistic.rb +1 -1
- data/lib/active_record/turntable/active_record_ext/log_subscriber.rb +1 -0
- data/lib/active_record/turntable/active_record_ext/persistence.rb +5 -0
- data/lib/active_record/turntable/active_record_ext/relation.rb +1 -0
- data/lib/active_record/turntable/active_record_ext/schema_dumper.rb +1 -0
- data/lib/active_record/turntable/active_record_ext/transactions.rb +1 -0
- data/lib/active_record/turntable/base.rb +6 -0
- data/lib/active_record/turntable/connection_proxy.rb +12 -0
- data/lib/active_record/turntable/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ed732d4f5ce27c8ec309d715a01e33bc4e287f2
|
4
|
+
data.tar.gz: e026370254d526d21205b9a72cd0a05e8df5d355
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77aa461ca4b2c0ce44589ffb756f8c49cfa263040b435235cfd9afd38d0469086c8a6e33ee2b1d82badbefbede00d640cdae145581f4cae9363eac271ee16cbc
|
7
|
+
data.tar.gz: f78bc87da3c3e41717f2a2cbd797a96fd7a07dc12daa274b7b8ff30c03055950f78c0b083b788d107e5744379acafea0cdde7d5f80e2cbe896d8b0c89db0fba5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module ActiveRecord::Turntable
|
2
2
|
module ActiveRecordExt
|
3
|
+
# activerecord-import extension
|
3
4
|
module ActiverecordImportExt
|
4
5
|
extend ActiveSupport::Concern
|
5
6
|
|
@@ -9,6 +10,7 @@ module ActiveRecord::Turntable
|
|
9
10
|
|
10
11
|
private
|
11
12
|
|
13
|
+
# @note override for sequencer injection
|
12
14
|
def values_sql_for_columns_and_attributes_with_turntable(columns, array_of_attributes)
|
13
15
|
connection_memo = connection
|
14
16
|
array_of_attributes.map do |arr|
|
@@ -1,8 +1,9 @@
|
|
1
1
|
begin
|
2
2
|
require 'acts_as_archive'
|
3
|
-
|
3
|
+
# acts_as_archive extension
|
4
4
|
class ActsAsArchive
|
5
5
|
class << self
|
6
|
+
# @note use the same shard which `from` shard using
|
6
7
|
def move_with_turntable(config, where, merge_options={})
|
7
8
|
if [config[:to], config[:from]].all? { |k| k.try(:turntable_enabled?) }
|
8
9
|
current_shard = config[:from].connection.current_shard.name.to_sym
|
@@ -20,6 +20,7 @@ module ActiveRecord::Turntable
|
|
20
20
|
|
21
21
|
private
|
22
22
|
|
23
|
+
# @note Override to add sharding condition for singular association
|
23
24
|
if ActiveRecord::Turntable.rails41_later?
|
24
25
|
def find_target_with_turntable
|
25
26
|
current_scope = scope
|
@@ -50,6 +51,7 @@ module ActiveRecord::Turntable
|
|
50
51
|
|
51
52
|
private
|
52
53
|
|
54
|
+
# @note Override to add sharding condition for collection association
|
53
55
|
def find_target_with_turntable
|
54
56
|
records =
|
55
57
|
if options[:finder_sql]
|
@@ -9,6 +9,7 @@ module ActiveRecord::Turntable
|
|
9
9
|
alias_method_chain :records_for, :turntable
|
10
10
|
end
|
11
11
|
|
12
|
+
# @note Override to add sharding condition on preload
|
12
13
|
def records_for_with_turntable(ids)
|
13
14
|
returning_scope = records_for_without_turntable(ids)
|
14
15
|
if should_use_shard_key?
|
@@ -9,6 +9,7 @@ module ActiveRecord::Turntable
|
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
+
# @note Override not to establish_connection destroy existing connection pool proxy object
|
12
13
|
def pool_for_with_turntable(owner)
|
13
14
|
owner_to_pool.fetch(owner.name) {
|
14
15
|
if ancestor_pool = pool_from_any_process_for(owner)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module ActiveRecord::Turntable::ActiveRecordExt
|
2
2
|
module Persistence
|
3
3
|
::ActiveRecord::Persistence.class_eval do
|
4
|
+
# @note Override to add sharding scope on reloading
|
4
5
|
def reload(options = nil)
|
5
6
|
clear_aggregation_cache
|
6
7
|
clear_association_cache
|
@@ -26,6 +27,7 @@ module ActiveRecord::Turntable::ActiveRecordExt
|
|
26
27
|
self
|
27
28
|
end
|
28
29
|
|
30
|
+
# @note Override to add sharding scope on `touch`
|
29
31
|
def touch(name = nil)
|
30
32
|
raise ActiveRecordError, "can not touch on a new record object" unless persisted?
|
31
33
|
|
@@ -58,6 +60,7 @@ module ActiveRecord::Turntable::ActiveRecordExt
|
|
58
60
|
|
59
61
|
private
|
60
62
|
|
63
|
+
# @note Override to add sharding scope on destroying
|
61
64
|
def relation_for_destroy
|
62
65
|
pk = self.class.primary_key
|
63
66
|
column = self.class.columns_hash[pk]
|
@@ -74,6 +77,8 @@ module ActiveRecord::Turntable::ActiveRecordExt
|
|
74
77
|
relation
|
75
78
|
end
|
76
79
|
|
80
|
+
|
81
|
+
# @note Override to add sharding scope on updating
|
77
82
|
ar_version = ActiveRecord::VERSION::STRING
|
78
83
|
if ar_version < "4.1"
|
79
84
|
method_name = ar_version =~ /\A4\.0\.[0-5]\z/ ? "update_record" : "_update_record"
|
@@ -15,6 +15,7 @@ module ActiveRecord::Turntable
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
# @note Override to add sharding scope on updating
|
18
19
|
def _update_record_with_turntable(values, id, id_was, turntable_scope = nil) # :nodoc:
|
19
20
|
substitutes, binds = substitute_values values
|
20
21
|
condition_scope = @klass.unscoped.where(@klass.arel_table[@klass.primary_key].eq(id_was || id))
|
@@ -16,6 +16,9 @@ module ActiveRecord::Turntable
|
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
19
|
+
# @param [Symbol] cluster_name cluster name for this class
|
20
|
+
# @param [Symbol] shard_key_name shard key attribute name
|
21
|
+
# @param [Hash] options
|
19
22
|
def turntable(cluster_name, shard_key_name, options = {})
|
20
23
|
class_attribute :turntable_shard_key,
|
21
24
|
:turntable_cluster, :turntable_cluster_name
|
@@ -34,6 +37,7 @@ module ActiveRecord::Turntable
|
|
34
37
|
turntable_define_cluster_methods(cluster_name)
|
35
38
|
end
|
36
39
|
|
40
|
+
#
|
37
41
|
def force_transaction_all_shards!(options={}, &block)
|
38
42
|
force_connect_all_shards!
|
39
43
|
shards = turntable_connections.values
|
@@ -172,10 +176,12 @@ module ActiveRecord::Turntable
|
|
172
176
|
self.class.shards_transaction(options, &block)
|
173
177
|
end
|
174
178
|
|
179
|
+
# @return [ActiveRecord::Turntable::Shard] current shard for self
|
175
180
|
def turntable_shard
|
176
181
|
turntable_cluster.shard_for(self.send(turntable_shard_key))
|
177
182
|
end
|
178
183
|
|
184
|
+
# @see ActiveRecord::Turntable::ConnectionProxy#with_shard
|
179
185
|
def with_shard(shard)
|
180
186
|
self.class.connection.with_shard(shard) { yield }
|
181
187
|
end
|
@@ -111,14 +111,22 @@ module ActiveRecord::Turntable
|
|
111
111
|
current_shard_entry[object_id] = shard
|
112
112
|
end
|
113
113
|
|
114
|
+
# @return connection of current shard
|
114
115
|
def connection
|
115
116
|
current_shard.connection
|
116
117
|
end
|
117
118
|
|
119
|
+
# @return connection_pool of current shard
|
118
120
|
def connection_pool
|
119
121
|
current_shard.connection_pool
|
120
122
|
end
|
121
123
|
|
124
|
+
# Fix connection to given shard in block
|
125
|
+
# @param [ActiveRecord::Base, Symbol, ActiveRecord::Turntable::Shard, Numeric, String] shard which you want to fix
|
126
|
+
# @param shard [ActiveRecord::Base] AR Object
|
127
|
+
# @param shard [Symbol] shard name symbol that defined in turntable.yml
|
128
|
+
# @param shard [ActiveRecord::Turntable::Shard] Shard object
|
129
|
+
# @param shard [String, Numeric] Raw sharding id
|
122
130
|
def with_shard(shard)
|
123
131
|
shard = cluster.to_shard(shard)
|
124
132
|
|
@@ -142,6 +150,8 @@ module ActiveRecord::Turntable
|
|
142
150
|
end
|
143
151
|
end
|
144
152
|
|
153
|
+
# Send queries to all shards in this cluster
|
154
|
+
# @param [Boolean] continue_on_error when a shard raises error, ignore exception and continue
|
145
155
|
def with_all(continue_on_error = false)
|
146
156
|
@cluster.shards.values.map do |shard|
|
147
157
|
begin
|
@@ -157,6 +167,8 @@ module ActiveRecord::Turntable
|
|
157
167
|
end
|
158
168
|
end
|
159
169
|
|
170
|
+
# Send queries to master connection and all shards in this cluster
|
171
|
+
# @param [Boolean] continue_on_error when a shard raises error, ignore exception and continue
|
160
172
|
def with_master_and_all(continue_on_error = false)
|
161
173
|
([@cluster.master] + @cluster.shards.values).map do |shard|
|
162
174
|
begin
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-turntable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gussan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -430,9 +430,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
430
430
|
version: '0'
|
431
431
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
432
432
|
requirements:
|
433
|
-
- - "
|
433
|
+
- - ">="
|
434
434
|
- !ruby/object:Gem::Version
|
435
|
-
version:
|
435
|
+
version: '0'
|
436
436
|
requirements: []
|
437
437
|
rubyforge_project: activerecord-turntable
|
438
438
|
rubygems_version: 2.2.2
|
@@ -480,3 +480,4 @@ test_files:
|
|
480
480
|
- spec/spec_helper.rb
|
481
481
|
- spec/support/matchers/be_saved_to.rb
|
482
482
|
- spec/support/turntable_helper.rb
|
483
|
+
has_rdoc:
|