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

Commitb05fe7b

Browse files
committed
Review logical replication tablesync code
Most importantly, remove optimization in LogicalRepSyncTableStart thatskips the normal walrcv_startstreaming/endstreaming dance. Theoptimization is not critically important for production uses anyway,since it only fires in cases with no activity, and saves anuninteresting amount of work even then. Critically, it obscures bugs byhiding the interesting code path from test cases.Also: in GetSubscriptionRelState, remove pointless relation open; accesspg_subscription_rel->srsubstate with GETSTRUCT as is typical rather thanSysCacheGetAttr; remove unused 'missing_ok' argument.In wait_for_relation_state_change, use explicit catalog snapshotinvalidation rather than obscurely (and expensively) throughGetLatestSnapshot.In various places: sprinkle comments more liberally and rewrite a numberof them. Other cosmetic code improvements.No backpatch, since no bug is being fixed here.Author: Álvaro Herrera <alvherre@alvh.no-ip.org>Reviewed-by: Petr Jelínek <petr.jelinek@2ndquadrant.com>Discussion:https://postgr.es/m/20201010190637.GA5774@alvherre.pgsql
1 parentc5b097f commitb05fe7b

File tree

5 files changed

+131
-178
lines changed

5 files changed

+131
-178
lines changed

‎src/backend/catalog/pg_subscription.c

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -328,43 +328,31 @@ UpdateSubscriptionRelState(Oid subid, Oid relid, char state,
328328
/*
329329
* Get state of subscription table.
330330
*
331-
* Returns SUBREL_STATE_UNKNOWN whennot found and missing_ok is true.
331+
* Returns SUBREL_STATE_UNKNOWN whenthe table is not in the subscription.
332332
*/
333333
char
334-
GetSubscriptionRelState(Oidsubid,Oidrelid,XLogRecPtr*sublsn,
335-
boolmissing_ok)
334+
GetSubscriptionRelState(Oidsubid,Oidrelid,XLogRecPtr*sublsn)
336335
{
337-
Relationrel;
338336
HeapTupletup;
339337
charsubstate;
340338
boolisnull;
341339
Datumd;
342340

343-
rel=table_open(SubscriptionRelRelationId,AccessShareLock);
344-
345341
/* Try finding the mapping. */
346342
tup=SearchSysCache2(SUBSCRIPTIONRELMAP,
347343
ObjectIdGetDatum(relid),
348344
ObjectIdGetDatum(subid));
349345

350346
if (!HeapTupleIsValid(tup))
351347
{
352-
if (missing_ok)
353-
{
354-
table_close(rel,AccessShareLock);
355-
*sublsn=InvalidXLogRecPtr;
356-
returnSUBREL_STATE_UNKNOWN;
357-
}
358-
359-
elog(ERROR,"subscription table %u in subscription %u does not exist",
360-
relid,subid);
348+
*sublsn=InvalidXLogRecPtr;
349+
returnSUBREL_STATE_UNKNOWN;
361350
}
362351

363352
/* Get the state. */
364-
d=SysCacheGetAttr(SUBSCRIPTIONRELMAP,tup,
365-
Anum_pg_subscription_rel_srsubstate,&isnull);
366-
Assert(!isnull);
367-
substate=DatumGetChar(d);
353+
substate= ((Form_pg_subscription_rel)GETSTRUCT(tup))->srsubstate;
354+
355+
/* Get the LSN */
368356
d=SysCacheGetAttr(SUBSCRIPTIONRELMAP,tup,
369357
Anum_pg_subscription_rel_srsublsn,&isnull);
370358
if (isnull)
@@ -374,7 +362,6 @@ GetSubscriptionRelState(Oid subid, Oid relid, XLogRecPtr *sublsn,
374362

375363
/* Cleanup */
376364
ReleaseSysCache(tup);
377-
table_close(rel,AccessShareLock);
378365

379366
returnsubstate;
380367
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ logicalrep_rel_open(LogicalRepRelId remoteid, LOCKMODE lockmode)
437437
if (entry->state!=SUBREL_STATE_READY)
438438
entry->state=GetSubscriptionRelState(MySubscription->oid,
439439
entry->localreloid,
440-
&entry->statelsn,
441-
true);
440+
&entry->statelsn);
442441

443442
returnentry;
444443
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp