forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitccc4c07
committed
Close some holes in BRIN page assignment
In some corner cases, it is possible for the BRIN index relation to beextended by brin_getinsertbuffer but the new page not be usedimmediately for anything by its callers; when this happens, the page isinitialized and the FSM is updated (by brin_getinsertbuffer) with theinfo about that page, but these actions are not WAL-logged. A laterindex insert/update can use the page, but since the page is alreadyinitialized, the initialization itself is not WAL-logged then either.Replay of this sequence of events causes recovery to fail altogether.There is a related corner case within brin_getinsertbuffer itself, inwhich we extend the relation to put a new index tuple there, but laterfind out that we cannot do so, and do not return the buffer; the pageobtained from extension is not even initialized. The resulting page islost forever.To fix, shuffle the code so that initialization is not theresponsibility of brin_getinsertbuffer anymore, in normal cases;instead, the initialization is done by its callers (brin_doinsert andbrin_doupdate) once they're certain that the page is going to be used.When either those functions determine that the new page cannot be used,before bailing out they initialize the page as an empty regular page,enter it in FSM and WAL-log all this. This way, the page is usable forfuture index insertions, and WAL replay doesn't find trying to inserttuples in pages whose initialization didn't make it to the WAL. Thesame strategy is used in brin_getinsertbuffer when it cannot return thenew page.Additionally, add a new step to vacuuming so that all pages of the indexare scanned; whenever an uninitialized page is found, it is initializedas empty and WAL-logged. This closes the hole that the relation isextended but the system crashes before anything is WAL-logged about it.We also take this opportunity to update the FSM, in case it has gottenout of date.Thanks to Heikki Linnakangas for finding the problem that kicked someadditional analysis of BRIN page assignment code.Backpatch to 9.5, where BRIN was introduced.Discussion:https://www.postgresql.org/message-id/20150723204810.GY5596@postgresql.org1 parenta4b059f commitccc4c07
File tree
4 files changed
+258
-22
lines changed- src
- backend/access/brin
- include/access
4 files changed
+258
-22
lines changedLines changed: 43 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
68 | 68 |
| |
69 | 69 |
| |
70 | 70 |
| |
| 71 | + | |
71 | 72 |
| |
72 | 73 |
| |
73 | 74 |
| |
| |||
736 | 737 |
| |
737 | 738 |
| |
738 | 739 |
| |
| 740 | + | |
| 741 | + | |
739 | 742 |
| |
740 | 743 |
| |
741 | 744 |
| |
| |||
1150 | 1153 |
| |
1151 | 1154 |
| |
1152 | 1155 |
| |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + |
0 commit comments
Comments
(0)