From fe1087f45361baa5408276807625c64d572a3ae1 Mon Sep 17 00:00:00 2001 From: chenxiaobin19 <1025221611@qq.com> Date: Wed, 29 Nov 2023 09:31:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AEcatchup2nor?= =?UTF-8?q?mal=5Fwait=5Ftime=E5=90=8E=E6=80=A7=E8=83=BD=E4=B8=8B=E9=99=8D?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/process/threadpool/knl_instance.cpp | 1 + src/gausskernel/storage/replication/syncrep.cpp | 4 +++- src/gausskernel/storage/replication/walsender.cpp | 6 ++++-- src/include/knl/knl_instance.h | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/gausskernel/process/threadpool/knl_instance.cpp b/src/gausskernel/process/threadpool/knl_instance.cpp index 7a2b377c4..118cbdd70 100755 --- a/src/gausskernel/process/threadpool/knl_instance.cpp +++ b/src/gausskernel/process/threadpool/knl_instance.cpp @@ -1062,6 +1062,7 @@ void knl_instance_init() g_instance.needCheckConflictSubIds = NIL; pthread_mutex_init(&g_instance.subIdsLock, NULL); #endif + g_instance.noNeedWaitForCatchup = 0; knl_g_datadir_init(&g_instance.datadir_cxt); knl_g_listen_sock_init(&g_instance.listen_cxt); diff --git a/src/gausskernel/storage/replication/syncrep.cpp b/src/gausskernel/storage/replication/syncrep.cpp index 090c25d8a..9ba6a79e3 100755 --- a/src/gausskernel/storage/replication/syncrep.cpp +++ b/src/gausskernel/storage/replication/syncrep.cpp @@ -174,7 +174,8 @@ bool SynRepWaitCatchup(XLogRecPtr XactCommitLSN) * return true. */ if (!t_thrd.walsender_cxt.WalSndCtl->most_available_sync || - u_sess->attr.attr_storage.catchup2normal_wait_time < 0) { + u_sess->attr.attr_storage.catchup2normal_wait_time < 0 || + pg_atomic_read_u32(&g_instance.noNeedWaitForCatchup) == 1) { return true; } @@ -956,6 +957,7 @@ static bool SyncRepGetSyncLeftTime(XLogRecPtr XactCommitLSN, TimestampTz* leftTi num_standbys = SyncRepGetSyncStandbys(&sync_standbys, &catchup_standbys); /* Skip here if there is at lease one sync standby, or no standby in catchup. */ if (check_sync_standbys_num(sync_standbys, num_standbys) != STANDBIES_EMPTY || list_length(catchup_standbys) == 0) { + pg_atomic_exchange_u32(&g_instance.noNeedWaitForCatchup, 1); pfree(sync_standbys); list_free(catchup_standbys); return false; diff --git a/src/gausskernel/storage/replication/walsender.cpp b/src/gausskernel/storage/replication/walsender.cpp index af28a15d1..c0a49325c 100755 --- a/src/gausskernel/storage/replication/walsender.cpp +++ b/src/gausskernel/storage/replication/walsender.cpp @@ -6003,10 +6003,12 @@ void WalSndSetState(WalSndState state) SpinLockAcquire(&walsnd->mutex); walsnd->state = state; - if (state == WALSNDSTATE_CATCHUP) + if (state == WALSNDSTATE_CATCHUP) { walsnd->catchupTime[0] = GetCurrentTimestamp(); - else if (state == WALSNDSTATE_STREAMING) + pg_atomic_exchange_u32(&g_instance.noNeedWaitForCatchup, 0); + } else if (state == WALSNDSTATE_STREAMING) { walsnd->catchupTime[1] = GetCurrentTimestamp(); + } SpinLockRelease(&walsnd->mutex); } diff --git a/src/include/knl/knl_instance.h b/src/include/knl/knl_instance.h index 82f5d005d..e487f56f3 100755 --- a/src/include/knl/knl_instance.h +++ b/src/include/knl/knl_instance.h @@ -1428,6 +1428,7 @@ typedef struct knl_instance_context { List* needCheckConflictSubIds; pthread_mutex_t subIdsLock; #endif + uint32 noNeedWaitForCatchup; pg_atomic_uint32 extensionNum; knl_g_audit_context audit_cxt; knl_g_abo_context abo_cxt;