neondatabase / neon

Neon: Serverless Postgres. We separated storage and compute to offer autoscaling, code-like database branching, and scale to zero.
https://neon.tech
Apache License 2.0
15.15k stars 442 forks source link

Support asynchronous replication #4296

Open knizhnik opened 1 year ago

knizhnik commented 1 year ago

Steps to reproduce

Neon now supports read-only replicas which are streaming WAL from safekeeper. So safekeeper has multiple subscribers and receives standby reply / hot-stanby feeback from all of them. Right now safekeerp merge hot-standaby feedbacks:

                let hs_feedback = standby_feedback.hs_feedback;
                // doing Option math like op1.iter().chain(op2.iter()).min()
                // would be nicer, but we serialize/deserialize this struct
                // directly, so leave as is for now
                if hs_feedback.xmin != INVALID_FULL_TRANSACTION_ID {
                    if agg.xmin != INVALID_FULL_TRANSACTION_ID {
                        agg.xmin = min(agg.xmin, hs_feedback.xmin);
                    } else {
                        agg.xmin = hs_feedback.xmin;
                    }
                    agg.ts = min(agg.ts, hs_feedback.ts);
                }

But I failed to ind code where it is merging StandbyReply (write/commit/flush LSNs). Looks like now safe keeper is forwarding all replies to master node. It seems to e not correct, because some of RO replicas can proceed WAL faster than master pageserver. But just taken min of all replies is also not a good solution, because in this case lagged replica can cause throttling of master compute node.

Expected result

Actual result

Environment

Logs, links

jcsp commented 4 days ago

@arssher is this issue still something we should be thinking about?