> 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. >
Makes sense. Splitted the comments
> 2.
> + if (rel->reported && rel->state == rel->reportedstate)
> + return;
>
> Where are `reported` and `reportedstate` initialised to non-garbage?
While checking this my LLM also noticed that the entry is re-zeroed
whenever the publisher resends a RELATION message, for example after
DDL. So the report is once per sync state each time the entry is
built, not once for the lifetime of the worker as v2 claimed. I
corrected the comments and the commit message.
> 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.
>
Appreciated, added this enhancement to v3 patch as well.
> 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 '?'
Yes, that works and is simpler. v3 replaces reported and reportedstate
with a single last_unapplied_state, and report_unapplied_change() now
just checks rel->state == rel->last_unapplied_state.
The relation map entries are zeroed with memset() when they are built,
and a zero here is SUBREL_STATE_UNKNOWN. That is exactly the state
that gets the LOG message, so a zeroed field would wrongly suppress
it. v3 therefore sets the sentinel explicitly after the memset() in
both logicalrep_relmap_update() and logicalrep_partition_open(), and
the field's comment says so. I used your
SUBREL_STATE_INIT_LAST_UNAPPLIED name and defined it in
logicalrelation.h, next to the struct that uses it.
Greetings,
Demir.
v3-0001-log-unapplied-changes-for-non-ready-relations.patch
Description: Binary data
