forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1691512
committed
pg_rewind: Fetch small files according to new size.
There's a race condition if a file changes in the source systemafter we have collected the file list. If the file becomes larger,we only fetched up to its original size. That can easily result ina truncated file. That's not a problem for relation files, filesin pg_xact, etc. because any actions on them will be replayed fromthe WAL. However, configuration files are affected.This commit mitigates the race condition by fetching small files inwhole, even if they have grown. A test is added in which an extrafile copied is concurrently grown with the output of pg_rewind thusguaranteeing it to have changed in size during the operation. Thisis not a full fix: we still believe the original file size for fileslarger than 1 MB. That should be enough for configuration files,and doing more than that would require big changes to the chunkinglogic in libpq_source.c.This mitigates the race condition if the file is modified betweenthe original scan of files and copying the file, but there's stilla race condition if a file is changed while it's being copied.That's a much smaller window, though, and pg_basebackup has thesame issue.This race can be seen with pg_auto_failover, which frequently usesALTER SYSTEM, which updates postgresql.auto.conf. Often, pg_rewindwill fail, because the postgresql.auto.conf file changed concurrentlyand a partial version of it was copied to the target. The partialfile would fail to parse, preventing the server from starting up.Author: Heikki LinnakangasReviewed-by: Cary HuangDiscussion:https://postgr.es/m/f67feb24-5833-88cb-1020-19a4a2b83ac7%40iki.fi1 parent98fe742 commit1691512
File tree
5 files changed
+188
-14
lines changed- src/bin/pg_rewind
- t
5 files changed
+188
-14
lines changedLines changed: 32 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
63 | 63 |
| |
64 | 64 |
| |
65 | 65 |
| |
| 66 | + | |
66 | 67 |
| |
67 | 68 |
| |
68 | 69 |
| |
| |||
88 | 89 |
| |
89 | 90 |
| |
90 | 91 |
| |
| 92 | + | |
91 | 93 |
| |
92 | 94 |
| |
93 | 95 |
| |
| |||
307 | 309 |
| |
308 | 310 |
| |
309 | 311 |
| |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
310 | 342 |
| |
311 | 343 |
| |
312 | 344 |
| |
|
Lines changed: 66 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
29 | 29 |
| |
30 | 30 |
| |
31 | 31 |
| |
32 |
| - | |
33 |
| - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
34 | 36 |
| |
35 | 37 |
| |
36 | 38 |
| |
| |||
43 | 45 |
| |
44 | 46 |
| |
45 | 47 |
| |
46 |
| - | |
| 48 | + | |
| 49 | + | |
47 | 50 |
| |
48 | 51 |
| |
49 | 52 |
| |
| |||
65 | 68 |
| |
66 | 69 |
| |
67 | 70 |
| |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
68 | 124 |
| |
69 | 125 |
| |
70 | 126 |
| |
71 | 127 |
| |
72 |
| - | |
73 |
| - | |
| 128 | + | |
| 129 | + | |
74 | 130 |
| |
75 | 131 |
| |
76 | 132 |
| |
| |||
94 | 150 |
| |
95 | 151 |
| |
96 | 152 |
| |
97 |
| - | |
| 153 | + | |
98 | 154 |
| |
99 | 155 |
| |
100 |
| - | |
| 156 | + | |
101 | 157 |
| |
102 |
| - | |
| 158 | + | |
103 | 159 |
| |
104 |
| - | |
| 160 | + | |
105 | 161 |
| |
106 | 162 |
| |
107 | 163 |
| |
| |||
120 | 176 |
| |
121 | 177 |
| |
122 | 178 |
| |
123 |
| - | |
| 179 | + | |
124 | 180 |
| |
125 | 181 |
| |
126 | 182 |
| |
|
Lines changed: 1 addition & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
537 | 537 |
| |
538 | 538 |
| |
539 | 539 |
| |
540 |
| - | |
541 |
| - | |
542 |
| - | |
543 |
| - | |
| 540 | + | |
544 | 541 |
| |
545 | 542 |
| |
546 | 543 |
| |
|
Lines changed: 13 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
47 | 47 |
| |
48 | 48 |
| |
49 | 49 |
| |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
50 | 63 |
| |
51 | 64 |
| |
52 | 65 |
| |
|
Lines changed: 76 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + |
0 commit comments
Comments
(0)