Repository navigation
gprecoverseg: port the replay-lag check, --max-rate and stale-slot handling from Greenplum - #2184
MisterRaindrop wants to merge 3 commits into
Conversation
Surprisingly, in our internal installation we are doing opposite - we are increasing priority for pg_basebackup on source host. So, users workload doesn't prevent us from cluster repair. |
That makes sense, and this PR leaves it alone: |
b85b91b to
ce85c47
Compare
| port = primary_db.getSegmentPort() | ||
| host = primary_db.getSegmentHostName() | ||
| logger.debug('Get replay lag on mirror of primary segment with host:{}, port:{}'.format(host, port)) | ||
| sql = "select pg_wal_lsn_diff(flush_lsn, replay_lsn) from pg_stat_replication;" |
There was a problem hiding this comment.
Here we expect exact one row. But in a case of working pg_basebackup here will be other rows. We should either ignore it or fail with message that we cannot rebalance while basebackup still working on (clear message, not failed querySingleton function)
There was a problem hiding this comment.
Good catch, reproduced: with pg_basebackup -X stream running against the acting primary, pg_stat_replication had three rows and gprecoverseg -r failed with "SQL retrieved 3 rows but 1 was expected". The check now reads only the mirror's walsender (application_name = 'gp_walreceiver', as gpstate does), so a running basebackup no longer blocks the rebalance. If there is no mirror connection, or more than one, it fails and says so. The same rebalance now completes while the basebackup runs.
The fix is folded into the commit that ported this check (1eaffd8), and the branch is rebased onto main.
Rebalancing promotes the mirror and demotes the primary. If the mirror
still has a large amount of WAL left to replay, that promotion stalls
until it catches up, with the segment unavailable for the duration.
Greenplum guards against this by measuring the replay lag before
rebalancing a pair and refusing when it exceeds a limit. Cloudberry
carries the file this lives in but not the check: replay_lag(), the
block in rebalance() that calls it, the ALLOWED_REPLAY_LAG default and
the two options that drive it had all been dropped.
Port them back, so these two scenarios can run instead of being skipped:
gprecoverseg rebalance aborts and throws exception if replay lag on
mirror is more than or equal to the allowed limit
gprecoverseg errors out if invalid options are used with
--disable-replay-lag
cherry-pick from Greenplum Database, greenplum-db/gpdb-archive @ 482967c1b4:
gpMgmt/bin/gppylib/operations/rebalanceSegments.py
gpMgmt/bin/gppylib/programs/clsRecoverSegment.py
gpMgmt/bin/gppylib/commands/gp.py
gpMgmt/bin/gppylib/test/unit/test_unit_rebalance_segment.py
Deliberate departures from upstream:
- Greenplum reaches the same check through a differential-recovery code
path that Cloudberry does not have, so only the rebalance caller is
ported.
- replay_lag() reads only the mirror's walsender (application_name
gp_walreceiver, as gpstate does). Upstream expects pg_stat_replication
to hold exactly one row, so a pg_basebackup running against the primary
failed the rebalance with "SQL retrieved 3 rows but 1 was expected".
No mirror connection, more than one, or a NULL replay position now
fails with a message that says so.
Split out of apache#1639 (originally ad3c9d5).
A full recovery runs pg_basebackup, which will use whatever network
bandwidth it can get. On a cluster that is still serving queries that
can starve everything else, so Greenplum lets the operator cap it with
--max-rate, validated and then passed through to pg_basebackup.
Cloudberry has the same plumbing -- gprecoverseg builds a
GpMirrorListToBuild, which builds a GpSegRecovery command line, which
gpsegrecovery parses and turns into a PgBaseBackup -- but no maxRate
parameter anywhere along it. Add it at each hop, along with the
validation, the two "this flag is ignored with -r/-o" warnings, and the
"Maximum Transfer Rate" row in the recovery plan the scenario asserts on.
This lets the scenario run instead of being skipped:
gprecoverseg recovers segment for valid max-rate options and errors
out for others
cherry-pick from Greenplum Database, greenplum-db/gpdb-archive @ 482967c1b4:
gpMgmt/bin/gppylib/programs/clsRecoverSegment.py
gpMgmt/bin/gppylib/operations/buildMirrorSegments.py
gpMgmt/bin/gppylib/commands/gp.py
gpMgmt/bin/gppylib/commands/pg.py
gpMgmt/sbin/gpsegrecovery.py
gpMgmt/sbin/recovery_base.py
Two deliberate departures from upstream. Greenplum also threads maxRate
into its differential recovery path, which Cloudberry does not have.
And Cloudberry's FullRecovery retries pg_basebackup with --create-slot
when the first attempt fails on a cluster that never had mirrors;
upstream has no such retry, so the cap is applied to it too -- without
that the retry would silently ignore the limit the operator asked for.
The comment in gprecoverseg.feature that claimed Greenplum does not
implement this either was wrong; it goes when apache#2170 drops the tag.
Split out of apache#1639 (originally 993b99d).
… retry
A full recovery streams from the primary through the replication slot
internal_wal_replication_slot. pg_basebackup --create-slot fails if that
slot already exists, and PostgreSQL offers no way to reuse one.
Cloudberry worked around it by guessing: run pg_basebackup without
--create-slot, and if anything at all goes wrong, run the whole thing
again with it. That is expensive when the backup failed for an unrelated
reason -- the second attempt also forces forceoverwrite=True, discarding
the target directory -- and it leaves the slot handling implicit. The
code says as much:
GPDB_12_MERGE_FIXME could we check it before? or let
pg_basebackup create slot if not exists.
Greenplum answers that FIXME: ask the primary whether the slot is there,
drop it if so, and pass --create-slot once. Port PgReplicationSlot and
use it, in gpsegrecovery for gprecoverseg and in gpconfigurenewsegment
for gpexpand, dropping both retries.
Porting it into gpconfigurenewsegment is not optional. PgBaseBackup's
constructor now talks to the database, and there the second constructor
call sat inside an except block, so a failure to reach the primary would
have escaped from the handler rather than being reported.
This lets the last two skipped scenarios run, which also assert the
messages this prints:
gprecoverseg should drop existing slot on full recovery
<scenario> recovery should not try to drop slot if slot does not exist
With them, nothing in gprecoverseg.feature or gpmovemirrors.feature is
tagged @not_implemented any more.
cherry-pick from Greenplum Database, greenplum-db/gpdb-archive @ 482967c1b4:
gpMgmt/bin/gppylib/commands/pg.py
gpMgmt/sbin/gpsegrecovery.py
gpMgmt/bin/lib/gpconfigurenewsegment
Two things in gpconfigurenewsegment are fixed in passing, both found by
running open-code-review over this commit:
- It called PgBaseBackup with logfile=, a keyword that constructor has
never had, so the mirror path raised TypeError before doing anything.
Upstream has the same line and the same bug; nothing in either test
suite reaches it, because gpaddmirrors builds mirrors through
gpsegrecovery and only gpexpand comes this way. It is progress_file=.
- The constructor call sat outside the try below. Now that it talks to
the database it can fail, and a failure there returned no result at
all, which the worker pool reports as "'NoneType' object has no
attribute 'wasSuccessful'" long after the fact.
One deliberate departure from upstream: drop_slot() catches pgdb's
DatabaseError, not psycopg2's, because that is the driver Cloudberry's
dbconn is built on.
Split out of apache#1639 (originally 8377856).
ce85c47 to
e14c6f8
Compare
What does this PR do?
Ports three gprecoverseg features from Greenplum that the gpMgmt Behave suite (#2170) has scenarios for. Cloudberry carried the scenarios but not the code, so they had to be skipped. Three commits; each commit message gives the full reasoning and lists what is cherry-picked from greenplum-db/gpdb-archive @ 482967c1b4.
gprecoverseg -rpromotes a mirror, it measures how much WAL the mirror still has to replay, and refuses when that exceeds a limit, because the promotion would stall until replay caught up. This brings backreplay_lag(), the block inrebalance()that calls it, theALLOWED_REPLAY_LAGdefault, and the--replay-lagand--disable-replay-lagoptions.--max-rate. An optional cap on pg_basebackup's bandwidth during a full recovery, for when the recovery should not starve a cluster that is still serving queries. Without the option, pg_basebackup runs uncapped, as before. The value is validated and passed along gprecoverseg →GpMirrorListToBuild→gpsegrecovery→PgBaseBackup.pg_basebackup --create-slotfails ifinternal_wal_replication_slotalready exists. Cloudberry worked around that by running pg_basebackup without the flag and, on any failure, running the whole backup again with it and withforceoverwrite=True. The code's ownGPDB_12_MERGE_FIXMEasked for something better. Greenplum's answer is ported: ask the primary whether the slot exists, drop it if it does, and pass--create-slotonce. This applies ingpsegrecovery(gprecoverseg) and ingpconfigurenewsegment(gpexpand). Two bugs ingpconfigurenewsegmentare fixed in passing; the commit message has the details.Where each commit departs from upstream, its message says so and why: Greenplum's differential-recovery path does not exist here, and
drop_slot()catches PyGreSQL'sDatabaseErrorrather than psycopg2's.This builds on #2183 (gprecoverseg fixes, merged as 8101834): commit 3 touches the code that PR changed, and the scenarios assume its fixes. It is now rebased onto main and contains only its three commits.
Split out of #1639 (originally ad3c9d5, 993b99d and 8377856, by @tuhaihe).
Changes from #1639:
test_complete_workflow_exceptionstill expected pg_basebackup to fail twice, which commit 3 makes impossible. It failed once CI: add gpMgmt Behave test #1639's other test changes were in. It now expects one attempt and one error.@not_implementedtoday. That stops being true once CI: run the gpMgmt Behave suite #2170 tags the gpcheckcat-xscenario, so that edit is left out.Why one PR for three ports: #1639 carried 19 fixes. Opening one PR per fix would leave a long queue of tiny PRs for reviewers, so the remaining ones are grouped by area into five PRs (this one, #2178, #2180, #2183 and #2182). The commits are kept separate on purpose, so please merge this with "Rebase and merge" rather than squash.
Test Plan
Rocky 9 build image, built from #2170's tree plus #2177, #2178, #2180 and #2183, with a demo cluster created the way the Behave workflow creates it. In
gprecoverseg.featureI untagged the scenarios these three commits make runnable, then ran it with CI's arguments.gprecoverseg.feature(--tags ~@concourse_cluster --tags ~@extended --tags ~@differential --tags ~@not_implemented)gpmovemirrors.feature(--tags ~@concourse_cluster --tags ~@extended)gpaddmirrors.feature(--tags ~@concourse_cluster)gpmovemirrors and gpaddmirrors are there to show nothing regressed. Both build mirrors through the full-recovery path in
gpsegrecoverythat commit 3 changes.Without this PR, every one of these scenarios that runs fails:
Checking if slot internal_wal_replication_slot exists.error: transfer rate 30 is out of range.The max-rate failure leaves the mirrors down, so the next scenario fails on
all segments are not currently running, and the one after waits forever onuser can start transactions. That is why run A timed out. The two replay-lag scenarios come later in the file and were never reached. #2170 therefore tags these five scenarios@needs_fixone by one, so a missing feature cannot hang the rest of the job.Unit tests (
python3 -m unittest, withPYTHONPATHset the waymake -C gpMgmt/bin unitdevelsets it):test_unit_rebalance_segment,test_unit_gpsegrecoveryandtest_unit_pg_base_backuppass. Across the wholegppylibsuite, this PR adds no failures. It fixes threetest_unit_rebalance_segmenttests that fail without it, because they test the replay-lag check. Intest_unit_gprecoverseg,test_gprecoverseg_with_mirrorlesserrors with and without this PR: its mockgpArrayhas nostandbyCoordinator. I have not looked into the other tests that fail either way.#2170 tagged the scenarios these commits make runnable
@needs_fix, each pointing at its #1639 commit. This PR removes those five tags. CI runs three of them; the two replay-lag scenarios are tagged@concourse_cluster, which CI skips, so I ran them separately on a fresh demo cluster: 2 passed, 0 failed.Type of Change
Checklist