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

Commit74b25e4

Browse files
committed
Revert "Decompress restored file by remote agent"
This reverts commit3873318.
1 parentde38db4 commit74b25e4

File tree

4 files changed

+49
-79
lines changed

4 files changed

+49
-79
lines changed

‎src/data.c

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ do_compress(void* dst, size_t dst_size, void const* src, size_t src_size,
8989
* Decompresses source into dest using algorithm. Returns the number of bytes
9090
* decompressed in the destination buffer, or -1 if decompression fails.
9191
*/
92-
int32
92+
staticint32
9393
do_decompress(void*dst,size_tdst_size,voidconst*src,size_tsrc_size,
9494
CompressAlgalg,constchar**errormsg)
9595
{
@@ -719,7 +719,6 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
719719
BlockNumberblknum=0,
720720
truncate_from=0;
721721
boolneed_truncate= false;
722-
size_trc;
723722

724723
/* BYTES_INVALID allowed only in case of restoring file from DELTA backup */
725724
if (file->write_size!=BYTES_INVALID)
@@ -751,9 +750,9 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
751750
{
752751
off_twrite_pos;
753752
size_tread_len;
753+
DataPagecompressed_page;/* used as read buffer */
754754
DataPagepage;
755-
int32compressed_size;
756-
constchar*errormsg=NULL;
755+
int32uncompressed_size=0;
757756

758757
/* File didn`t changed. Nothig to copy */
759758
if (file->write_size==BYTES_INVALID)
@@ -790,9 +789,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
790789
blknum,file->path,strerror(errno_tmp));
791790
}
792791

793-
compressed_size=header.compressed_size;
794-
795-
if (header.block==0&&compressed_size)
792+
if (header.block==0&&header.compressed_size==0)
796793
{
797794
elog(VERBOSE,"Skip empty block of \"%s\"",file->path);
798795
continue;
@@ -804,7 +801,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
804801

805802
blknum=header.block;
806803

807-
if (compressed_size==PageIsTruncated)
804+
if (header.compressed_size==PageIsTruncated)
808805
{
809806
/*
810807
* Backup contains information that this block was truncated.
@@ -815,14 +812,39 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
815812
break;
816813
}
817814

818-
Assert(compressed_size <=BLCKSZ);
815+
Assert(header.compressed_size <=BLCKSZ);
819816

820817
/* read a page from file */
821-
read_len=fread(page.data,1,
822-
MAXALIGN(compressed_size),in);
823-
if (read_len!=MAXALIGN(compressed_size))
818+
read_len=fread(compressed_page.data,1,
819+
MAXALIGN(header.compressed_size),in);
820+
if (read_len!=MAXALIGN(header.compressed_size))
824821
elog(ERROR,"Cannot read block %u of \"%s\" read %zu of %d",
825-
blknum,file->path,read_len,compressed_size);
822+
blknum,file->path,read_len,header.compressed_size);
823+
824+
/*
825+
* if page size is smaller than BLCKSZ, decompress the page.
826+
* BUGFIX for versions < 2.0.23: if page size is equal to BLCKSZ.
827+
* we have to check, whether it is compressed or not using
828+
* page_may_be_compressed() function.
829+
*/
830+
if (header.compressed_size!=BLCKSZ
831+
||page_may_be_compressed(compressed_page.data,file->compress_alg,
832+
backup_version))
833+
{
834+
constchar*errormsg=NULL;
835+
836+
uncompressed_size=do_decompress(page.data,BLCKSZ,
837+
compressed_page.data,
838+
header.compressed_size,
839+
file->compress_alg,&errormsg);
840+
if (uncompressed_size<0&&errormsg!=NULL)
841+
elog(WARNING,"An error occured during decompressing block %u of file \"%s\": %s",
842+
blknum,file->path,errormsg);
843+
844+
if (uncompressed_size!=BLCKSZ)
845+
elog(ERROR,"Page of file \"%s\" uncompressed to %d bytes. != BLCKSZ",
846+
file->path,uncompressed_size);
847+
}
826848

827849
write_pos= (write_header) ?blknum* (BLCKSZ+sizeof(header)) :
828850
blknum*BLCKSZ;
@@ -843,24 +865,21 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
843865
blknum,file->path,strerror(errno));
844866
}
845867

846-
/*
847-
* if page size is smaller than BLCKSZ, decompress the page.
848-
* BUGFIX for versions < 2.0.23: if page size is equal to BLCKSZ.
849-
* we have to check, whether it is compressed or not using
850-
* page_may_be_compressed() function.
868+
/* if we uncompressed the page - write page.data,
869+
* if page wasn't compressed -
870+
* write what we've read - compressed_page.data
851871
*/
852-
rc= (compressed_size!=BLCKSZ||page_may_be_compressed(page.data,file->compress_alg,backup_version))
853-
?fio_fwrite_compressed(out,page.data,compressed_size,file->compress_alg,&errormsg)
854-
:fio_fwrite(out,page.data,compressed_size);
855-
856-
if (rc!=compressed_size)
872+
if (uncompressed_size==BLCKSZ)
857873
{
858-
if (errormsg!=NULL)
859-
elog(WARNING,"An error occured during decompressing block %u of file \"%s\": %s",
860-
blknum,file->path,errormsg);
861-
862-
elog(ERROR,"Cannot write block %u of \"%s\": %s",
863-
blknum,file->path,strerror(errno));
874+
if (fio_fwrite(out,page.data,BLCKSZ)!=BLCKSZ)
875+
elog(ERROR,"Cannot write block %u of \"%s\": %s",
876+
blknum,file->path,strerror(errno));
877+
}
878+
else
879+
{
880+
if (fio_fwrite(out,compressed_page.data,BLCKSZ)!=BLCKSZ)
881+
elog(ERROR,"Cannot write block %u of \"%s\": %s",
882+
blknum,file->path,strerror(errno));
864883
}
865884
}
866885

