forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitb8bff07
committed
Make ResourceOwners more easily extensible.
Instead of having a separate array/hash for each resource kind, use asingle array and hash to hold all kinds of resources. This makes itpossible to introduce new resource "kinds" without having to modifythe ResourceOwnerData struct. In particular, this makes it possiblefor extensions to register custom resource kinds.The old approach was to have a small array of resources of each kind,and if it fills up, switch to a hash table. The new approach also usesan array and a hash, but now the array and the hash are used at thesame time. The array is used to hold the recently added resources, andwhen it fills up, they are moved to the hash. This keeps the access torecent entries fast, even when there are a lot of long-held resources.All the resource-specific ResourceOwnerEnlarge*(),ResourceOwnerRemember*(), and ResourceOwnerForget*() functions havebeen replaced with three generic functions that take resource kind asargument. For convenience, we still define resource-specific wrappermacros around the generic functions with the old names, but they arenow defined in the source files that use those resource kinds.The release callback no longer needs to call ResourceOwnerForget onthe resource being released. ResourceOwnerRelease unregisters theresource from the owner before calling the callback. That needed somechanges in bufmgr.c and some other files, where releasing theresources previously always called ResourceOwnerForget.Each resource kind specifies a release priority, andResourceOwnerReleaseAll releases the resources in priority order. Tomake that possible, we have to restrict what you can do betweenphases. After calling ResourceOwnerRelease(), you are no longerallowed to remember any more resources in it or to forget anypreviously remembered resources by calling ResourceOwnerForget. Therewas one case where that was done previously. At subtransaction commit,AtEOSubXact_Inval() would handle the invalidation messages and callRelationFlushRelation(), which temporarily increased the referencecount on the relation being flushed. We now switch to the parentsubtransaction's resource owner before calling AtEOSubXact_Inval(), sothat there is a valid ResourceOwner to temporarily hold that relcachereference.Other end-of-xact routines make similar calls to AtEOXact_Inval()between release phases, but I didn't see any regression test failuresfrom those, so I'm not sure if they could reach a codepath that needsremembering extra resources.There were two exceptions to how the resource leak WARNINGs on commitwere printed previously: llvmjit silently released the context withoutprinting the warning, and a leaked buffer io triggered a PANIC. Noweverything prints a WARNING, including those cases.Add tests in src/test/modules/test_resowner.Reviewed-by: Aleksander Alekseev, Michael Paquier, Julien RouhaudReviewed-by: Kyotaro Horiguchi, Hayato Kuroda, Álvaro Herrera, Zhihong YuReviewed-by: Peter Eisentraut, Andres FreundDiscussion:https://www.postgresql.org/message-id/cbfabeb0-cd3c-e951-a572-19b365ed314d%40iki.fi1 parentb70c214 commitb8bff07
File tree
36 files changed
+2278
-1144
lines changed- src
- backend
- access
- common
- transam
- jit
- llvm
- storage
- buffer
- file
- ipc
- lmgr
- utils
- cache
- resowner
- time
- common
- include
- storage
- utils
- pl/plpgsql/src
- test/modules
- test_resowner
- expected
- sql
- tools/pgindent
36 files changed
+2278
-1144
lines changedLines changed: 49 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
27 | 27 |
| |
28 | 28 |
| |
29 | 29 |
| |
30 |
| - | |
| 30 | + | |
31 | 31 |
| |
32 | 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 | + | |
33 | 58 |
| |
34 | 59 |
| |
35 | 60 |
| |
| |||
364 | 389 |
| |
365 | 390 |
| |
366 | 391 |
| |
367 |
| - | |
| 392 | + | |
368 | 393 |
| |
369 | 394 |
| |
370 | 395 |
| |
| |||
847 | 872 |
| |
848 | 873 |
| |
849 | 874 |
| |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + |
Lines changed: 14 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5172 | 5172 |
| |
5173 | 5173 |
| |
5174 | 5174 |
| |
| 5175 | + | |
5175 | 5176 |
| |
5176 | 5177 |
| |
| 5178 | + | |
| 5179 | + | |
| 5180 | + | |
| 5181 | + | |
| 5182 | + | |
| 5183 | + | |
| 5184 | + | |
| 5185 | + | |
| 5186 | + | |
| 5187 | + | |
5177 | 5188 |
| |
| 5189 | + | |
| 5190 | + | |
| 5191 | + | |
5178 | 5192 |
| |
5179 | 5193 |
| |
5180 | 5194 |
| |
|
Lines changed: 0 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
26 | 26 |
| |
27 | 27 |
| |
28 | 28 |
| |
29 |
| - | |
30 | 29 |
| |
31 | 30 |
| |
32 | 31 |
| |
| |||
140 | 139 |
| |
141 | 140 |
| |
142 | 141 |
| |
143 |
| - | |
144 | 142 |
| |
145 | 143 |
| |
146 | 144 |
| |
|
Lines changed: 42 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
45 | 45 |
| |
46 | 46 |
| |
47 | 47 |
| |
48 |
| - | |
| 48 | + | |
49 | 49 |
| |
50 | 50 |
| |
51 | 51 |
| |
| |||
131 | 131 |
| |
132 | 132 |
| |
133 | 133 |
| |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
134 | 158 |
| |
135 | 159 |
| |
136 | 160 |
| |
| |||
220 | 244 |
| |
221 | 245 |
| |
222 | 246 |
| |
223 |
| - | |
| 247 | + | |
224 | 248 |
| |
225 | 249 |
| |
226 | 250 |
| |
227 | 251 |
| |
228 | 252 |
| |
229 | 253 |
| |
230 | 254 |
| |
231 |
| - | |
| 255 | + | |
232 | 256 |
| |
233 | 257 |
| |
234 | 258 |
| |
| |||
300 | 324 |
| |
301 | 325 |
| |
302 | 326 |
| |
| 327 | + | |
| 328 | + | |
| 329 | + | |
303 | 330 |
| |
304 | 331 |
| |
305 | 332 |
| |
| |||
1394 | 1421 |
| |
1395 | 1422 |
| |
1396 | 1423 |
| |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + |
0 commit comments
Comments
(0)