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

Commit 0fa0b48

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 72eab84, 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 d5daae4 commit 0fa0b48

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
@@ -7631,7 +7631,9 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
76317631
<structfield>srsublsn</structfield> <type>pg_lsn</type>
76327632
</para>
76337633
<para>
7634-
End LSN for <literal>s</literal> and <literal>r</literal> states.
7634+
Remote LSN of the state change used for synchronization coordination
7635+
when in <literal>s</literal> or <literal>r</literal> states,
7636+
otherwise null
76357637
</para></entry>
76367638
</row>
76377639
</tbody>

src/backend/catalog/pg_subscription.c

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

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

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

463470
res = lappend(res, relstate);
464471
}
@@ -504,13 +511,20 @@ GetSubscriptionNotReadyRelations(Oid subid)
504511
{
505512
Form_pg_subscription_rel subrel;
506513
SubscriptionRelState *relstate;
514+
Datum d;
515+
bool isnull;
507516

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

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

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

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 202007192
56+
#define CATALOG_VERSION_NO 202007202
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)