Repository navigation
Replies: 5 comments
|
So, new to K8s operators but the source code is quite readable. There is a lot of psql experience behind the cnpg team, so perhaps my opinions on administering psql are wrong/outdated, but I'd like to learn, and would appreciate corrections/comments on the following. I do really like how easy cnpg is to use and I find the arguments for using it leveraging k8s very compelling, however: Synchronous replication is done by simply shoving all The reconciliation loop creates a sorted list of instances, first the primary, then the replicas in order of most-up-to-date. All instances not available are filtered from this list. If the first item in this list is then not the current (wanted) primary, then the first item in the list gets promoted to primary. There are, as far as I can tell, no constraints on this. Meaning, if you have a 3 month old stale replica that happens to ever show up on top of the list (see my initial comment) then cnpg will happily throw away all writes that happened in those 3 months. This ensures availability, and you could argue there would be backups of the "actual" primary timeline, but at this point you have a forked timeline and very confused and angry users. Even for asynchronous replicas this possibility would make me very nervous. When it comes to the synchronous case you'd never want this to happen. You want to wait for the primary to come back online, but since this could take time, or may not even be possible, you can promote a known synchronous standby (I mean, that is what synchronous replication was designed for). If you are using quorum writes, then you can only fail over to a synchronous standby if all standbys in the quorum are available, since only then can you compare LSNs to see which one is the most up to date (the one who acknowledged the very last commit). The cluster can only resume if either the primary comes back or all synchronous standbys are available. If you also lose a standby, you can not safely resume without risking data loss. Having a designated synchronous standby ( I want to mention how Patroni handles this, not to argue it is better or not, but to point out that these issues are worth considering. Patroni has constraints on promoting replicas while using synchronous replication, and there are constraints on the maximum allowed data loss if promoting a replica (so you can say no more than 5 minutes out of date or else wait for an administrator - of course if a more appropriate replica, or the original primary, comes back you can still resume the cluster so it would still automatically recover from transient problems). I believe the least disruptive change (and quickest, that I would probably be able to work on if cnpg would consider including such a change) would be for the failover in case of synchronous replication to only promote a replica if it can be determined to contain the last commit of the primary. This means all replicas that were available at the moment the primary disappeared must be available for inspection (who has the latest commit). If this can not be determined, or if there were no synchronous standbys, there will be no failover until either a) the primary comes back, or b) the required replica(s) come back, or c) the DBA manually promotes a replica. Ideally, cnpg could maintain a pool of |
|
Question: This page (https://cloudnative-pg.io/documentation/1.20/operator_capability_levels/#zero-data-loss-clusters-through-synchronous-replication) has the formula |
|
Hello @Dennis4b, This looks more like a discussion than an issue yet, since there's a lot of discussion to clean before doing anything. Regards! |
|
@Dennis4b did you find any solution since we are running into exactly this behaviour? |
|
Any updates about this issue? |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
It appears that, despite running a cluster having 2 synchronous replicas, a sequence of transitory events (i.e. no permanent disk errors or such) can cause data loss, and I wonder if this is intentional.
tl;dr; version: if nodes fail and then recover in a certain order, an out of date replica can assume the role of primary. Every transaction committed since this replica went offline, and this can be a long time since the remaining two nodes would have continued working, is then lost.
This is a condition Patroni explicitly guards against:
To reproduce:
A database:
which, with a few rows of data, results in:
To simulate failures I set the ZFS dataset to readonly on the corresponding node, something like:
Fail
test-2, then:Fail
test-1, then:(This works because CNPG will allow a standalone primary, see bottom notes. This transaction is thus only ever committed on
test-3)And finally fail
test-3:Now let's assume our provider had a bad day, and slowly the nodes are getting back up, first
test-2:Because
test-2has assumed the role of primary, we have lost the last 2 INSERTs. Recoveringtest-1andtest-3:works, but those transactions are lost.
There are 2 parts to this:
CNPG loosens synchronous constraints when no replicas are available. This may/may not be appropriate for some. In my case I would agree this is reasonable, the only permanent data loss scenario in this case would be if the disks of the primary are permanently lost, but I consider this unlikely to happen simultaneously to either provider issues or disk issues on both other nodes (i.e. if nodes drop out like this it's more likely power or network and transient).
CNPG allows a node which was not previously a primary or a synchronous (up to date!) standby to become primary, with potential data loss. For my case I do not want to this to happen or be possible, if this happens the (IMHO) only acceptable automatic recovery is waiting for the original primary, or a fully up to date synchronous standby (which due to 1. and the commit quorum is difficult to guarantee), to recover. Anything else should require manual intervention.
I know risk tolerance is subjective, and "we prioritize availability over all else" is a valid standpoint, am just curious if I am missing something. IMHO if you choose to use synchronous replication it's because you care very much about durability of committed transactions.
All reactions