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

Commita8d0732

Browse files
committed
Remove manual tracking of file position in pg_dump/pg_backup_custom.c.
We do not really need to track the file position by hand. We werealready relying on ftello() whenever the archive file is seekable,while if it's not seekable we don't need the file position infoanyway because we're not going to be able to re-write the TOC.Moreover, that tracking was buggy since it failed to account forthe effects of fseeko(). Somewhat remarkably, that seems not tohave made for any live bugs up to now. We could fix the oversights,but it seems better to just get rid of the whole error-prone mess.In itself this is merely code cleanup. However, it's necessaryinfrastructure for an upcoming bug-fix patch (because that code*does* need valid file position after fseeko). The bug fixneeds to go back as far as v12; hence, back-patch that far.Discussion:https://postgr.es/m/CALBH9DDuJ+scZc4MEvw5uO-=vRyR2=QF9+Yh=3hPEnKHWfS81A@mail.gmail.com
1 parent5da8bf8 commita8d0732

File tree

1 file changed

+14
-39
lines changed

1 file changed

+14
-39
lines changed

‎src/bin/pg_dump/pg_backup_custom.c

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,12 @@ typedef struct
7070
{
7171
CompressorState*cs;
7272
inthasSeek;
73-
pgoff_tfilePos;
74-
pgoff_tdataStart;
7573
}lclContext;
7674

7775
typedefstruct
7876
{
7977
intdataState;
80-
pgoff_tdataPos;
78+
pgoff_tdataPos;/* valid only if dataState=K_OFFSET_POS_SET */
8179
}lclTocEntry;
8280

8381

@@ -144,8 +142,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
144142
AH->lo_buf_size=LOBBUFSIZE;
145143
AH->lo_buf= (void*)pg_malloc(LOBBUFSIZE);
146144

147-
ctx->filePos=0;
148-
149145
/*
150146
* Now open the file
151147
*/
@@ -185,7 +181,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
185181

186182
ReadHead(AH);
187183
ReadToc(AH);
188-
ctx->dataStart=_getFilePos(AH,ctx);
189184
}
190185

191186
}
@@ -290,7 +285,8 @@ _StartData(ArchiveHandle *AH, TocEntry *te)
290285
lclTocEntry*tctx= (lclTocEntry*)te->formatData;
291286

292287
tctx->dataPos=_getFilePos(AH,ctx);
293-
tctx->dataState=K_OFFSET_POS_SET;
288+
if (tctx->dataPos >=0)
289+
tctx->dataState=K_OFFSET_POS_SET;
294290

295291
_WriteByte(AH,BLK_DATA);/* Block type */
296292
WriteInt(AH,te->dumpId);/* For sanity check */
@@ -350,7 +346,8 @@ _StartBlobs(ArchiveHandle *AH, TocEntry *te)
350346
lclTocEntry*tctx= (lclTocEntry*)te->formatData;
351347

352348
tctx->dataPos=_getFilePos(AH,ctx);
353-
tctx->dataState=K_OFFSET_POS_SET;
349+
if (tctx->dataPos >=0)
350+
tctx->dataState=K_OFFSET_POS_SET;
354351

355352
_WriteByte(AH,BLK_BLOBS);/* Block type */
356353
WriteInt(AH,te->dumpId);/* For sanity check */
@@ -551,7 +548,6 @@ _skipBlobs(ArchiveHandle *AH)
551548
staticvoid
552549
_skipData(ArchiveHandle*AH)
553550
{
554-
lclContext*ctx= (lclContext*)AH->formatData;
555551
size_tblkLen;
556552
char*buf=NULL;
557553
intbuflen=0;
@@ -575,8 +571,6 @@ _skipData(ArchiveHandle *AH)
575571
fatal("could not read from input file: %m");
576572
}
577573

578-
ctx->filePos+=blkLen;
579-
580574
blkLen=ReadInt(AH);
581575
}
582576

