We are using couchbase trying out couchbase but now we are facing two problems regarding fallbacks/failover and we need some support here.
We are using the following setup:
3 couchbase machines with the replication factor of 2.
Version 4.5.0-2601 Enterprise Edition (build-2601).
libcouchbase runtime version 2.6.3
libcouchbase headers version 2.6.1
how can i read the information from one replica? We are using the follow code but the “getFromReplica” method returns nothing (and we don’t see any activity in the couchbase web interface regarding the get).
First of all, when you size your cluster, if you want to support one node failure with 2 replica copies you will need at least 4 nodes. Otherwise, in case of node failure, you cannot write data since you cannot make two copies.
Second, Couchbase support “Read your own write” (RYOW) but it works when reading from the primary copy, that is why best practice is to read always from the primary, and read from replica only in case of failure.
In your example, you can try upsert with option replicate_to = 2. In that way write operation should block until replica is done.
Regarding 2), it is normal that in case of a node failure, 1/n of the reads will timeout. In that case you can catch the error and read fro replica.
For writing, 1/n of the writing will fail. You can implement a retry strategy in your client code to assure that you will write after the failover happens. From that point all works fine again.
That is a CP scenario in terms of the CAP theorem. In this case Couchbase works as CP, giving Consistency precedence over Availability.
Examples in this repository contain one for durability
For example exponential backoff when you which will increase wait intervals for some point and then keeps retrying on some fixed interval until maximum retry limit reached and then return error to application.