‎src/pg_probackup.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,6 @@ int32 do_compress(void* dst, size_t dst_size, void const* src, size_t src_size,
700700
externPGconn*pgdata_basic_setup(ConnectionOptionsconn_opt,PGNodeInfo*nodeInfo);
701701
externvoidcheck_system_identifiers(PGconn*conn,char*pgdata);
702702
externvoidparse_filelist_filenames(parray*files,constchar*root);
703-
externint32do_decompress(void*dst,size_tdst_size,voidconst*src,size_tsrc_size,
704-
CompressAlgalg,constchar**errormsg);
705703

706704

707705
#endif/* PG_PROBACKUP_H */

‎src/utils/file.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -566,35 +566,6 @@ size_t fio_fwrite(FILE* f, void const* buf, size_t size)
566566
:fwrite(buf,1,size,f);
567567
}
568568

569-
/* Write data to stdio file */
570-
size_tfio_fwrite_compressed(FILE*f,voidconst*buf,size_tsize,intcompress_alg,constchar**errmsg)
571-
{
572-
uint32decompressed_size;
573-
chardecompressed_page[BLCKSZ];
574-
575-
if (fio_is_remote_file(f))
576-
{
577-
fio_headerhdr;
578-
579-
hdr.cop=FIO_WRITE_COMPRESSED;
580-
hdr.handle=fio_fileno(f)& ~FIO_PIPE_MARKER;
581-
hdr.size=size;
582-
hdr.arg=compress_alg;
583-
584-
IO_CHECK(fio_write_all(fio_stdout,&hdr,sizeof(hdr)),sizeof(hdr));
585-
IO_CHECK(fio_write_all(fio_stdout,buf,size),size);
586-
587-
returnsize;
588-
}
589-
decompressed_size=do_decompress(decompressed_page,
590-
BLCKSZ,
591-
buf,
592-
size,
593-
(CompressAlg)compress_alg,errmsg);
594-
returndecompressed_size!=BLCKSZ
595-
?0 :fwrite(decompressed_page,1,decompressed_size,f);
596-
}
597-
598569
/* Write data to the file */
599570
ssize_tfio_write(intfd,voidconst*buf,size_tsize)
600571
{
@@ -1410,22 +1381,6 @@ void fio_communicate(int in, int out)
14101381
caseFIO_WRITE:/* Write to the current position in file */
14111382
IO_CHECK(fio_write_all(fd[hdr.handle],buf,hdr.size),hdr.size);
14121383
break;
1413-
caseFIO_WRITE_COMPRESSED:/* Write to the current position in file */
1414-
{
1415-
chardecompressed_page[BLCKSZ];
1416-
charconst*errmsg=NULL;
1417-
int32decompressed_size=do_decompress(decompressed_page,BLCKSZ,
1418-
buf,
1419-
hdr.size,
1420-
(CompressAlg)hdr.arg,&errmsg);
1421-
if (errmsg!=NULL||decompressed_size!=BLCKSZ)
1422-
{
1423-
fprintf(stderr,"Failed to decompress block: %s",errmsg ?errmsg:"unknown error");
1424-
exit(EXIT_FAILURE);
1425-
}
1426-
IO_CHECK(fio_write_all(fd[hdr.handle],decompressed_page,BLCKSZ),BLCKSZ);
1427-
}
1428-
break;
14291384
caseFIO_READ:/* Read from the current position in file */
14301385
if ((size_t)hdr.arg>buf_size) {
14311386
buf_size=hdr.arg;

‎src/utils/file.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ typedef enum
3333
FIO_READDIR,
3434
FIO_CLOSEDIR,
3535
FIO_SEND_PAGES,
36-
FIO_PAGE,
37-
FIO_WRITE_COMPRESSED,
36+
FIO_PAGE
3837
}fio_operations;
3938

4039
typedefenum
@@ -70,7 +69,6 @@ extern void fio_communicate(int in, int out);
7069

7170
externFILE*fio_fopen(charconst*name,charconst*mode,fio_locationlocation);
7271
externsize_tfio_fwrite(FILE*f,voidconst*buf,size_tsize);
73-
externsize_tfio_fwrite_compressed(FILE*f,voidconst*buf,size_tsize,intcompress_alg,constchar**errmsg);
7472
externssize_tfio_fread(FILE*f,void*buf,size_tsize);
7573
externintfio_pread(FILE*f,void*buf,off_toffs);
7674
externintfio_fprintf(FILE*f,charconst*arg, ...)pg_attribute_printf(2,3);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp