Class: Cassandra::LoadBalancing::Policies::TokenAware
- Inherits:
-
Cassandra::LoadBalancing::Policy
- Object
- Cassandra::LoadBalancing::Policy
- Cassandra::LoadBalancing::Policies::TokenAware
- Extended by:
- Forwardable
- Defined in:
- lib/cassandra/load_balancing/policies/token_aware.rb
Instance Method Summary collapse
-
#distance(host) ⇒ Object
Delegates to wrapped policy.
-
#host_down(host) ⇒ Object
Delegates to wrapped policy.
-
#host_found(host) ⇒ Object
Delegates to wrapped policy.
-
#host_lost(host) ⇒ Object
Delegates to wrapped policy.
-
#host_up(host) ⇒ Object
Delegates to wrapped policy.
-
#initialize(wrapped_policy, shuffle = true) ⇒ TokenAware
constructor
A new instance of TokenAware.
- #plan(keyspace, statement, options) ⇒ Object
- #setup(cluster) ⇒ Object
- #teardown(cluster) ⇒ Object
Constructor Details
#initialize(wrapped_policy, shuffle = true) ⇒ TokenAware
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.
Returns a new instance of TokenAware.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 101 def initialize(wrapped_policy, shuffle = true) methods = [:host_up, :host_down, :host_found, :host_lost, :setup, :teardown, :distance, :plan] Util.assert_responds_to_all(methods, wrapped_policy) do "supplied policy must respond to #{methods.inspect}, but doesn't" end @policy = wrapped_policy @shuffle = !!shuffle end |
Instance Method Details
#distance(host) ⇒ Object
Delegates to wrapped policy
88 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 88 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#host_down(host) ⇒ Object
Delegates to wrapped policy
88 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 88 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#host_found(host) ⇒ Object
Delegates to wrapped policy
88 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 88 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#host_lost(host) ⇒ Object
Delegates to wrapped policy
88 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 88 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#host_up(host) ⇒ Object
Delegates to wrapped policy
88 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 88 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#plan(keyspace, statement, options) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 125 def plan(keyspace, statement, ) return @policy.plan(keyspace, statement, ) unless @cluster replicas = @cluster.find_replicas(keyspace, statement) return @policy.plan(keyspace, statement, ) if replicas.empty? replicas = if @shuffle replicas.shuffle else replicas.dup end Plan.new(replicas, @policy, keyspace, statement, ) end |
#setup(cluster) ⇒ Object
113 114 115 116 117 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 113 def setup(cluster) @cluster = cluster @policy.setup(cluster) nil end |
#teardown(cluster) ⇒ Object
119 120 121 122 123 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 119 def teardown(cluster) @cluster = nil @policy.teardown(cluster) nil end |