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

Commit47ac203

Browse files
committed
Simplify some ERROR paths clearing wait events and transient files
Transient files and wait events get normally cleaned up when seeing anexception (be it in the context of a transaction for a backend oranother process like the checkpointer), hence there is little point incomplicating error code paths to do this work. This shaves a bit ofcode, and removes some extra handling with errno which needed to bepreserved during the cleanup steps done.Reported-by: Masahiko SawadaAuthor: Michael PaquierReviewed-by: Tom Lane, Masahiko SawadaDiscussion:https://postgr.es/m/CAD21AoDhHYVq5KkXfkaHhmjA-zJYj-e4teiRAJefvXuKJz1tKQ@mail.gmail.com
1 parenta6dcf9d commit47ac203

File tree

4 files changed

+10
-48
lines changed

4 files changed

+10
-48
lines changed

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,26 +1693,18 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
16931693
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_WRITE);
16941694
if (write(fd,content,len)!=len)
16951695
{
1696-
intsave_errno=errno;
1697-
1698-
pgstat_report_wait_end();
1699-
CloseTransientFile(fd);
1700-
17011696
/* if write didn't set errno, assume problem is no disk space */
1702-
errno=save_errno ?save_errno :ENOSPC;
1697+
if (errno==0)
1698+
errno=ENOSPC;
17031699
ereport(ERROR,
17041700
(errcode_for_file_access(),
17051701
errmsg("could not write file \"%s\": %m",path)));
17061702
}
17071703
if (write(fd,&statefile_crc,sizeof(pg_crc32c))!=sizeof(pg_crc32c))
17081704
{
1709-
intsave_errno=errno;
1710-
1711-
pgstat_report_wait_end();
1712-
CloseTransientFile(fd);
1713-
17141705
/* if write didn't set errno, assume problem is no disk space */
1715-
errno=save_errno ?save_errno :ENOSPC;
1706+
if (errno==0)
1707+
errno=ENOSPC;
17161708
ereport(ERROR,
17171709
(errcode_for_file_access(),
17181710
errmsg("could not write file \"%s\": %m",path)));
@@ -1725,15 +1717,9 @@ RecreateTwoPhaseFile(TransactionId xid, void *content, int len)
17251717
*/
17261718
pgstat_report_wait_start(WAIT_EVENT_TWOPHASE_FILE_SYNC);
17271719
if (pg_fsync(fd)!=0)
1728-
{
1729-
intsave_errno=errno;
1730-
1731-
CloseTransientFile(fd);
1732-
errno=save_errno;
17331720
ereport(ERROR,
17341721
(errcode_for_file_access(),
17351722
errmsg("could not fsync file \"%s\": %m",path)));
1736-
}
17371723
pgstat_report_wait_end();
17381724

17391725
if (CloseTransientFile(fd)!=0)

‎src/backend/replication/logical/origin.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,9 @@ CheckPointReplicationOrigin(void)
579579
errno=0;
580580
if ((write(tmpfd,&magic,sizeof(magic)))!=sizeof(magic))
581581
{
582-
intsave_errno=errno;
583-
584-
CloseTransientFile(tmpfd);
585-
586582
/* if write didn't set errno, assume problem is no disk space */
587-
errno=save_errno ?save_errno :ENOSPC;
583+
if (errno==0)
584+
errno=ENOSPC;
588585
ereport(PANIC,
589586
(errcode_for_file_access(),
590587
errmsg("could not write to file \"%s\": %m",
@@ -624,12 +621,9 @@ CheckPointReplicationOrigin(void)
624621
if ((write(tmpfd,&disk_state,sizeof(disk_state)))!=
625622
sizeof(disk_state))
626623
{
627-
intsave_errno=errno;
628-
629-
CloseTransientFile(tmpfd);
630-
631624
/* if write didn't set errno, assume problem is no disk space */
632-
errno=save_errno ?save_errno :ENOSPC;
625+
if (errno==0)
626+
errno=ENOSPC;
633627
ereport(PANIC,
634628
(errcode_for_file_access(),
635629
errmsg("could not write to file \"%s\": %m",
@@ -646,12 +640,9 @@ CheckPointReplicationOrigin(void)
646640
errno=0;
647641
if ((write(tmpfd,&crc,sizeof(crc)))!=sizeof(crc))
648642
{
649-
intsave_errno=errno;
650-
651-
CloseTransientFile(tmpfd);
652-
653643
/* if write didn't set errno, assume problem is no disk space */
654-
errno=save_errno ?save_errno :ENOSPC;
644+
if (errno==0)
645+
errno=ENOSPC;
655646
ereport(PANIC,
656647
(errcode_for_file_access(),
657648
errmsg("could not write to file \"%s\": %m",

‎src/backend/replication/slot.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,16 +1398,10 @@ RestoreSlotFromDisk(const char *name)
13981398
*/
13991399
pgstat_report_wait_start(WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC);
14001400
if (pg_fsync(fd)!=0)
1401-
{
1402-
intsave_errno=errno;
1403-
1404-
CloseTransientFile(fd);
1405-
errno=save_errno;
14061401
ereport(PANIC,
14071402
(errcode_for_file_access(),
14081403
errmsg("could not fsync file \"%s\": %m",
14091404
path)));
1410-
}
14111405
pgstat_report_wait_end();
14121406

14131407
/* Also sync the parent directory */
@@ -1421,10 +1415,6 @@ RestoreSlotFromDisk(const char *name)
14211415
pgstat_report_wait_end();
14221416
if (readBytes!=ReplicationSlotOnDiskConstantSize)
14231417
{
1424-
intsaved_errno=errno;
1425-
1426-
CloseTransientFile(fd);
1427-
errno=saved_errno;
14281418
if (readBytes<0)
14291419
ereport(PANIC,
14301420
(errcode_for_file_access(),
@@ -1466,10 +1456,6 @@ RestoreSlotFromDisk(const char *name)
14661456
pgstat_report_wait_end();
14671457
if (readBytes!=cp.length)
14681458
{
1469-
intsaved_errno=errno;
1470-
1471-
CloseTransientFile(fd);
1472-
errno=saved_errno;
14731459
if (readBytes<0)
14741460
ereport(PANIC,
14751461
(errcode_for_file_access(),

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ copy_file(char *fromfile, char *tofile)
199199
pgstat_report_wait_start(WAIT_EVENT_COPY_FILE_WRITE);
200200
if ((int)write(dstfd,buffer,nbytes)!=nbytes)
201201
{
202-
pgstat_report_wait_end();
203202
/* if write didn't set errno, assume problem is no disk space */
204203
if (errno==0)
205204
errno=ENOSPC;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp