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

Commite82201f

Browse files
committed
Consider empty blocks within datafiles.
RelationAddExtraBlocks() may extend a relation with empty blocks dueto optimisation to avoid contentions.
1 parent0b26072 commite82201f

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

‎src/data.c

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
705705
in=fopen(file->path,PG_BINARY_R);
706706
if (in==NULL)
707707
{
708-
elog(ERROR,"cannot open backup file \"%s\": %s",file->path,
708+
elog(ERROR,"Cannot open backup file \"%s\": %s",file->path,
709709
strerror(errno));
710710
}
711711
}
@@ -722,7 +722,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
722722
{
723723
interrno_tmp=errno;
724724
fclose(in);
725-
elog(ERROR,"cannot open restore target file \"%s\": %s",
725+
elog(ERROR,"Cannot open restore target file \"%s\": %s",
726726
to_path,strerror(errno_tmp));
727727
}
728728

@@ -762,16 +762,22 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
762762
break;/* EOF found */
763763
elseif (read_len!=0&&feof(in))
764764
elog(ERROR,
765-
"odd size page found at block %u of \"%s\"",
765+
"Odd size page found at block %u of \"%s\"",
766766
blknum,file->path);
767767
else
768-
elog(ERROR,"cannot read header of block %u of \"%s\": %s",
768+
elog(ERROR,"Cannot read header of block %u of \"%s\": %s",
769769
blknum,file->path,strerror(errno_tmp));
770770
}
771771

772+
if (header.block==0&&header.compressed_size==0)
773+
{
774+
elog(VERBOSE,"Skip empty block of \"%s\"",file->path);
775+
continue;
776+
}
777+
772778
if (header.block<blknum)
773-
elog(ERROR,"backup is broken atfile->path %s block %u",
774-
file->path,blknum);
779+
elog(ERROR,"Backup is broken atblock %u of \"%s\"",
780+
blknum,file->path);
775781

776782
blknum=header.block;
777783

@@ -792,7 +798,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
792798
read_len=fread(compressed_page.data,1,
793799
MAXALIGN(header.compressed_size),in);
794800
if (read_len!=MAXALIGN(header.compressed_size))
795-
elog(ERROR,"cannot read block %u of \"%s\" read %zu of %d",
801+
elog(ERROR,"Cannot read block %u of \"%s\" read %zu of %d",
796802
blknum,file->path,read_len,header.compressed_size);
797803

798804
/*
@@ -816,7 +822,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
816822
blknum,file->path,errormsg);
817823

818824
if (uncompressed_size!=BLCKSZ)
819-
elog(ERROR,"page of file \"%s\" uncompressed to %d bytes. != BLCKSZ",
825+
elog(ERROR,"Page of file \"%s\" uncompressed to %d bytes. != BLCKSZ",
820826
file->path,uncompressed_size);
821827
}
822828

@@ -827,15 +833,15 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
827833
* Seek and write the restored page.
828834
*/
829835
if (fseek(out,write_pos,SEEK_SET)<0)
830-
elog(ERROR,"cannot seek block %u of \"%s\": %s",
836+
elog(ERROR,"Cannot seek block %u of \"%s\": %s",
831837
blknum,to_path,strerror(errno));
832838

833839
if (write_header)
834840
{
835841
/* We uncompressed the page, so its size is BLCKSZ */
836842
header.compressed_size=BLCKSZ;
837843
if (fwrite(&header,1,sizeof(header),out)!=sizeof(header))
838-
elog(ERROR,"cannot write header of block %u of \"%s\": %s",
844+
elog(ERROR,"Cannot write header of block %u of \"%s\": %s",
839845
blknum,file->path,strerror(errno));
840846
}
841847

@@ -846,14 +852,14 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
846852
if (uncompressed_size==BLCKSZ)
847853
{
848854
if (fwrite(page.data,1,BLCKSZ,out)!=BLCKSZ)
849-
elog(ERROR,"cannot write block %u of \"%s\": %s",
855+
elog(ERROR,"Cannot write block %u of \"%s\": %s",
850856
blknum,file->path,strerror(errno));
851857
}
852858
else
853859
{
854860
/* */
855861
if (fwrite(compressed_page.data,1,BLCKSZ,out)!=BLCKSZ)
856-
elog(ERROR,"cannot write block %u of \"%s\": %s",
862+
elog(ERROR,"Cannot write block %u of \"%s\": %s",
857863
blknum,file->path,strerror(errno));
858864
}
859865
}
@@ -891,7 +897,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
891897
* Truncate file to this length.
892898
*/
893899
if (ftruncate(fileno(out),write_pos)!=0)
894-
elog(ERROR,"cannot truncate \"%s\": %s",
900+
elog(ERROR,"Cannot truncate \"%s\": %s",
895901
file->path,strerror(errno));
896902
elog(VERBOSE,"Delta truncate file %s to block %u",
897903
file->path,truncate_from);
@@ -905,14 +911,14 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
905911
if (in)
906912
fclose(in);
907913
fclose(out);
908-
elog(ERROR,"cannot change mode of \"%s\": %s",to_path,
914+
elog(ERROR,"Cannot change mode of \"%s\": %s",to_path,
909915
strerror(errno_tmp));
910916
}
911917

912918
if (fflush(out)!=0||
913919
fsync(fileno(out))!=0||
914920
fclose(out))
915-
elog(ERROR,"cannot write \"%s\": %s",to_path,strerror(errno));
921+
elog(ERROR,"Cannot write \"%s\": %s",to_path,strerror(errno));
916922
if (in)
917923
fclose(in);
918924
}
@@ -1571,7 +1577,7 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
15711577
pg_crc32crc;
15721578
booluse_crc32c=backup_version <=20021||backup_version >=20025;
15731579

1574-
elog(VERBOSE,"validate relation blocks for file %s",file->path);
1580+
elog(VERBOSE,"Validate relation blocks for file %s",file->path);
15751581

15761582
in=fopen(file->path,PG_BINARY_R);
15771583
if (in==NULL)
@@ -1582,7 +1588,7 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
15821588
return false;
15831589
}
15841590

1585-
elog(ERROR,"cannot open file \"%s\": %s",
1591+
elog(ERROR,"Cannot open file \"%s\": %s",
15861592
file->path,strerror(errno));
15871593
}
15881594

@@ -1606,29 +1612,35 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
16061612
break;/* EOF found */
16071613
elseif (read_len!=0&&feof(in))
16081614
elog(WARNING,
1609-
"odd size page found at block %u of \"%s\"",
1615+
"Odd size page found at block %u of \"%s\"",
16101616
blknum,file->path);
16111617
else
1612-
elog(WARNING,"cannot read header of block %u of \"%s\": %s",
1618+
elog(WARNING,"Cannot read header of block %u of \"%s\": %s",
16131619
blknum,file->path,strerror(errno_tmp));
16141620
return false;
16151621
}
16161622

16171623
COMP_FILE_CRC32(use_crc32c,crc,&header,read_len);
16181624

1625+
if (header.block==0&&header.compressed_size==0)
1626+
{
1627+
elog(VERBOSE,"Skip empty block of \"%s\"",file->path);
1628+
continue;
1629+
}
1630+
16191631
if (header.block<blknum)
16201632
{
1621-
elog(WARNING,"backup is broken atfile->path %s block %u",
1622-
file->path,blknum);
1633+
elog(WARNING,"Backup is broken atblock %u of \"%s\"",
1634+
blknum,file->path);
16231635
return false;
16241636
}
16251637

16261638
blknum=header.block;
16271639

16281640
if (header.compressed_size==PageIsTruncated)
16291641
{
1630-
elog(LOG,"File %s, block %u is truncated",
1631-
file->path,blknum);
1642+
elog(LOG,"Block %u of \"%s\" is truncated",
1643+
blknum,file->path);
16321644
continue;
16331645
}
16341646

@@ -1638,7 +1650,7 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
16381650
MAXALIGN(header.compressed_size),in);
16391651
if (read_len!=MAXALIGN(header.compressed_size))
16401652
{
1641-
elog(WARNING,"cannot read block %u of \"%s\" read %zu of %d",
1653+
elog(WARNING,"Cannot read block %u of \"%s\" read %zu of %d",
16421654
blknum,file->path,read_len,header.compressed_size);
16431655
return false;
16441656
}
@@ -1668,7 +1680,7 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
16681680
is_valid= false;
16691681
continue;
16701682
}
1671-
elog(WARNING,"page of file \"%s\" uncompressed to %d bytes. != BLCKSZ",
1683+
elog(WARNING,"Page of file \"%s\" uncompressed to %d bytes. != BLCKSZ",
16721684
file->path,uncompressed_size);
16731685
return false;
16741686
}
@@ -1690,7 +1702,7 @@ check_file_pages(pgFile *file, XLogRecPtr stop_lsn, uint32 checksum_version,
16901702

16911703
if (crc!=file->crc)
16921704
{
1693-
elog(WARNING,"Invalid CRC of backup file \"%s\": %X. Expected %X",
1705+
elog(WARNING,"Invalid CRC of backup file \"%s\": %X. Expected %X",
16941706
file->path,file->crc,crc);
16951707
is_valid= false;
16961708
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp