class Cassandra::LoadBalancing::Policies::TokenAware
Public Class Methods
new(wrapped_policy, shuffle = true)
click to toggle source
@param wrapped_policy [Cassandra::LoadBalancing::Policy] actual
policy to filter
@param shuffle [Boolean] (true) whether or not to shuffle the replicas
@note If replicas are not shuffled (`shuffle = false`), then it is
possibile to create hotspots in a write-heavy scenario, where most of the write requests will be handled by the same node(s). The default behavior of shuffling replicas helps mitigate this by universally distributing write load between replicas. However, it under-utilizes read caching and forces multiple replicas to cache the same read statements.
# File lib/cassandra/load_balancing/policies/token_aware.rb 101 def initialize(wrapped_policy, shuffle = true) 102 methods = [:host_up, :host_down, :host_found, :host_lost, :setup, :teardown, 103 :distance, :plan] 104 105 Util.assert_responds_to_all(methods, wrapped_policy) do 106 "supplied policy must respond to #{methods.inspect}, but doesn't" 107 end 108 109 @policy = wrapped_policy 110 @shuffle = !!shuffle 111 end
Public Instance Methods
inspect()
click to toggle source
@private
# File lib/cassandra/load_balancing/policies/token_aware.rb 141 def inspect 142 "#<#{self.class.name}:0x#{object_id.to_s(16)} " \ 143 "policy=#{@policy.inspect}, " \ 144 "shuffle=#{@shuffle.inspect}>" 145 end
plan(keyspace, statement, options)
click to toggle source
# File lib/cassandra/load_balancing/policies/token_aware.rb 125 def plan(keyspace, statement, options) 126 return @policy.plan(keyspace, statement, options) unless @cluster 127 128 replicas = @cluster.find_replicas(keyspace, statement) 129 return @policy.plan(keyspace, statement, options) if replicas.empty? 130 131 replicas = if @shuffle 132 replicas.shuffle 133 else 134 replicas.dup 135 end 136 137 Plan.new(replicas, @policy, keyspace, statement, options) 138 end
setup(cluster)
click to toggle source
# File lib/cassandra/load_balancing/policies/token_aware.rb 113 def setup(cluster) 114 @cluster = cluster 115 @policy.setup(cluster) 116 nil 117 end
teardown(cluster)
click to toggle source
# File lib/cassandra/load_balancing/policies/token_aware.rb 119 def teardown(cluster) 120 @cluster = nil 121 @policy.teardown(cluster) 122 nil 123 end