Re: [PATCH] Report changes discarded for relations not in the subscription

From: Peter Smith <smithpb2250(at)gmail(dot)com>
To: Hüseyin Demir <huseyin(dot)d3r(at)gmail(dot)com>
Cc: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Report changes discarded for relations not in the subscription
Date: 2026-11-19 06:10:44
Message-ID: CAHut+Ps2m77a=NrDfWnQT=s95kp5-b7MNW8P5qNVwMBLn+aVRw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Some initial review comments for patch v2.

======
src/backend/replication/logical/worker.c

report_unapplied_change:

1.
+/*
+ * Report that changes for this relation are not being applied.
+ *
+ * A relation that is not ready is skipped silently on every change. That is
+ * correct while a tablesync worker is still copying it, but it is
+ * indistinguishable from a relation missing from pg_subscription_rel
+ * altogether -- one whose changes are discarded, and acknowledged to the
+ * publisher as applied, for as long as the subscription runs. Report the
+ * latter at LOG and the former, which is transient and expected, at DEBUG2.
+ *
+ * The gate this serves is reached once per change, so report each sync state
+ * of a relation only once. The record is kept in the relation map entry, so
+ * it lasts as long as the worker does.
+ */

Much of this seemed like background and justification for the patch,
instead of describing what the function does. IMO, saying "latter" and
"former" is difficult to understand without reading it several times.
Most of this paragraph might be better moved to comments in the
function body, not in the function header.

~~~

2.
+ if (rel->reported && rel->state == rel->reportedstate)
+ return;

Where are `reported` and `reportedstate` initialised to non-garbage?

~~~

3.
+ ereport(LOG,
+ errmsg("skipping changes for relation \"%s.%s\" in subscription \"%s\"",
+ rel->remoterel.nspname, rel->remoterel.relname,
+ MySubscription->name),
+ errdetail("The relation is not part of the subscription."),
+ errhint("Use ALTER SUBSCRIPTION ... REFRESH PUBLICATION to add it."));

The errmsg and errdetail seem conflicting, by firstly saying "in
subscription \"%s\", and then saying "The relation is not part of the
subscription."

SUGGESTION
errmsg("skipping changes for relation \"%s.%s\"" ...)
errdetail("The published relation is not included in subscription \"%s\"." ...)
errhint("Consider using ALTER SUBSCRIPTION ... REFRESH PUBLICATION")

My LLM said "to add it" in the errhint might be a bit strong -- e.g.
there can be legitimate reasons for the unapplied change. E.g there
might have been a RERESH PUBLICATION moments before that removed the
row, so these in-flight changes really should be skipped.

======
src/include/replication/logicalrelation.h

4.
+ /*
+ * Sync state.
+ *
+ * reported and reportedstate limit report_unapplied_change() to one
+ * report per sync state: whether a report was made, and for which state.
+ * They are kept next to state so that they occupy padding that follows it
+ * anyway.
+ */
char state;
+ bool reported;
+ char reportedstate;
XLogRecPtr statelsn;
} LogicalRepRelMapEntry;

4A
Why do we need the commentary about padding?

~

4B.
IIUC, you could achieve the same with a single member "char
last_unapplied_state" with an initial value of '?'.

#define SUBREL_STATE_INIT_LAST_UNAPPLIED '?'

======
Kind Regards,
Peter Smith.
Fujitsu Australia

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Xuneng Zhou 2026-11-19 06:26:29 Re: test: avoid redundant standby catchup in 049_wait_for_lsn
Previous Message 신성준 2026-11-19 06:05:32 Re: Add wait events for server logging destination writes