From f8e52531dddc16e4cb8a710b5e72141952e6f2ff Mon Sep 17 00:00:00 2001 From: April01xxx Date: Wed, 22 Jan 2025 17:38:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A2=9E=E9=87=8Fbuild?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E4=B8=8B=E5=8F=AF=E8=83=BD=E4=BC=9A=E5=A4=9A?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E9=83=A8=E5=88=86=E6=97=A0=E7=94=A8=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=A1=B5=E9=9D=A2=E5=92=8CXLog=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_rewind/pg_rewind.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_rewind/pg_rewind.cpp b/src/bin/pg_rewind/pg_rewind.cpp index 4075b0c9c7..cdc173e588 100755 --- a/src/bin/pg_rewind/pg_rewind.cpp +++ b/src/bin/pg_rewind/pg_rewind.cpp @@ -90,6 +90,7 @@ BuildErrorCode gs_increment_build(const char* pgdata, const char* connstr, char* errno_t errorno = EOK; GaussState state; BuildErrorCode rv = BUILD_SUCCESS; + bool needCrashRecovery = false; datadir_target = pg_strdup(pgdata); /* here we set basedir for last xlog requests purpose. the value is the datadir */ @@ -252,12 +253,20 @@ BuildErrorCode gs_increment_build(const char* pgdata, const char* connstr, char* } } - /* Checkpoint redo should exist. Otherwise, fatal and change to full build. */ - (void)readOneRecord(datadir_target, chkptredo, chkpttli); - pg_log(PG_PROGRESS, - "read checkpoint redo (%X/%X) success before rewinding.\n", - (uint32)(chkptredo >> 32), - (uint32)chkptredo); + /* + * If chkptrec < startrec, we don't need to restore the pages modified by + * XLog between [chkptredo, chkptrec] because they have already been fsync'd + * to the disk, and therefore there is no need to determine whether the XLog + * at chkptredo exists either. + */ + needCrashRecovery = chkptrec >= startrec; + if (needCrashRecovery) { + (void)readOneRecord(datadir_target, chkptredo, chkpttli); + pg_log(PG_PROGRESS, + "read checkpoint redo (%X/%X) success before rewinding.\n", + (uint32)(chkptredo >> 32), + (uint32)chkptredo); + } pg_log(PG_PROGRESS, "rewinding from checkpoint redo point at %X/%X on timeline %u\n", @@ -297,7 +306,7 @@ BuildErrorCode gs_increment_build(const char* pgdata, const char* connstr, char* * we would need to replay until the end of WAL here. */ pg_log(PG_PROGRESS, "reading WAL in target\n"); - extractPageMap(datadir_target, chkptredo, lastcommontli); + extractPageMap(datadir_target, needCrashRecovery ? chkptredo : chkptrec, lastcommontli); PG_CHECKBUILD_AND_RETURN(); filemap_finalize(); calculate_totals(); @@ -333,7 +342,7 @@ BuildErrorCode gs_increment_build(const char* pgdata, const char* connstr, char* PG_CHECKBUILD_AND_RETURN(); } pg_log(PG_WARNING, _("starting background WAL receiver\n")); - nRet = snprintf_s(xlog_start, MAXFNAMELEN, MAXFNAMELEN - 1, "%X/%X", (uint32)(chkptredo >> 32), (uint32)chkptredo); + nRet = snprintf_s(xlog_start, MAXFNAMELEN, MAXFNAMELEN - 1, "%X/%X", (uint32)(chkptrec >> 32), (uint32)chkptrec); securec_check_ss_c(nRet, "", ""); get_xlog_location(xlog_location); pg_log(PG_PROGRESS, "Starting copy xlog, start point: %s\n", xlog_start); -- Gitee