Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e5372b4

Browse files
committed
Correctly mark pg_subscription_rel.srsublsn as nullable.
The code has always set this column to NULL when it's not valid, but the catalog header's description failed to reflect that, as did the SGML docs, as did some of the code. To prevent future coding errors of the same ilk, let's hide the field from C code as though it were variable-length (which, in a sense, it is). As with commit 72eab84a5, we can only fix this cleanly in HEAD and v13; the problem extends further back but we'll need some klugery in the released branches. Discussion: https://postgr.es/m/367660.1595202498@sss.pgh.pa.us
1 parent 2f1f189 commit e5372b4

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7620,7 +7620,9 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
76207620
<structfield>srsublsn</structfield> <type>pg_lsn</type>
76217621
</para>
76227622
<para>
7623-
End LSN for <literal>s</literal> and <literal>r</literal> states.
7623+
Remote LSN of the state change used for synchronization coordination
7624+
when in <literal>s</literal> or <literal>r</literal> states,
7625+
otherwise null
76247626
</para></entry>
76257627
</row>
76267628
</tbody>

src/backend/catalog/pg_subscription.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,20 @@ GetSubscriptionRelations(Oid subid)
451451
{
452452
Form_pg_subscription_rel subrel;
453453
SubscriptionRelState *relstate;
454+
Datum d;
455+
bool isnull;
454456

455457
subrel = (Form_pg_subscription_rel) GETSTRUCT(tup);
456458

457459
relstate = (SubscriptionRelState *) palloc(sizeof(SubscriptionRelState));
458460
relstate->relid = subrel->srrelid;
459461
relstate->state = subrel->srsubstate;
460-
relstate->lsn = subrel->srsublsn;
462+
d = SysCacheGetAttr(SUBSCRIPTIONRELMAP, tup,
463+
Anum_pg_subscription_rel_srsublsn, &isnull);
464+
if (isnull)
465+
relstate->lsn = InvalidXLogRecPtr;
466+
else
467+
relstate->lsn = DatumGetLSN(d);
461468

462469
res = lappend(res, relstate);
463470
}
@@ -503,13 +510,20 @@ GetSubscriptionNotReadyRelations(Oid subid)
503510
{
504511
Form_pg_subscription_rel subrel;
505512
SubscriptionRelState *relstate;
513+
Datum d;
514+
bool isnull;
506515

507516
subrel = (Form_pg_subscription_rel) GETSTRUCT(tup);
508517

509518
relstate = (SubscriptionRelState *) palloc(sizeof(SubscriptionRelState));
510519
relstate->relid = subrel->srrelid;
511520
relstate->state = subrel->srsubstate;
512-
relstate->lsn = subrel->srsublsn;
521+
d = SysCacheGetAttr(SUBSCRIPTIONRELMAP, tup,
522+
Anum_pg_subscription_rel_srsublsn, &isnull);
523+
if (isnull)
524+
relstate->lsn = InvalidXLogRecPtr;
525+
else
526+
relstate->lsn = DatumGetLSN(d);
513527

514528
res = lappend(res, relstate);
515529
}

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 202007191
56+
#define CATALOG_VERSION_NO 202007201
5757

5858
#endif

src/include/catalog/pg_subscription_rel.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,18 @@ CATALOG(pg_subscription_rel,6102,SubscriptionRelRelationId)
3333
Oid srsubid; /* Oid of subscription */
3434
Oid srrelid; /* Oid of relation */
3535
char srsubstate; /* state of the relation in subscription */
36-
XLogRecPtr srsublsn; /* remote lsn of the state change used for
37-
* synchronization coordination */
36+
37+
/*
38+
* Although srsublsn is a fixed-width type, it is allowed to be NULL, so
39+
* we prevent direct C code access to it just as for a varlena field.
40+
*/
41+
#ifdef CATALOG_VARLEN /* variable-length fields start here */
42+
43+
XLogRecPtr srsublsn BKI_FORCE_NULL; /* remote LSN of the state change
44+
* used for synchronization
45+
* coordination, or NULL if not
46+
* valid */
47+
#endif
3848
} FormData_pg_subscription_rel;
3949

4050
typedef FormData_pg_subscription_rel *Form_pg_subscription_rel;

0 commit comments

Comments
 (0)