Thanks you for the comments! At Wed, 1 Nov 2023 18:08:19 +1100, Peter Smith <smithpb2...@gmail.com> wrote in > Hi, here are some minor review comments for the v3 patch. > > ====== > src/backend/access/transam/xlog.c
> I asked ChatGPT to suggest alternative wording for that comment, and > it came up with something that I felt was a slight improvement. > > SUGGESTION > ... > If WALs needed by logical replication slots are deleted, these slots > become inoperable. During a binary upgrade, pg_upgrade sets this > variable to -1 via the command line in an attempt to prevent such > deletions, but users have ways to override it. To ensure the > successful completion of the upgrade, it's essential to keep this > variable unaltered. > ... > > ~~~ ChatGPT seems to tend to generate sentences in a slightly different from our usual writing. While I tried to retain the original phrasing in the patch, I don't mind using the suggested version. Used as is. > 2. > + GUC_check_errdetail("\"max_slot_wal_keep_size\" must be set to -1 > during binary upgrade mode."); > Some of the other GUC_check_errdetail()'s do not include the GUC name > in the translatable message text. Isn't that a preferred style? > SUGGESTION > GUC_check_errdetail("\"%s\" must be set to -1 during binary upgrade mode.", > "max_slot_wal_keep_size"); I believe that that style was adopted to minimize translatable messages by consolidting identical ones that only differ in variable names. I see both versions in the tree. I didn't find necessity to adopt this approach for this specific message, especially since I'm skeptical about adding new messages that end with "must be set to -1 during binary upgrade mode". (pg_upgrade sets synchronous_commit, fsync and full_page_writes to "off".) However, some unique messages are in this style, so I'm fine with using that style. Revised accordingly. > ====== > src/backend/replication/slot.c > > 3. InvalidatePossiblyObsoleteSlot > + Assert (!*invalidated || !SlotIsLogical(s) || !IsBinaryUpgrade); > > IMO new Assert became trickier to understand than the original condition. > YMMV. > > SUGGESTION > Assert(!(*invalidated && SlotIsLogical(s) && IsBinaryUpgrade)); Yeah, I also liked that style and considered using it, but I didn't feel it was too hard to read in this particular case, so I ended up using the current way. Just like with the point of other comments, I'm not particularly attached to this style. Thus if someone find it difficult to read, I have no issue with changing it. Revised as suggested. regards. -- Kyotaro Horiguchi NTT Open Source Software Center
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index b541be8eec..46833f6ecd 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -2063,6 +2063,29 @@ check_wal_segment_size(int *newval, void **extra, GucSource source) return true; } +/* + * GUC check_hook for max_slot_wal_keep_size + * + * If WALs needed by logical replication slots are deleted, these slots become + * inoperable. During a binary upgrade, pg_upgrade sets this variable to -1 via + * the command line in an attempt to prevent such deletions, but users have + * ways to override it. To ensure the successful completion of the upgrade, + * it's essential to keep this variable unaltered. See + * InvalidatePossiblyObsoleteSlot() and start_postmaster() in pg_upgrade for + * more details. + */ +bool +check_max_slot_wal_keep_size(int *newval, void **extra, GucSource source) +{ + if (IsBinaryUpgrade && *newval != -1) + { + GUC_check_errdetail("\"%s\" must be set to -1 during binary upgrade mode.", + "max_slot_wal_keep_size"); + return false; + } + return true; +} + /* * At a checkpoint, how many WAL segments to recycle as preallocated future * XLOG segments? Returns the highest segment that should be preallocated. diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 99823df3c7..5c3d2b1082 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -1424,18 +1424,12 @@ InvalidatePossiblyObsoleteSlot(ReplicationSlotInvalidationCause cause, SpinLockRelease(&s->mutex); /* - * The logical replication slots shouldn't be invalidated as - * max_slot_wal_keep_size GUC is set to -1 during the upgrade. - * - * The following is just a sanity check. + * check_max_slot_wal_keep_size() ensures max_slot_wal_keep_size is set + * to -1, so, slot invalidation for logical slots shouldn't happen + * during an upgrade. At present, only logical slots really require + * this. */ - if (*invalidated && SlotIsLogical(s) && IsBinaryUpgrade) - { - ereport(ERROR, - errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("replication slots must not be invalidated during the upgrade"), - errhint("\"max_slot_wal_keep_size\" must be set to -1 during the upgrade")); - } + Assert (!(*invalidated && SlotIsLogical(s) && IsBinaryUpgrade)); if (active_pid != 0) { diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c index 7605eff9b9..818ffdb2ae 100644 --- a/src/backend/utils/misc/guc_tables.c +++ b/src/backend/utils/misc/guc_tables.c @@ -2845,7 +2845,7 @@ struct config_int ConfigureNamesInt[] = }, &max_slot_wal_keep_size_mb, -1, -1, MAX_KILOBYTES, - NULL, NULL, NULL + check_max_slot_wal_keep_size, NULL, NULL }, { diff --git a/src/include/utils/guc_hooks.h b/src/include/utils/guc_hooks.h index 2a191830a8..3d74483f44 100644 --- a/src/include/utils/guc_hooks.h +++ b/src/include/utils/guc_hooks.h @@ -84,6 +84,8 @@ extern bool check_maintenance_io_concurrency(int *newval, void **extra, extern void assign_maintenance_io_concurrency(int newval, void *extra); extern bool check_max_connections(int *newval, void **extra, GucSource source); extern bool check_max_wal_senders(int *newval, void **extra, GucSource source); +extern bool check_max_slot_wal_keep_size(int *newval, void **extra, + GucSource source); extern void assign_max_wal_size(int newval, void *extra); extern bool check_max_worker_processes(int *newval, void **extra, GucSource source);