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

Commit4c032dd

Browse files
committed
Check for two_phase change at end of process_syncing_tables_for_apply.
Previously this function checked to see if we were ready to switchto two_phase mode at its start, but that's silly: we should checkat the end, after we've done the work that might make us ready.This simple change removes one sleep cycle from the time needed toswitch to two_phase mode. In the real world that might not beworth much, but it shaves a few seconds off the runtime for thesubscription test suite.Nathan BossartDiscussion:https://postgr.es/m/20221122004119.GA132961@nathanxps13
1 parentb1665bf commit4c032dd

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

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

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
415415
staticHTAB*last_start_times=NULL;
416416
ListCell*lc;
417417
boolstarted_tx= false;
418+
boolshould_exit= false;
418419

419420
Assert(!IsTransactionState());
420421

@@ -446,28 +447,6 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
446447
last_start_times=NULL;
447448
}
448449

449-
/*
450-
* Even when the two_phase mode is requested by the user, it remains as
451-
* 'pending' until all tablesyncs have reached READY state.
452-
*
453-
* When this happens, we restart the apply worker and (if the conditions
454-
* are still ok) then the two_phase tri-state will become 'enabled' at
455-
* that time.
456-
*
457-
* Note: If the subscription has no tables then leave the state as
458-
* PENDING, which allows ALTER SUBSCRIPTION ... REFRESH PUBLICATION to
459-
* work.
460-
*/
461-
if (MySubscription->twophasestate==LOGICALREP_TWOPHASE_STATE_PENDING&&
462-
AllTablesyncsReady())
463-
{
464-
ereport(LOG,
465-
(errmsg("logical replication apply worker for subscription \"%s\" will restart so that two_phase can be enabled",
466-
MySubscription->name)));
467-
468-
proc_exit(0);
469-
}
470-
471450
/*
472451
* Process all tables that are being synchronized.
473452
*/
@@ -619,9 +598,36 @@ process_syncing_tables_for_apply(XLogRecPtr current_lsn)
619598

620599
if (started_tx)
621600
{
601+
/*
602+
* Even when the two_phase mode is requested by the user, it remains
603+
* as 'pending' until all tablesyncs have reached READY state.
604+
*
605+
* When this happens, we restart the apply worker and (if the
606+
* conditions are still ok) then the two_phase tri-state will become
607+
* 'enabled' at that time.
608+
*
609+
* Note: If the subscription has no tables then leave the state as
610+
* PENDING, which allows ALTER SUBSCRIPTION ... REFRESH PUBLICATION to
611+
* work.
612+
*/
613+
if (MySubscription->twophasestate==LOGICALREP_TWOPHASE_STATE_PENDING)
614+
{
615+
CommandCounterIncrement();/* make updates visible */
616+
if (AllTablesyncsReady())
617+
{
618+
ereport(LOG,
619+
(errmsg("logical replication apply worker for subscription \"%s\" will restart so that two_phase can be enabled",
620+
MySubscription->name)));
621+
should_exit= true;
622+
}
623+
}
624+
622625
CommitTransactionCommand();
623626
pgstat_report_stat(true);
624627
}
628+
629+
if (should_exit)
630+
proc_exit(0);
625631
}
626632

627633
/*
@@ -802,6 +808,7 @@ fetch_remote_table_info(char *nspname, char *relname,
802808
TupleTableSlot*tslot;
803809
OidattrsRow[]= {INT2VECTOROID};
804810
StringInfoDatapub_names;
811+
805812
initStringInfo(&pub_names);
806813
foreach(lc,MySubscription->publications)
807814
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp