Skip to content

Commit 38fc056

Browse files
committed
Maintain valid md.c state when FileClose() fails.
FileClose() failure ordinarily causes a PANIC. Suppose the user disables that PANIC via data_sync_retry=on. After mdclose() issued a FileClose() that failed, calls into md.c raised SIGSEGV. This fix adds repalloc() calls during mdclose(); update a comment about ignoring repalloc() cost. The rate of relation segment count change is a minor factor; more relevant to overall performance is the rate of mdclose() and subsequent re-opening of segments. Back-patch to v10, where commit 45e191e introduced the bug. Reviewed by Kyotaro Horiguchi. Discussion: https://postgr.es/m/20191222091930.GA1280238@rfd.leadboat.com
1 parent 1a4a032 commit 38fc056

File tree

1 file changed

+6
-14
lines changed
  • src/backend/storage/smgr

1 file changed

+6
-14
lines changed

src/backend/storage/smgr/md.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,18 +516,10 @@ mdclose(SMgrRelation reln, ForkNumber forknum)
516516
{
517517
MdfdVec *v = &reln->md_seg_fds[forknum][nopensegs - 1];
518518

519-
/* if not closed already */
520-
if (v->mdfd_vfd >= 0)
521-
{
522-
FileClose(v->mdfd_vfd);
523-
v->mdfd_vfd = -1;
524-
}
525-
519+
FileClose(v->mdfd_vfd);
520+
_fdvec_resize(reln, forknum, nopensegs - 1);
526521
nopensegs--;
527522
}
528-
529-
/* resize just once, avoids pointless reallocations */
530-
_fdvec_resize(reln, forknum, 0);
531523
}
532524

533525
/*
@@ -1050,10 +1042,10 @@ _fdvec_resize(SMgrRelation reln,
10501042
else
10511043
{
10521044
/*
1053-
* It doesn't seem worthwhile complicating the code by having a more
1054-
* aggressive growth strategy here; the number of segments doesn't
1055-
* grow that fast, and the memory context internally will sometimes
1056-
* avoid doing an actual reallocation.
1045+
* It doesn't seem worthwhile complicating the code to amortize
1046+
* repalloc() calls. Those are far faster than PathNameOpenFile() or
1047+
* FileClose(), and the memory context internally will sometimes avoid
1048+
* doing an actual reallocation.
10571049
*/
10581050
reln->md_seg_fds[forknum] =
10591051
repalloc(reln->md_seg_fds[forknum],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy