At Sun, 28 Aug 2022 10:16:21 +0530, Dilip Kumar <[email protected]> wrote
in
> On Fri, Aug 26, 2022 at 7:53 PM Robert Haas <[email protected]> wrote:
> > v2 attached.
>
> The patch LGTM, this patch will apply on master and v15. PFA patch
> for back branches.
StandbyMode is obviously wrong. On the other hand I thought that
!ArchiveRecoveryRequested is somewhat wrong, too (, as I stated in the
pointed thread). On second thought, I changed my mind that it is
right. After aborted contrec is found, The cause of the confusion is
that I somehow thought that archive recovery continues from the
aborted-contrec record. However, that assumption is wrong. The next
redo starts from the beginning of the aborted contrecord so we should
forget abouat the old missing/aborted contrec info when archive
recovery is requested.
In the end, the point is that we need to set the global variables only
when XLogPrefetcherReadRecord() (or XLogReadRecord()) returns NULL and
we return it to the caller. Is it worth to do a small refactoring
like the attached? If no, I'm fine with the proposed patch including
the added assertion.
# I havent reproduce the issue of the OP in the other thread yet, and
# also not found how to reproduce this issue, though..
regards.
--
Kyotaro Horiguchi
NTT Open Source Software Center
diff --git a/src/backend/access/transam/xlogrecovery.c
b/src/backend/access/transam/xlogrecovery.c
index a59a0e826b..d354701423 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -3023,19 +3023,6 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
record = XLogPrefetcherReadRecord(xlogprefetcher, &errormsg);
if (record == NULL)
{
- /*
- * When not in standby mode we find that WAL ends in an
incomplete
- * record, keep track of that record. After recovery
is done,
- * we'll write a record to indicate to downstream WAL
readers that
- * that portion is to be ignored.
- */
- if (!StandbyMode &&
- !XLogRecPtrIsInvalid(xlogreader->abortedRecPtr))
- {
- abortedRecPtr = xlogreader->abortedRecPtr;
- missingContrecPtr =
xlogreader->missingContrecPtr;
- }
-
if (readFile >= 0)
{
close(readFile);
@@ -3125,8 +3112,20 @@ ReadRecord(XLogPrefetcher *xlogprefetcher, int emode,
/* In standby mode, loop back to retry. Otherwise, give
up. */
if (StandbyMode && !CheckForStandbyTrigger())
continue;
- else
- return NULL;
+
+ /*
+ * We return NULL to the caller. If the last record
has failed
+ * with a missing contrecord, inform that to the caller
as well.
+ * In other cases we retry from the beginning of the
failed record
+ * so no need to do this.
+ */
+ if (!XLogRecPtrIsInvalid(xlogreader->abortedRecPtr))
+ {
+ abortedRecPtr = xlogreader->abortedRecPtr;
+ missingContrecPtr =
xlogreader->missingContrecPtr;
+ }
+
+ return NULL;
}
}
}