Repository navigation
RCBC-558: Add Collection#get_replica - #257
Merged
Merged
Conversation
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 7, 2026 18:29
c5696aa to
d268566
Compare
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 7, 2026 23:44
d268566 to
d8b8999
Compare
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 7, 2026 23:48
d8b8999 to
4693e4f
Compare
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 16, 2026 22:27
4693e4f to
ca38654
Compare
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 16, 2026 22:32
ca38654 to
da242f8
Compare
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 16, 2026 22:37
da242f8 to
3f1155b
Compare
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 16, 2026 23:17
3f1155b to
37b8f91
Compare
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 16, 2026 23:38
37b8f91 to
12a0b7f
Compare
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 20, 2026 19:35
12a0b7f to
00796db
Compare
Motivation ---------- Collection#get_any_replica returns whichever copy of a document answers first. A caller cannot read a named replica. RFC-0053 adds GetReplica: a single-replica read that takes the document id and a strategy that selects the replica. Modifications ------------- Collection#get_replica takes a GetReplicaStrategy. GetReplicaStrategy.from_index accepts :first, :second or :third and a Boolean wrap flag. Any other value raises Error::InvalidArgument before a request is sent. Three new errors report why a replica read fails: - ReplicaIndexOutOfBounds: the bucket is not configured with the requested replica. - ReplicaIndexCurrentlyUnavailable: the bucket is configured with it, but no node holds that replica right now. - DocumentNotFoundOnReplica: the replica does not hold the document. It subclasses DocumentNotFound, so a rescue of the general condition still matches it. The core resolves the index against the vbucket map it already holds. The read therefore raises either replica-index error without a network round trip. The index is checked against the configured replica count. During a rebalance, a shorter replica chain reports ReplicaIndexCurrentlyUnavailable. With wrap, an index that cannot be read resolves to the next readable replica. A bucket without replicas still raises ReplicaIndexOutOfBounds. If no replica is readable, it still raises ReplicaIndexCurrentlyUnavailable. The replica is chosen from the vbucket map, which RFC-0053 specifies. Node health is not consulted: - A replica on a node that is down is still chosen until that node is failed over. - The read can then wait for that node until the read times out. - A read that starts after the failover raises ReplicaIndexCurrentlyUnavailable, or moves on with wrap. - The from_index documentation shows how to bound the wait: a short timeout, then get_any_replica. couchbase2:// raises FeatureNotAvailable. The gateway does not carry the operation. CI creates a second bucket with three replicas on its three KV nodes. Its third replica has no node. Results ------- Integration tests read every replica the bucket places on a node. They cover each error and both wrap cases. They do not check which node served a read. The tests that need an unplaced replica skip when no bucket has one.
avsej
force-pushed
the
rcbc-558-get-replica
branch
from
October 20, 2026 19:55
00796db to
020e84d
Compare
DemetrisChr
approved these changes
Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Implements RCBC-558:
Collection#get_replica, defined by RFC-0053.Problem
Collection#get_any_replicareturns whichever copy answers first. An application cannot read one particular replica.Change
GetReplicaStrategy.from_indexaccepts:first,:secondor:third. Any other index raisesError::InvalidArgumentbefore a request is sent. So does awrapthat is not a Boolean.Error::ReplicaIndexOutOfBounds: the bucket is configured with fewer replicas than the index asks for, e.g.:thirdwith two.Error::ReplicaIndexCurrentlyUnavailable: the bucket is configured with that replica, but no node holds it right now.Error::ReplicaIndexCurrentlyUnavailable.Error::DocumentNotFoundOnReplica: the replica does not have the document. It is a subclass ofError::DocumentNotFound, sorescue Error::DocumentNotFoundstill catches it.replica?is alwaystrueon the result. This read never goes to the active copy.couchbase2://raisesError::FeatureNotAvailable. The Couchbase gateway has no single-replica read.With
wrap: true, the read moves on instead of failing::thirdon a bucket with one replica reads the first replica.Error::ReplicaIndexOutOfBounds.Error::ReplicaIndexCurrentlyUnavailable.RFC-0053 specifies where the replica comes from:
Node health is not consulted:
wrap.Error::ReplicaIndexCurrentlyUnavailable, or moves to the next replica withwrap.GetReplicaStrategy.from_indexdocumentation shows how to bound the wait: a short timeout, thenget_any_replica.