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

Commitd0024cd

Browse files
committed
Avoid crashing when we have problems unlinking files post-commit.
smgrdounlink takes care to not throw an ERROR if it fails to unlinksomething, but that caution was rendered useless by commit3396000, which put an smgrexists call infront of it; smgrexists *does* throw error if anything looks funny, suchas getting a permissions error from trying to open the file. If thathappens post-commit, you get a PANIC, and what's worse the same logicappears in the WAL replay code, so the database even fails to restart.Restore the intended behavior by removing the smgrexists call --- it isn'taccomplishing anything that we can't do better by adjusting mdunlink'sideas of whether it ought to warn about ENOENT or not.Per report from Joseph Shraibman of unrecoverable crash after trying todrop a table whose FSM fork had somehow gotten chmod'd to 000 permissions.Backpatch to 8.4, where the bogus coding was introduced.
1 parent7292055 commitd0024cd

File tree

4 files changed

+20
-26
lines changed

4 files changed

+20
-26
lines changed

‎src/backend/access/transam/twophase.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,8 +1366,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
13661366

13671367
for (fork=0;fork <=MAX_FORKNUM;fork++)
13681368
{
1369-
if (smgrexists(srel,fork))
1370-
smgrdounlink(srel,fork, false);
1369+
smgrdounlink(srel,fork, false);
13711370
}
13721371
smgrclose(srel);
13731372
}

‎src/backend/access/transam/xact.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,11 +4595,8 @@ xact_redo_commit_internal(TransactionId xid, XLogRecPtr lsn,
45954595

45964596
for (fork=0;fork <=MAX_FORKNUM;fork++)
45974597
{
4598-
if (smgrexists(srel,fork))
4599-
{
4600-
XLogDropRelation(xnodes[i],fork);
4601-
smgrdounlink(srel,fork, true);
4602-
}
4598+
XLogDropRelation(xnodes[i],fork);
4599+
smgrdounlink(srel,fork, true);
46034600
}
46044601
smgrclose(srel);
46054602
}
@@ -4738,11 +4735,8 @@ xact_redo_abort(xl_xact_abort *xlrec, TransactionId xid)
47384735

47394736
for (fork=0;fork <=MAX_FORKNUM;fork++)
47404737
{
4741-
if (smgrexists(srel,fork))
4742-
{
4743-
XLogDropRelation(xlrec->xnodes[i],fork);
4744-
smgrdounlink(srel,fork, true);
4745-
}
4738+
XLogDropRelation(xlrec->xnodes[i],fork);
4739+
smgrdounlink(srel,fork, true);
47464740
}
47474741
smgrclose(srel);
47484742
}

‎src/backend/catalog/storage.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ smgrDoPendingDeletes(bool isCommit)
361361
srel=smgropen(pending->relnode,pending->backend);
362362
for (i=0;i <=MAX_FORKNUM;i++)
363363
{
364-
if (smgrexists(srel,i))
365-
smgrdounlink(srel,i, false);
364+
smgrdounlink(srel,i, false);
366365
}
367366
smgrclose(srel);
368367
}

‎src/backend/storage/smgr/md.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,13 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
323323
* number until it's safe, because relfilenode assignment skips over any
324324
* existing file.
325325
*
326-
* If isRedo is true, it's okay for the relation to be already gone.
326+
* All the above applies only to the relation's main fork; other forks can
327+
* just be removed immediately, since they are not needed to prevent the
328+
* relfilenode number from being recycled. Also, we do not carefully
329+
* track whether other forks have been created or not, but just attempt to
330+
* unlink them unconditionally; so we should never complain about ENOENT.
331+
*
332+
* If isRedo is true, it's unsurprising for the relation to be already gone.
327333
* Also, we should remove the file immediately instead of queuing a request
328334
* for later, since during redo there's no possibility of creating a
329335
* conflicting relation.
@@ -351,13 +357,10 @@ mdunlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo)
351357
if (isRedo||forkNum!=MAIN_FORKNUM)
352358
{
353359
ret=unlink(path);
354-
if (ret<0)
355-
{
356-
if (!isRedo||errno!=ENOENT)
357-
ereport(WARNING,
358-
(errcode_for_file_access(),
359-
errmsg("could not remove file \"%s\": %m",path)));
360-
}
360+
if (ret<0&&errno!=ENOENT)
361+
ereport(WARNING,
362+
(errcode_for_file_access(),
363+
errmsg("could not remove file \"%s\": %m",path)));
361364
}
362365
else
363366
{
@@ -380,6 +383,9 @@ mdunlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo)
380383
ereport(WARNING,
381384
(errcode_for_file_access(),
382385
errmsg("could not truncate file \"%s\": %m",path)));
386+
387+
/* Register request to unlink first segment later */
388+
register_unlink(rnode);
383389
}
384390

385391
/*
@@ -411,10 +417,6 @@ mdunlink(RelFileNodeBackend rnode, ForkNumber forkNum, bool isRedo)
411417
}
412418

413419
pfree(path);
414-
415-
/* Register request to unlink first segment later */
416-
if (!isRedo&&forkNum==MAIN_FORKNUM)
417-
register_unlink(rnode);
418420
}
419421

420422
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp