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

Commit39a068c

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 parenta40733d commit39a068c

File tree

1 file changed

+14
-43
lines changed

1 file changed

+14
-43
lines changed

‎src/bin/pg_dump/pg_backup_custom.c

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,12 @@ typedef struct
7171
{
7272
CompressorState*cs;
7373
inthasSeek;
74-
pgoff_tfilePos;
75-
pgoff_tdataStart;
7674
}lclContext;
7775

7876
typedefstruct
7977
{
8078
intdataState;
81-
pgoff_tdataPos;
79+
pgoff_tdataPos;/* valid only if dataState=K_OFFSET_POS_SET */
8280
}lclTocEntry;
8381

8482

@@ -145,8 +143,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
145143
AH->lo_buf_size=LOBBUFSIZE;
146144
AH->lo_buf= (void*)pg_malloc(LOBBUFSIZE);
147145

148-
ctx->filePos=0;
149-
150146
/*
151147
* Now open the file
152148
*/
@@ -186,7 +182,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
186182

187183
ReadHead(AH);
188184
ReadToc(AH);
189-
ctx->dataStart=_getFilePos(AH,ctx);
190185
}
191186

192187
}
@@ -292,7 +287,8 @@ _StartData(ArchiveHandle *AH, TocEntry *te)
292287
lclTocEntry*tctx= (lclTocEntry*)te->formatData;
293288

294289
tctx->dataPos=_getFilePos(AH,ctx);
295-
tctx->dataState=K_OFFSET_POS_SET;
290+
if (tctx->dataPos >=0)
291+
tctx->dataState=K_OFFSET_POS_SET;
296292

297293
_WriteByte(AH,BLK_DATA);/* Block type */
298294
WriteInt(AH,te->dumpId);/* For sanity check */
@@ -355,7 +351,8 @@ _StartBlobs(ArchiveHandle *AH, TocEntry *te)
355351
lclTocEntry*tctx= (lclTocEntry*)te->formatData;
356352

357353
tctx->dataPos=_getFilePos(AH,ctx);
358-
tctx->dataState=K_OFFSET_POS_SET;
354+
if (tctx->dataPos >=0)
355+
tctx->dataState=K_OFFSET_POS_SET;
359356

360357
_WriteByte(AH,BLK_BLOBS);/* Block type */
361358
WriteInt(AH,te->dumpId);/* For sanity check */
@@ -556,7 +553,6 @@ _skipBlobs(ArchiveHandle *AH)
556553
staticvoid
557554
_skipData(ArchiveHandle*AH)
558555
{
559-
lclContext*ctx= (lclContext*)AH->formatData;
560556
size_tblkLen;
561557
char*buf=NULL;
562558
intbuflen=0;
@@ -580,8 +576,6 @@ _skipData(ArchiveHandle *AH)
580576
fatal("could not read from input file: %m");
581577
}
582578

583-
ctx->filePos+=blkLen;
584-
585579
blkLen=ReadInt(AH);
586580
}
587581

@@ -599,12 +593,10 @@ _skipData(ArchiveHandle *AH)
599593
staticint
600594
_WriteByte(ArchiveHandle*AH,constinti)
601595
{
602-
lclContext*ctx= (lclContext*)AH->formatData;
603596
intres;
604597

605598
if ((res=fputc(i,AH->FH))==EOF)
606599
WRITE_ERROR_EXIT;
607-
ctx->filePos+=1;
608600

609601
return1;
610602
}
@@ -620,13 +612,11 @@ _WriteByte(ArchiveHandle *AH, const int i)
620612
staticint
621613
_ReadByte(ArchiveHandle*AH)
622614
{
623-
lclContext*ctx= (lclContext*)AH->formatData;
624615
intres;
625616

626617
res=getc(AH->FH);
627618
if (res==EOF)
628619
READ_ERROR_EXIT(AH->FH);
629-
ctx->filePos+=1;
630620
returnres;
631621
}
632622

@@ -640,13 +630,8 @@ _ReadByte(ArchiveHandle *AH)
640630
staticvoid
641631
_WriteBuf(ArchiveHandle*AH,constvoid*buf,size_tlen)
642632
{
643-
lclContext*ctx= (lclContext*)AH->formatData;
644-
645633
if (fwrite(buf,1,len,AH->FH)!=len)
646634
WRITE_ERROR_EXIT;
647-
ctx->filePos+=len;
648-
649-
return;
650635
}
651636

652637
/*
@@ -659,13 +644,8 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
659644
staticvoid
660645
_ReadBuf(ArchiveHandle*AH,void*buf,size_tlen)
661646
{
662-
lclContext*ctx= (lclContext*)AH->formatData;
663-
664647
if (fread(buf,1,len,AH->FH)!=len)
665648
READ_ERROR_EXIT(AH->FH);
666-
ctx->filePos+=len;
667-
668-
return;
669649
}
670650

671651
/*
@@ -697,7 +677,6 @@ _CloseArchive(ArchiveHandle *AH)
697677
if (tpos<0&&ctx->hasSeek)
698678
fatal("could not determine seek position in archive file: %m");
699679
WriteToc(AH);
700-
ctx->dataStart=_getFilePos(AH,ctx);
701680
WriteDataChunks(AH,NULL);
702681

703682
/*
@@ -871,30 +850,24 @@ _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
871850

872851
/*
873852
* Get the current position in the archive file.
853+
*
854+
* With a non-seekable archive file, we may not be able to obtain the
855+
* file position. If so, just return -1. It's not too important in
856+
* that case because we won't be able to rewrite the TOC to fill in
857+
* data block offsets anyway.
874858
*/
875859
staticpgoff_t
876860
_getFilePos(ArchiveHandle*AH,lclContext*ctx)
877861
{
878862
pgoff_tpos;
879863

880-
if (ctx->hasSeek)
864+
pos=ftello(AH->FH);
865+
if (pos<0)
881866
{
882-
/*
883-
* Prior to 1.7 (pg7.3) we relied on the internally maintained
884-
* pointer. Now we rely on ftello() always, unless the file has been
885-
* found to not support it. For debugging purposes, print a warning
886-
* if the internal pointer disagrees, so that we're more likely to
887-
* notice if something's broken about the internal position tracking.
888-
*/
889-
pos=ftello(AH->FH);
890-
if (pos<0)
867+
/* Not expected if we found we can seek. */
868+
if (ctx->hasSeek)
891869
fatal("could not determine seek position in archive file: %m");
892-
893-
if (pos!=ctx->filePos)
894-
pg_log_warning("ftell mismatch with expected position -- ftell used");
895870
}
896-
else
897-
pos=ctx->filePos;
898871
returnpos;
899872
}
900873

@@ -906,7 +879,6 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
906879
staticvoid
907880
_readBlockHeader(ArchiveHandle*AH,int*type,int*id)
908881
{
909-
lclContext*ctx= (lclContext*)AH->formatData;
910882
intbyt;
911883

912884
/*
@@ -927,7 +899,6 @@ _readBlockHeader(ArchiveHandle *AH, int *type, int *id)
927899
*id=0;/* don't return an uninitialized value */
928900
return;
929901
}
930-
ctx->filePos+=1;
931902
}
932903

933904
*id=ReadInt(AH);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp