Hi there,
This is more of a subjective question so I would appreciate anyone’s thoughts on the subject. I’ve gone through all the documentation I can find on error handling and failure scenarios, but don’t see much official guidance on when I should consider trying GetFromReplica if my result is failed. The one code example I see shows using it with a KeyNotFound operation result, but I can’t tell if that’s just a random example or what is recommended. My anecdotal experience tells me that the vast majority of when GetFromReplica would help is on a timeout.
I have two thoughts on how I should be utilizing it, curious what you think:
The most protective method I thought of uses ShouldRetry as well as GetFromReplica. I’m not sure if ShouldRetry() is even needed, I know the client handles some retries on it’s own. This has the worst potential performance, but seems like the “safest” way to handle failure if I can’t tolerate it:
private T InternalGet(bool retry = false)
{
var result = _couchbaseBucket.Get<T>(“key”);if (!result.Success) { if (result.ShouldRetry() && !retry) //only retry once { return InternalGet(true); } else { var replicaResult = _couchbaseBucket.GetFromReplica<T>("key"); if (!replicaResult.Success) { //some custom exception throw new CouchbaseGetException(); } return replicaResult.Value; } } return result.Value; }
The second way just ignores ShouldRetry() and goes straight to the replica. This seems a little broad to me as there are probably some operation results that retrying on replica will not have any effect.
private T InternalGet()
{
var result = _couchbaseBucket.Get<T>(GetKey());if (!result.Success)
{
var replicaResult = _couchbaseBucket.GetFromReplica<T>(“key”);if (!replicaResult.Success) { //some custom exception throw new CouchbaseGetException(); } return replicaResult.Value;
}
return result.Value;
}
sorry the formatting is a little funky on these snippets.