Files
postgresql/src/include/replication/logicalrelation.h
Amit Kapila b7658c24c7 Fix data inconsistency between publisher and subscriber.
We were not updating the partition map cache in the subscriber even when
the corresponding remote rel is changed. Due to this data was getting
incorrectly replicated for partition tables after the publisher has
changed the table schema.

Fix it by resetting the required entries in the partition map cache after
receiving a new relation mapping from the publisher.

Reported-by: Shi Yu
Author: Shi Yu, Hou Zhijie
Reviewed-by: Amit Langote, Amit Kapila
Backpatch-through: 13, where it was introduced
Discussion: https://postgr.es/m/OSZPR01MB6310F46CD425A967E4AEF736FDA49@OSZPR01MB6310.jpnprd01.prod.outlook.com
2022-06-16 08:45:07 +05:30

51 lines
1.6 KiB
C

/*-------------------------------------------------------------------------
*
* logicalrelation.h
* Relation definitions for logical replication relation mapping.
*
* Portions Copyright (c) 2016-2022, PostgreSQL Global Development Group
*
* src/include/replication/logicalrelation.h
*
*-------------------------------------------------------------------------
*/
#ifndef LOGICALRELATION_H
#define LOGICALRELATION_H
#include "access/attmap.h"
#include "replication/logicalproto.h"
typedef struct LogicalRepRelMapEntry
{
LogicalRepRelation remoterel; /* key is remoterel.remoteid */
/*
* Validity flag -- when false, revalidate all derived info at next
* logicalrep_rel_open. (While the localrel is open, we assume our lock
* on that rel ensures the info remains good.)
*/
bool localrelvalid;
/* Mapping to local relation. */
Oid localreloid; /* local relation id */
Relation localrel; /* relcache entry (NULL when closed) */
AttrMap *attrmap; /* map of local attributes to remote ones */
bool updatable; /* Can apply updates/deletes? */
/* Sync state. */
char state;
XLogRecPtr statelsn;
} LogicalRepRelMapEntry;
extern void logicalrep_relmap_update(LogicalRepRelation *remoterel);
extern void logicalrep_partmap_reset_relmap(LogicalRepRelation *remoterel);
extern LogicalRepRelMapEntry *logicalrep_rel_open(LogicalRepRelId remoteid,
LOCKMODE lockmode);
extern LogicalRepRelMapEntry *logicalrep_partition_open(LogicalRepRelMapEntry *root,
Relation partrel, AttrMap *map);
extern void logicalrep_rel_close(LogicalRepRelMapEntry *rel,
LOCKMODE lockmode);
#endif /* LOGICALRELATION_H */