Module: ActiveRecord::Turntable::Base::ClassMethods
- Defined in:
- lib/active_record/turntable/base.rb
Instance Method Summary collapse
- #current_last_shard ⇒ Object
- #sequencer(sequencer_name, *args) ⇒ Object
- #sequencer_enabled? ⇒ Boolean
- #sharding_condition_needed? ⇒ Boolean
- #turntable(cluster_name, shard_key_name, options = {}) ⇒ Object
- #turntable_cluster ⇒ Object
- #turntable_enabled? ⇒ Boolean
- #turntable_pool_list ⇒ Object
- #turntable_replace_connection_pool ⇒ Object
- #turntable_sequencer ⇒ Object
- #with_master ⇒ Object
- #with_shard(any_shard) ⇒ Object
- #with_slave ⇒ Object
Instance Method Details
#current_last_shard ⇒ Object
93 94 95 |
# File 'lib/active_record/turntable/base.rb', line 93 def current_last_shard turntable_cluster.select_shard(current_sequence_value) if sequencer_enabled? end |
#sequencer(sequencer_name, *args) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/active_record/turntable/base.rb', line 67 def sequencer(sequencer_name, *args) class_attribute :turntable_sequencer_name class << self prepend ActiveRecordExt::Sequencer end self.turntable_sequencer_enabled = true self.turntable_sequencer_name = sequencer_name end |
#sequencer_enabled? ⇒ Boolean
89 90 91 |
# File 'lib/active_record/turntable/base.rb', line 89 def sequencer_enabled? turntable_sequencer_enabled end |
#sharding_condition_needed? ⇒ Boolean
85 86 87 |
# File 'lib/active_record/turntable/base.rb', line 85 def sharding_condition_needed? turntable_enabled? && primary_key != turntable_shard_key.to_s end |
#turntable(cluster_name, shard_key_name, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/active_record/turntable/base.rb', line 41 def turntable(cluster_name, shard_key_name, = {}) class_attribute :turntable_shard_key, :turntable_cluster_name self.turntable_enabled = true self.turntable_cluster_name = cluster_name self.turntable_shard_key = shard_key_name turntable_replace_connection_pool end |
#turntable_cluster ⇒ Object
50 51 52 |
# File 'lib/active_record/turntable/base.rb', line 50 def turntable_cluster turntable_clusters[turntable_cluster_name] end |
#turntable_enabled? ⇒ Boolean
81 82 83 |
# File 'lib/active_record/turntable/base.rb', line 81 def turntable_enabled? turntable_enabled end |
#turntable_pool_list ⇒ Object
54 55 56 |
# File 'lib/active_record/turntable/base.rb', line 54 def turntable_pool_list turntable_clusters.values.map { |cluster| cluster.shards.map(&:connection_pool) }.flatten.uniq end |
#turntable_replace_connection_pool ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/active_record/turntable/base.rb', line 58 def turntable_replace_connection_pool ch = connection_handler cp = ConnectionProxy.new(self, turntable_cluster) pp = PoolProxy.new(cp) self.connection_specification_name = "turntable_pool_proxy::#{name}" ch.owner_to_turntable_pool[connection_specification_name] = pp end |
#turntable_sequencer ⇒ Object
77 78 79 |
# File 'lib/active_record/turntable/base.rb', line 77 def turntable_sequencer turntable_sequencers[turntable_sequencer_name] end |
#with_master ⇒ Object
113 114 115 |
# File 'lib/active_record/turntable/base.rb', line 113 def with_master connection.with_master { yield } end |
#with_shard(any_shard) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/active_record/turntable/base.rb', line 97 def with_shard(any_shard) shard = case any_shard when Numeric turntable_cluster.shard_for(any_shard) when ActiveRecord::Base turntable_cluster.shard_for(any_shard.send(any_shard.turntable_shard_key)) else shard_or_key end connection.with_shard(shard) { yield } end |
#with_slave ⇒ Object
109 110 111 |
# File 'lib/active_record/turntable/base.rb', line 109 def with_slave connection.with_slave { yield } end |