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

Commit923e8de

Browse files
committed
Add defenses against pre-crash files to BufFileOpenShared().
Crash restarts currently don't clean up temporary files, as a debugging aid.If a left-over file happens to have the same name as a segment file we'retrying to create, we'll just truncate and reuse it, but there is a problem:BufFileOpenShared() determines how many segment files exist by trying to open.0, .1, .2, ... until it finds no more files. It might be confused by a junkfile that has the next segment number. To defend against that, make sure wealways create a gap after the end file by unlinking the following name if itexists. Also make it an error to try to open a BufFile that doesn't exist(has no segment 0), so as not to encourage the development of client codethat depends on an interface that we can't reliably provide.Author: Thomas MunroReviewed-By: Andres FreundDiscussion:https://postgr.es/m/CAEepm%3D2jhCbC_GFQJaaDhWxLB4EXtT3vVd5czuRNaqF5CWSTog%40mail.gmail.com
1 parent884a608 commit923e8de

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

‎src/backend/storage/file/buffile.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,16 @@ MakeNewSharedSegment(BufFile *buffile, int segment)
211211
charname[MAXPGPATH];
212212
Filefile;
213213

214+
/*
215+
* It is possible that there are files left over from before a crash
216+
* restart with the same name. In order for BufFileOpenShared()
217+
* not to get confused about how many segments there are, we'll unlink
218+
* the next segment number if it already exists.
219+
*/
220+
SharedSegmentName(name,buffile->name,segment+1);
221+
SharedFileSetDelete(buffile->fileset,name, true);
222+
223+
/* Create the new segment. */
214224
SharedSegmentName(name,buffile->name,segment);
215225
file=SharedFileSetCreate(buffile->fileset,name);
216226

@@ -303,7 +313,9 @@ BufFileOpenShared(SharedFileSet *fileset, const char *name)
303313
* name.
304314
*/
305315
if (nfiles==0)
306-
returnNULL;
316+
ereport(ERROR,
317+
(errcode_for_file_access(),
318+
errmsg("could not open BufFile \"%s\"",name)));
307319

308320
file->numFiles=nfiles;
309321
file->files=files;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp