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

Commitce3049b

Browse files
committed
Refactor code in charge of grabbing the relations of a subscription
GetSubscriptionRelations() and GetSubscriptionNotReadyRelations() sharemostly the same code, which scans pg_subscription_rel and fetches allthe relations of a given subscription. The only difference is that thesecond routine looks for all the relations not in a ready state. Thiscommit refactors the code to use a single routine, shaving a bit ofcode.Author: Vignesh CReviewed-By: Kyotaro Horiguchi, Amit Kapila, Michael Paquier, PeterSmithDiscussion:https://postgr.es/m/CALDaNm0eW-9g4G_EzHebnFT5zZoasWCS_EzZQ5BgnLZny9S=pg@mail.gmail.com
1 parentd0b193c commitce3049b

File tree

4 files changed

+14
-65
lines changed

4 files changed

+14
-65
lines changed

‎src/backend/catalog/pg_subscription.c

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -533,65 +533,14 @@ HasSubscriptionRelations(Oid subid)
533533
}
534534

535535
/*
536-
* Getall relations for subscription.
536+
* Getthe relations for the subscription.
537537
*
538-
* Returned list is palloc'ed in current memory context.
538+
* If not_ready is true, return only the relations that are not in a ready
539+
* state, otherwise return all the relations of the subscription. The
540+
* returned list is palloc'ed in the current memory context.
539541
*/
540542
List*
541-
GetSubscriptionRelations(Oidsubid)
542-
{
543-
List*res=NIL;
544-
Relationrel;
545-
HeapTupletup;
546-
ScanKeyDataskey[1];
547-
SysScanDescscan;
548-
549-
rel=table_open(SubscriptionRelRelationId,AccessShareLock);
550-
551-
ScanKeyInit(&skey[0],
552-
Anum_pg_subscription_rel_srsubid,
553-
BTEqualStrategyNumber,F_OIDEQ,
554-
ObjectIdGetDatum(subid));
555-
556-
scan=systable_beginscan(rel,InvalidOid, false,
557-
NULL,1,skey);
558-
559-
while (HeapTupleIsValid(tup=systable_getnext(scan)))
560-
{
561-
Form_pg_subscription_relsubrel;
562-
SubscriptionRelState*relstate;
563-
Datumd;
564-
boolisnull;
565-
566-
subrel= (Form_pg_subscription_rel)GETSTRUCT(tup);
567-
568-
relstate= (SubscriptionRelState*)palloc(sizeof(SubscriptionRelState));
569-
relstate->relid=subrel->srrelid;
570-
relstate->state=subrel->srsubstate;
571-
d=SysCacheGetAttr(SUBSCRIPTIONRELMAP,tup,
572-
Anum_pg_subscription_rel_srsublsn,&isnull);
573-
if (isnull)
574-
relstate->lsn=InvalidXLogRecPtr;
575-
else
576-
relstate->lsn=DatumGetLSN(d);
577-
578-
res=lappend(res,relstate);
579-
}
580-
581-
/* Cleanup */
582-
systable_endscan(scan);
583-
table_close(rel,AccessShareLock);
584-
585-
returnres;
586-
}
587-
588-
/*
589-
* Get all relations for subscription that are not in a ready state.
590-
*
591-
* Returned list is palloc'ed in current memory context.
592-
*/
593-
List*
594-
GetSubscriptionNotReadyRelations(Oidsubid)
543+
GetSubscriptionRelations(Oidsubid,boolnot_ready)
595544
{
596545
List*res=NIL;
597546
Relationrel;
@@ -607,10 +556,11 @@ GetSubscriptionNotReadyRelations(Oid subid)
607556
BTEqualStrategyNumber,F_OIDEQ,
608557
ObjectIdGetDatum(subid));
609558

610-
ScanKeyInit(&skey[nkeys++],
611-
Anum_pg_subscription_rel_srsubstate,
612-
BTEqualStrategyNumber,F_CHARNE,
613-
CharGetDatum(SUBREL_STATE_READY));
559+
if (not_ready)
560+
ScanKeyInit(&skey[nkeys++],
561+
Anum_pg_subscription_rel_srsubstate,
562+
BTEqualStrategyNumber,F_CHARNE,
563+
CharGetDatum(SUBREL_STATE_READY));
614564

615565
scan=systable_beginscan(rel,InvalidOid, false,
616566
NULL,nkeys,skey);

‎src/backend/commands/subscriptioncmds.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ AlterSubscription_refresh(Subscription *sub, bool copy_data,
814814
pubrel_names=fetch_table_list(wrconn,sub->publications);
815815

816816
/* Get local table list. */
817-
subrel_states=GetSubscriptionRelations(sub->oid);
817+
subrel_states=GetSubscriptionRelations(sub->oid, false);
818818

819819
/*
820820
* Build qsorted array of local table oids for faster lookup. This can
@@ -1494,7 +1494,7 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel)
14941494
* the apply and tablesync workers and they can't restart because of
14951495
* exclusive lock on the subscription.
14961496
*/
1497-
rstates=GetSubscriptionNotReadyRelations(subid);
1497+
rstates=GetSubscriptionRelations(subid, true);
14981498
foreach(lc,rstates)
14991499
{
15001500
SubscriptionRelState*rstate= (SubscriptionRelState*)lfirst(lc);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ FetchTableStates(bool *started_tx)
14791479
}
14801480

14811481
/* Fetch all non-ready tables. */
1482-
rstates=GetSubscriptionNotReadyRelations(MySubscription->oid);
1482+
rstates=GetSubscriptionRelations(MySubscription->oid, true);
14831483

14841484
/* Allocate the tracking info in a permanent memory context. */
14851485
oldctx=MemoryContextSwitchTo(CacheMemoryContext);

‎src/include/catalog/pg_subscription_rel.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ extern char GetSubscriptionRelState(Oid subid, Oid relid, XLogRecPtr *sublsn);
8888
externvoidRemoveSubscriptionRel(Oidsubid,Oidrelid);
8989

9090
externboolHasSubscriptionRelations(Oidsubid);
91-
externList*GetSubscriptionRelations(Oidsubid);
92-
externList*GetSubscriptionNotReadyRelations(Oidsubid);
91+
externList*GetSubscriptionRelations(Oidsubid,boolnot_ready);
9392

9493
#endif/* PG_SUBSCRIPTION_REL_H */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp