Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit04c8a69

Browse files
author
Amit Kapila
committed
Fix subscriber invalid memory access on DDL.
This patch allows building the local relmap cache for a subscribedrelation after processing pending invalidation messages and potentialrelcache updates. Without this, the attributes in the local cache don'ttally with the updated relcache entry leading to invalid memory access.Reported-by Jehan-Guillaume de RorthaisAuthor: Jehan-Guillaume de Rorthais and Vignesh CReviewed-by: Amit KapilaBackpatch-through: 10Discussion:https://postgr.es/m/20191025175929.7e90dbf5@firost
1 parent52dcfda commit04c8a69

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

‎src/backend/replication/logical/relation.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
220220
{
221221
LogicalRepRelMapEntry*entry;
222222
boolfound;
223+
Oidrelid=InvalidOid;
224+
LogicalRepRelation*remoterel;
223225

224226
if (LogicalRepRelMap==NULL)
225227
logicalrep_relmap_init();
@@ -232,19 +234,16 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
232234
elog(ERROR,"no relation map entry for remote relation ID %u",
233235
remoteid);
234236

235-
/* Need to update the local cache? */
237+
remoterel=&entry->remoterel;
238+
239+
/*
240+
* When opening and locking a relation, pending invalidation messages are
241+
* processed which can invalidate the relation. We need to update the
242+
* local cache both when we are first time accessing the relation and when
243+
* the relation is invalidated (aka entry->localreloid is set InvalidOid).
244+
*/
236245
if (!OidIsValid(entry->localreloid))
237246
{
238-
Oidrelid;
239-
inti;
240-
intfound;
241-
Bitmapset*idkey;
242-
TupleDescdesc;
243-
LogicalRepRelation*remoterel;
244-
MemoryContextoldctx;
245-
246-
remoterel=&entry->remoterel;
247-
248247
/* Try to find and lock the relation by name. */
249248
relid=RangeVarGetRelid(makeRangeVar(remoterel->nspname,
250249
remoterel->relname,-1),
@@ -256,6 +255,21 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
256255
remoterel->nspname,remoterel->relname)));
257256
entry->localrel=table_open(relid,NoLock);
258257

258+
}
259+
else
260+
{
261+
relid=entry->localreloid;
262+
entry->localrel=table_open(entry->localreloid,lockmode);
263+
}
264+
265+
if (!OidIsValid(entry->localreloid))
266+
{
267+
intfound;
268+
Bitmapset*idkey;
269+
TupleDescdesc;
270+
MemoryContextoldctx;
271+
inti;
272+
259273
/* Check for supported relkind. */
260274
CheckSubscriptionRelkind(entry->localrel->rd_rel->relkind,
261275
remoterel->nspname,remoterel->relname);
@@ -350,8 +364,6 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
350364

351365
entry->localreloid=relid;
352366
}
353-
else
354-
entry->localrel=table_open(entry->localreloid,lockmode);
355367

356368
if (entry->state!=SUBREL_STATE_READY)
357369
entry->state=GetSubscriptionRelState(MySubscription->oid,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp