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
Methods inherited from Cassandra::LoadBalancing::Policy
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.
102 103 104 105 106 107 108 109 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 102 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) { "supplied policy must respond to #{methods.inspect}, but doesn't" } @policy = wrapped_policy @shuffle = !!shuffle end |
Instance Method Details
#distance(host) ⇒ Object
Delegates to wrapped policy
89 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 89 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#host_down(host) ⇒ Object
Delegates to wrapped policy
89 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 89 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#host_found(host) ⇒ Object
Delegates to wrapped policy
89 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 89 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#host_lost(host) ⇒ Object
Delegates to wrapped policy
89 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 89 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#host_up(host) ⇒ Object
Delegates to wrapped policy
89 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 89 def_delegators :@policy, :distance, :host_found, :host_up, :host_down, :host_lost |
#plan(keyspace, statement, options) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 123 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? if @shuffle replicas = replicas.shuffle else replicas = replicas.dup end Plan.new(replicas, @policy, keyspace, statement, ) end |
#setup(cluster) ⇒ Object
111 112 113 114 115 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 111 def setup(cluster) @cluster = cluster @policy.setup(cluster) nil end |
#teardown(cluster) ⇒ Object
117 118 119 120 121 |
# File 'lib/cassandra/load_balancing/policies/token_aware.rb', line 117 def teardown(cluster) @cluster = nil @policy.teardown(cluster) nil end |