forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit2069e6f
committed
Clean up assorted messiness around AllocateDir() usage.
This patch fixes a couple of low-probability bugs that could lead toreporting an irrelevant errno value (and hence possibly a wrong SQLSTATE)concerning directory-open or file-open failures. It also fixes placeswhere we took shortcuts in reporting such errors, either by using eloginstead of ereport or by using ereport but forgetting to specify anerrcode. And it eliminates a lot of just plain redundant error-handlingcode.In service of all this, export fd.c's formerly-static functionReadDirExtended, so that external callers can make use of the codingpatterndir = AllocateDir(path);while ((de = ReadDirExtended(dir, path, LOG)) != NULL)if they'd like to treat directory-open failures as mere LOG conditionsrather than errors. Also fix FreeDir to be a no-op if we reach itwith dir == NULL, as such a coding pattern would cause.Then, remove code at many call sites that was throwing an error or logmessage for AllocateDir failure, as ReadDir or ReadDirExtended can handlethat job just fine. Aside from being a net code savings, this gets rid ofa lot of not-quite-up-to-snuff reports, as mentioned above. (In someplaces these changes result in replacing a custom error message such as"could not open tablespace directory" with more generic wording "could notopen directory", but it was agreed that the custom wording buys little aslong as we report the directory name.) In some other call sites where wecan't just remove code, change the error reports to be fullyproject-style-compliant.Also reorder code in restoreTwoPhaseData that was acquiring a lockbetween AllocateDir and ReadDir; in the unlikely but surely notimpossible case that LWLockAcquire changes errno, AllocateDir failureswould be misreported. There is no great value in opening the directorybefore acquiring TwoPhaseStateLock, so just do it in the other order.Also fix CheckXLogRemoved to guarantee that it preserves errno,as quite a number of call sites are implicitly assuming. (Again,it's unlikely but I think not impossible that errno could changeduring a SpinLockAcquire. If so, this function was broken for itsown purposes as well as breaking callers.)And change a few places that were using not-per-project-style messages,such as "could not read directory" when "could not open directory" ismore correct.Back-patch the exporting of ReadDirExtended, in case we have occasionto back-patch some fix that makes use of it; it's not needed right nowbut surely making it global is pretty harmless. Also back-patch therestoreTwoPhaseData and CheckXLogRemoved fixes. The rest of this isessentially cosmetic and need not get back-patched.Michael Paquier, with a bit of additional work by meDiscussion:https://postgr.es/m/CAB7nPqRpOCxjiirHmebEFhXVTK7V5Jvw4bz82p7Oimtsm3TyZA@mail.gmail.com1 parentab6eaee commit2069e6f
File tree
17 files changed
+102
-153
lines changed- contrib/adminpack
- src
- backend
- access/transam
- postmaster
- replication
- storage
- file
- ipc
- utils
- adt
- cache
- time
- include/storage
- timezone
17 files changed
+102
-153
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
319 | 319 |
| |
320 | 320 |
| |
321 | 321 |
| |
322 |
| - | |
| 322 | + | |
323 | 323 |
| |
324 | 324 |
| |
325 | 325 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1735 | 1735 |
| |
1736 | 1736 |
| |
1737 | 1737 |
| |
1738 |
| - | |
1739 | 1738 |
| |
| 1739 | + | |
1740 | 1740 |
| |
1741 | 1741 |
| |
1742 | 1742 |
| |
|
Lines changed: 12 additions & 19 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3764 | 3764 |
| |
3765 | 3765 |
| |
3766 | 3766 |
| |
| 3767 | + | |
| 3768 | + | |
| 3769 | + | |
| 3770 | + | |
| 3771 | + | |
3767 | 3772 |
| |
3768 | 3773 |
| |
3769 | 3774 |
| |
3770 | 3775 |
| |
| 3776 | + | |
3771 | 3777 |
| |
3772 | 3778 |
| |
3773 | 3779 |
| |
| |||
3779 | 3785 |
| |
3780 | 3786 |
| |
3781 | 3787 |
| |
| 3788 | + | |
3782 | 3789 |
| |
3783 | 3790 |
| |
3784 | 3791 |
| |
3785 | 3792 |
| |
3786 | 3793 |
| |
| 3794 | + | |
3787 | 3795 |
| |
3788 | 3796 |
| |
3789 | 3797 |
| |
| |||
3837 | 3845 |
| |
3838 | 3846 |
| |
3839 | 3847 |
| |
3840 |
| - | |
3841 |
| - | |
3842 |
| - | |
3843 |
| - | |
3844 |
| - | |
3845 |
| - | |
3846 |
| - | |
3847 | 3848 |
| |
3848 | 3849 |
| |
3849 | 3850 |
| |
| |||
3854 | 3855 |
| |
3855 | 3856 |
| |
3856 | 3857 |
| |
| 3858 | + | |
| 3859 | + | |
3857 | 3860 |
| |
3858 | 3861 |
| |
3859 | 3862 |
| |
| |||
3912 | 3915 |
| |
3913 | 3916 |
| |
3914 | 3917 |
| |
3915 |
| - | |
3916 |
| - | |
3917 |
| - | |
3918 |
| - | |
3919 |
| - | |
3920 |
| - | |
3921 |
| - | |
3922 | 3918 |
| |
3923 | 3919 |
| |
3924 | 3920 |
| |
| |||
3927 | 3923 |
| |
3928 | 3924 |
| |
3929 | 3925 |
| |
| 3926 | + | |
| 3927 | + | |
3930 | 3928 |
| |
3931 | 3929 |
| |
3932 | 3930 |
| |
| |||
4108 | 4106 |
| |
4109 | 4107 |
| |
4110 | 4108 |
| |
4111 |
| - | |
4112 |
| - | |
4113 |
| - | |
4114 |
| - | |
4115 |
| - | |
4116 | 4109 |
| |
4117 | 4110 |
| |
4118 | 4111 |
| |
|
Lines changed: 3 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
89 | 89 |
| |
90 | 90 |
| |
91 | 91 |
| |
92 |
| - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
93 | 95 |
| |
94 | 96 |
| |
95 | 97 |
| |
|
Lines changed: 0 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
673 | 673 |
| |
674 | 674 |
| |
675 | 675 |
| |
676 |
| - | |
677 |
| - | |
678 |
| - | |
679 |
| - | |
680 |
| - | |
681 | 676 |
| |
682 | 677 |
| |
683 | 678 |
| |
|
Lines changed: 3 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
367 | 367 |
| |
368 | 368 |
| |
369 | 369 |
| |
370 |
| - | |
371 |
| - | |
372 |
| - | |
373 | 370 |
| |
374 | 371 |
| |
375 | 372 |
| |
| |||
713 | 710 |
| |
714 | 711 |
| |
715 | 712 |
| |
716 |
| - | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
717 | 716 |
| |
718 | 717 |
| |
719 | 718 |
| |
|
Lines changed: 0 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
47 | 47 |
| |
48 | 48 |
| |
49 | 49 |
| |
50 |
| - | |
51 |
| - | |
52 |
| - | |
53 |
| - | |
54 | 50 |
| |
55 | 51 |
| |
56 | 52 |
| |
| |||
90 | 86 |
| |
91 | 87 |
| |
92 | 88 |
| |
93 |
| - | |
94 |
| - | |
95 |
| - | |
96 |
| - | |
97 | 89 |
| |
98 | 90 |
| |
99 | 91 |
| |
|
Lines changed: 37 additions & 32 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
318 | 318 |
| |
319 | 319 |
| |
320 | 320 |
| |
321 |
| - | |
322 | 321 |
| |
323 | 322 |
| |
324 | 323 |
| |
| |||
2587 | 2586 |
| |
2588 | 2587 |
| |
2589 | 2588 |
| |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
2590 | 2593 |
| |
2591 | 2594 |
| |
2592 | 2595 |
| |
| |||
2649 | 2652 |
| |
2650 | 2653 |
| |
2651 | 2654 |
| |
2652 |
| - | |
2653 |
| - | |
| 2655 | + | |
| 2656 | + | |
2654 | 2657 |
| |
2655 | 2658 |
| |
2656 | 2659 |
| |
| |||
2662 | 2665 |
| |
2663 | 2666 |
| |
2664 | 2667 |
| |
2665 |
| - | |
2666 |
| - | |
| 2668 | + | |
| 2669 | + | |
| 2670 | + | |
| 2671 | + | |
| 2672 | + | |
| 2673 | + | |
| 2674 | + | |
2667 | 2675 |
| |
2668 |
| - | |
| 2676 | + | |
2669 | 2677 |
| |
2670 | 2678 |
| |
2671 | 2679 |
| |
| |||
2695 | 2703 |
| |
2696 | 2704 |
| |
2697 | 2705 |
| |
2698 |
| - | |
2699 |
| - | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
2700 | 2712 |
| |
2701 | 2713 |
| |
2702 | 2714 |
| |
2703 | 2715 |
| |
2704 | 2716 |
| |
2705 | 2717 |
| |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
2706 | 2722 |
| |
2707 | 2723 |
| |
2708 | 2724 |
| |
| |||
3043 | 3059 |
| |
3044 | 3060 |
| |
3045 | 3061 |
| |
3046 |
| - | |
3047 |
| - | |
3048 |
| - | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
3049 | 3066 |
| |
3050 | 3067 |
| |
3051 | 3068 |
| |
| |||
3099 | 3116 |
| |
3100 | 3117 |
| |
3101 | 3118 |
| |
3102 |
| - | |
3103 |
| - | |
3104 |
| - | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
3105 | 3123 |
| |
3106 | 3124 |
| |
3107 | 3125 |
| |
| |||
3136 | 3154 |
| |
3137 | 3155 |
| |
3138 | 3156 |
| |
3139 |
| - | |
3140 |
| - | |
3141 |
| - | |
3142 |
| - | |
3143 |
| - | |
3144 |
| - | |
3145 |
| - | |
3146 |
| - | |
3147 | 3157 |
| |
3148 |
| - | |
| 3158 | + | |
3149 | 3159 |
| |
3150 | 3160 |
| |
3151 | 3161 |
| |
| |||
3310 | 3320 |
| |
3311 | 3321 |
| |
3312 | 3322 |
| |
3313 |
| - | |
3314 |
| - | |
3315 |
| - | |
3316 |
| - | |
3317 |
| - | |
3318 |
| - | |
3319 |
| - | |
3320 | 3323 |
| |
3321 | 3324 |
| |
3322 | 3325 |
| |
| |||
3356 | 3359 |
| |
3357 | 3360 |
| |
3358 | 3361 |
| |
3359 |
| - | |
| 3362 | + | |
| 3363 | + | |
3360 | 3364 |
| |
3361 |
| - | |
| 3365 | + | |
| 3366 | + | |
3362 | 3367 |
| |
3363 | 3368 |
| |
3364 | 3369 |
| |
|
Lines changed: 20 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
111 | 111 |
| |
112 | 112 |
| |
113 | 113 |
| |
114 |
| - | |
115 |
| - | |
116 |
| - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
117 | 118 |
| |
118 | 119 |
| |
119 | 120 |
| |
| |||
164 | 165 |
| |
165 | 166 |
| |
166 | 167 |
| |
167 |
| - | |
168 |
| - | |
169 |
| - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
170 | 172 |
| |
171 | 173 |
| |
172 | 174 |
| |
| |||
226 | 228 |
| |
227 | 229 |
| |
228 | 230 |
| |
229 |
| - | |
230 |
| - | |
231 |
| - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
232 | 235 |
| |
233 | 236 |
| |
234 | 237 |
| |
| |||
296 | 299 |
| |
297 | 300 |
| |
298 | 301 |
| |
299 |
| - | |
300 |
| - | |
301 |
| - | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
302 | 306 |
| |
303 | 307 |
| |
304 | 308 |
| |
| |||
349 | 353 |
| |
350 | 354 |
| |
351 | 355 |
| |
352 |
| - | |
353 |
| - | |
354 |
| - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
355 | 360 |
| |
356 | 361 |
| |
357 | 362 |
| |
|
0 commit comments
Comments
(0)