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

Commit0a7c9ee

Browse files
committed
Add more error context to RestoreBlockImage() and consume it
On failure in restoring a block image, no details were provided, whileit is possible to see failure with an inconsistent record state, afailure in processing decompression or a failure in decompressionbecause a build does not support this option.RestoreBlockImage() is used in two code paths in the backend code,during recovery and when checking a page consistency after applyingmasking, and both places are changed to consume the error messageproduced by the internal routine when it returns a false status. Allthe error messages are reported under ERRCODE_INTERNAL_ERROR, that getsused also when attempting to access a page compressed by a methodnot supported by the build attempting the decompression. This issomething that can happen in core when doing physical replication withprimary and standby using inconsistent build options, for example.This routine is available since2c03216 and it has never provided anycontext about the error happening when it failed. This change isjustified even more after57aa5b2, that introduced compression of FPWsin WAL.Reported-by: Justin PrysbyAuthor: Michael PaquierDiscussion:https://postgr.es/m/20220905002320.GD31833@telsasoft.comBackpatch-through: 15
1 parentade2409 commit0a7c9ee

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

‎src/backend/access/transam/xlogreader.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,8 @@ XLogRecGetBlockData(XLogReaderState *record, uint8 block_id, Size *len)
20342034
/*
20352035
* Restore a full-page image from a backup block attached to an XLOG record.
20362036
*
2037-
* Returns true if a full-page image is restored.
2037+
* Returns true if a full-page image is restored, and false on failure with
2038+
* an error to be consumed by the caller.
20382039
*/
20392040
bool
20402041
RestoreBlockImage(XLogReaderState*record,uint8block_id,char*page)
@@ -2045,9 +2046,20 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
20452046

20462047
if (block_id>record->record->max_block_id||
20472048
!record->record->blocks[block_id].in_use)
2049+
{
2050+
report_invalid_record(record,
2051+
"could not restore image at %X/%X with invalid block %d specified",
2052+
LSN_FORMAT_ARGS(record->ReadRecPtr),
2053+
block_id);
20482054
return false;
2055+
}
20492056
if (!record->record->blocks[block_id].has_image)
2057+
{
2058+
report_invalid_record(record,"could not restore image at %X/%X with invalid state, block %d",
2059+
LSN_FORMAT_ARGS(record->ReadRecPtr),
2060+
block_id);
20502061
return false;
2062+
}
20512063

20522064
bkpb=&record->record->blocks[block_id];
20532065
ptr=bkpb->bkp_image;
@@ -2070,7 +2082,7 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
20702082
bkpb->bimg_len,BLCKSZ-bkpb->hole_length) <=0)
20712083
decomp_success= false;
20722084
#else
2073-
report_invalid_record(record,"image at %X/%X compressed with %s not supported by build, block %d",
2085+
report_invalid_record(record,"could not restoreimage at %X/%X compressed with %s not supported by build, block %d",
20742086
LSN_FORMAT_ARGS(record->ReadRecPtr),
20752087
"LZ4",
20762088
block_id);
@@ -2087,7 +2099,7 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
20872099
if (ZSTD_isError(decomp_result))
20882100
decomp_success= false;
20892101
#else
2090-
report_invalid_record(record,"image at %X/%X compressed with %s not supported by build, block %d",
2102+
report_invalid_record(record,"could not restoreimage at %X/%X compressed with %s not supported by build, block %d",
20912103
LSN_FORMAT_ARGS(record->ReadRecPtr),
20922104
"zstd",
20932105
block_id);
@@ -2096,15 +2108,15 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
20962108
}
20972109
else
20982110
{
2099-
report_invalid_record(record,"image at %X/%X compressed with unknown method, block %d",
2111+
report_invalid_record(record,"could not restoreimage at %X/%X compressed with unknown method, block %d",
21002112
LSN_FORMAT_ARGS(record->ReadRecPtr),
21012113
block_id);
21022114
return false;
21032115
}
21042116

21052117
if (!decomp_success)
21062118
{
2107-
report_invalid_record(record,"invalid compressed image at %X/%X, block %d",
2119+
report_invalid_record(record,"could not decompress image at %X/%X, block %d",
21082120
LSN_FORMAT_ARGS(record->ReadRecPtr),
21092121
block_id);
21102122
return false;

‎src/backend/access/transam/xlogrecovery.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,9 @@ verifyBackupPageConsistency(XLogReaderState *record)
24102410
* can be directly applied on it.
24112411
*/
24122412
if (!RestoreBlockImage(record,block_id,primary_image_masked))
2413-
elog(ERROR,"failed to restore block image");
2413+
ereport(ERROR,
2414+
(errcode(ERRCODE_INTERNAL_ERROR),
2415+
errmsg_internal("%s",record->errormsg_buf)));
24142416

24152417
/*
24162418
* If masking function is defined, mask both the primary and replay

‎src/backend/access/transam/xlogutils.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ XLogReadBufferForRedoExtended(XLogReaderState *record,
392392
prefetch_buffer);
393393
page=BufferGetPage(*buf);
394394
if (!RestoreBlockImage(record,block_id,page))
395-
elog(ERROR,"failed to restore block image");
395+
ereport(ERROR,
396+
(errcode(ERRCODE_INTERNAL_ERROR),
397+
errmsg_internal("%s",record->errormsg_buf)));
396398

397399
/*
398400
* The page may be uninitialized. If so, we can't set the LSN because

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp