From 38cbb219a4b20a16aa835707bba709c13b6d92c1 Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Mon, 24 May 2021 10:53:19 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/storage/access/transam/xlog.cpp | 3 --- src/gausskernel/storage/replication/walrcvwriter.cpp | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index 414285367..422428c34 100644 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -2478,9 +2478,6 @@ static bool XLogArchiveCheckDone(const char *xlog) static bool HasBeenArchivedOnHaMode(const char* xlog) { load_server_mode(); - if (!t_thrd.xlog_cxt.server_mode == PRIMARY_MODE && !t_thrd.xlog_cxt.server_mode == STANDBY_MODE) { - return true; - } int mode = t_thrd.xlog_cxt.server_mode; XLogRecPtr minium_lsn = PG_UINT64_MAX; for (int i = 0; mode == PRIMARY_MODE && i < g_instance.attr.attr_storage.max_wal_senders; i++) { diff --git a/src/gausskernel/storage/replication/walrcvwriter.cpp b/src/gausskernel/storage/replication/walrcvwriter.cpp index b819c3691..33cd9e7ac 100644 --- a/src/gausskernel/storage/replication/walrcvwriter.cpp +++ b/src/gausskernel/storage/replication/walrcvwriter.cpp @@ -140,8 +140,6 @@ static void XLogWalRcvWrite(WalRcvCtlBlock *walrcb, char *buf, Size nbytes, XLog * would otherwise have to reopen this file to fsync it later */ if (recvFile >= 0) { - char xlogfname[MAXFNAMELEN]; - /* * XLOG segment files will be re-read by recovery in startup * process soon, so we don't advise the OS to release cache @@ -157,6 +155,7 @@ static void XLogWalRcvWrite(WalRcvCtlBlock *walrcb, char *buf, Size nbytes, XLog * Create .done file forcibly to prevent the restored segment from * being archived again later. */ + char xlogfname[MAXFNAMELEN]; XLogFileName(xlogfname, recvFileTLI, recvSegNo); XLogArchiveForceDone(xlogfname); #endif From 4038da407358de8ac388f2f744b93ab5b51fc09f Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Thu, 27 May 2021 11:13:15 +0800 Subject: [PATCH 2/3] fixed the bug of standby archiving --- src/gausskernel/storage/access/transam/xlog.cpp | 11 +++++++++++ src/gausskernel/storage/replication/walsender.cpp | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index 422428c34..77a8c40a0 100644 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -2477,9 +2477,20 @@ static bool XLogArchiveCheckDone(const char *xlog) static bool HasBeenArchivedOnHaMode(const char* xlog) { + /* + * Generally, the validity of the xlog transferred from the upper layer has been verified. + * Therefore, if the length of the xlog name transferred is greater than the standard length + * of the xlog name (24 characters), the transferred file is a .backup file. + * Therefore, if the xlog name contains more than 24 characters, return true . + */ + if (strlen(xlog) > 24) { + return true; + } + load_server_mode(); int mode = t_thrd.xlog_cxt.server_mode; XLogRecPtr minium_lsn = PG_UINT64_MAX; + for (int i = 0; mode == PRIMARY_MODE && i < g_instance.attr.attr_storage.max_wal_senders; i++) { /* use volatile pointer to prevent code rearrangement */ volatile WalSnd* walsnd = &t_thrd.walsender_cxt.WalSndCtl->walsnds[i]; diff --git a/src/gausskernel/storage/replication/walsender.cpp b/src/gausskernel/storage/replication/walsender.cpp index 8392f9010..f184ed514 100644 --- a/src/gausskernel/storage/replication/walsender.cpp +++ b/src/gausskernel/storage/replication/walsender.cpp @@ -3203,12 +3203,13 @@ static int WalSndLoop(WalSndSendDataCallback send_data) XLogRecPtr replayPtr; bool amSync = false; bool got_recptr = false; + int standby_nums = list_length(SyncRepGetSyncStandbys(&amSync)); got_recptr = SyncRepGetSyncRecPtr(&receivePtr, &writePtr, &flushPtr, &replayPtr, &amSync, false); if (got_recptr) { ArchiveXlogOnStandby(flushPtr); - } else if (t_thrd.syncrep_cxt.SyncRepConfig == NULL || - (t_thrd.walsender_cxt.WalSndCtl->most_available_sync && - list_length(SyncRepGetSyncStandbys(&amSync)) == 0)) { + } else if (t_thrd.syncrep_cxt.SyncRepConfig == NULL || + u_sess->attr.attr_storage.guc_synchronous_commit <= SYNCHRONOUS_COMMIT_LOCAL_FLUSH || + (t_thrd.walsender_cxt.WalSndCtl->most_available_sync && standby_nums == 0)) { /* * This step is used to deal with the situation that synchronous standbys are not set. */ From 6884947f927b497d344a3eb8b12e542e854bc1cd Mon Sep 17 00:00:00 2001 From: luozihao <1165977584@qq.com> Date: Fri, 28 May 2021 09:44:45 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=BC=96=E7=A0=81=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/storage/access/transam/xlog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index 77a8c40a0..93568a4f3 100644 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -2481,9 +2481,9 @@ static bool HasBeenArchivedOnHaMode(const char* xlog) * Generally, the validity of the xlog transferred from the upper layer has been verified. * Therefore, if the length of the xlog name transferred is greater than the standard length * of the xlog name (24 characters), the transferred file is a .backup file. - * Therefore, if the xlog name contains more than 24 characters, return true . + * Therefore, if the xlog name contains more than 24 characters, return true directly. */ - if (strlen(xlog) > 24) { + if (strlen(xlog) > XLOG_NAME_LENGTH) { return true; }