@@ -594,12 +588,10 @@ _skipData(ArchiveHandle *AH)
594588
staticint
595589
_WriteByte(ArchiveHandle*AH,constinti)
596590
{
597-
lclContext*ctx= (lclContext*)AH->formatData;
598591
intres;
599592

600593
if ((res=fputc(i,AH->FH))==EOF)
601594
WRITE_ERROR_EXIT;
602-
ctx->filePos+=1;
603595

604596
return1;
605597
}
@@ -615,13 +607,11 @@ _WriteByte(ArchiveHandle *AH, const int i)
615607
staticint
616608
_ReadByte(ArchiveHandle*AH)
617609
{
618-
lclContext*ctx= (lclContext*)AH->formatData;
619610
intres;
620611

621612
res=getc(AH->FH);
622613
if (res==EOF)
623614
READ_ERROR_EXIT(AH->FH);
624-
ctx->filePos+=1;
625615
returnres;
626616
}
627617

@@ -635,11 +625,8 @@ _ReadByte(ArchiveHandle *AH)
635625
staticvoid
636626
_WriteBuf(ArchiveHandle*AH,constvoid*buf,size_tlen)
637627
{
638-
lclContext*ctx= (lclContext*)AH->formatData;
639-
640628
if (fwrite(buf,1,len,AH->FH)!=len)
641629
WRITE_ERROR_EXIT;
642-
ctx->filePos+=len;
643630
}
644631

645632
/*
@@ -652,11 +639,8 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
652639
staticvoid
653640
_ReadBuf(ArchiveHandle*AH,void*buf,size_tlen)
654641
{
655-
lclContext*ctx= (lclContext*)AH->formatData;
656-
657642
if (fread(buf,1,len,AH->FH)!=len)
658643
READ_ERROR_EXIT(AH->FH);
659-
ctx->filePos+=len;
660644
}
661645

662646
/*
@@ -688,7 +672,6 @@ _CloseArchive(ArchiveHandle *AH)
688672
if (tpos<0&&ctx->hasSeek)
689673
fatal("could not determine seek position in archive file: %m");
690674
WriteToc(AH);
691-
ctx->dataStart=_getFilePos(AH,ctx);
692675
WriteDataChunks(AH,NULL);
693676

694677
/*
@@ -862,30 +845,24 @@ _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
862845

863846
/*
864847
* Get the current position in the archive file.
848+
*
849+
* With a non-seekable archive file, we may not be able to obtain the
850+
* file position. If so, just return -1. It's not too important in
851+
* that case because we won't be able to rewrite the TOC to fill in
852+
* data block offsets anyway.
865853
*/
866854
staticpgoff_t
867855
_getFilePos(ArchiveHandle*AH,lclContext*ctx)
868856
{
869857
pgoff_tpos;
870858

871-
if (ctx->hasSeek)
859+
pos=ftello(AH->FH);
860+
if (pos<0)
872861
{
873-
/*
874-
* Prior to 1.7 (pg7.3) we relied on the internally maintained
875-
* pointer. Now we rely on ftello() always, unless the file has been
876-
* found to not support it. For debugging purposes, print a warning
877-
* if the internal pointer disagrees, so that we're more likely to
878-
* notice if something's broken about the internal position tracking.
879-
*/
880-
pos=ftello(AH->FH);
881-
if (pos<0)
862+
/* Not expected if we found we can seek. */
863+
if (ctx->hasSeek)
882864
fatal("could not determine seek position in archive file: %m");
883-
884-
if (pos!=ctx->filePos)
885-
pg_log_warning("ftell mismatch with expected position -- ftell used");
886865
}
887-
else
888-
pos=ctx->filePos;
889866
returnpos;
890867
}
891868

@@ -897,7 +874,6 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
897874
staticvoid
898875
_readBlockHeader(ArchiveHandle*AH,int*type,int*id)
899876
{
900-
lclContext*ctx= (lclContext*)AH->formatData;
901877
intbyt;
902878

903879
/*
@@ -918,7 +894,6 @@ _readBlockHeader(ArchiveHandle *AH, int *type, int *id)
918894
*id=0;/* don't return an uninitialized value */
919895
return;
920896
}
921-
ctx->filePos+=1;
922897
}
923898

924899
*id=ReadInt(AH);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp