Class: Couchbase::GetReplicaStrategy
- Inherits:
-
Object
- Object
- Couchbase::GetReplicaStrategy
- Defined in:
- lib/couchbase/get_replica_strategy.rb
Overview
Selects the replica that Collection#get_replica reads from.
Instance Attribute Summary collapse
-
#index ⇒ Symbol
readonly
The requested replica, one of
:first,:secondor:third. -
#wrap ⇒ Boolean
readonly
Whether an index that cannot be read resolves to the next replica that can.
Class Method Summary collapse
-
.from_index(index, wrap: false) ⇒ GetReplicaStrategy
Selects the replica at the given index.
Instance Method Summary collapse
-
#initialize(index, wrap) ⇒ GetReplicaStrategy
constructor
private
A new instance of GetReplicaStrategy.
- #to_backend ⇒ Object private
Constructor Details
#initialize(index, wrap) ⇒ GetReplicaStrategy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of GetReplicaStrategy.
75 76 77 78 79 |
# File 'lib/couchbase/get_replica_strategy.rb', line 75 def initialize(index, wrap) @index = index @wrap = wrap freeze end |
Instance Attribute Details
#index ⇒ Symbol (readonly)
Returns the requested replica, one of :first, :second or :third.
28 29 30 |
# File 'lib/couchbase/get_replica_strategy.rb', line 28 def index @index end |
#wrap ⇒ Boolean (readonly)
Returns whether an index that cannot be read resolves to the next replica that can.
31 32 33 |
# File 'lib/couchbase/get_replica_strategy.rb', line 31 def wrap @wrap end |
Class Method Details
.from_index(index, wrap: false) ⇒ GetReplicaStrategy
Selects the replica at the given index.
Without wrap, the SDK resolves the index against the vbucket map it already holds. No network round trip
is made for these two errors:
- an index at or beyond the bucket's configured replica count raises Error::ReplicaIndexOutOfBounds
- a configured replica the vbucket map places on no node raises Error::ReplicaIndexCurrentlyUnavailable
The replica is chosen from the vbucket map, not from node health. A replica on a node that is down is still chosen. The read can then wait for that node until the read times out.
65 66 67 68 69 70 71 72 |
# File 'lib/couchbase/get_replica_strategy.rb', line 65 def self.from_index(index, wrap: false) unless REPLICA_INDEXES.key?(index) raise Error::InvalidArgument, "replica index must be one of #{REPLICA_INDEXES.keys.inspect}, but given #{index.inspect}" end raise Error::InvalidArgument, "wrap must be a Boolean, but given #{wrap.inspect}" unless [true, false].include?(wrap) new(index, wrap) end |
Instance Method Details
#to_backend ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 85 86 87 |
# File 'lib/couchbase/get_replica_strategy.rb', line 82 def to_backend { replica_index: REPLICA_INDEXES.fetch(@index), wrap: @wrap, } end |