Class: Couchbase::GetReplicaStrategy
- Inherits:
-
Object
- Object
- Couchbase::GetReplicaStrategy
- Defined in:
- lib/couchbase/get_replica_strategy.rb,
/home/runner/work/couchbase-ruby-client/couchbase-ruby-client/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 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 |