Re: ResourceOwner refactoring
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Julien Rouhaud <rjuju123@gmail.com>, Aleksander Alekseev <aleksander@timescale.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2022-11-01T00:15:23Z
Lists: pgsql-hackers
Hi, On 2022-10-31 10:51:36 +0100, Heikki Linnakangas wrote: > These are functions where quite a lot of things happen between the > ResourceOwnerEnlarge and ResourceOwnerRemember calls. It's important that > there are no unrelated ResourceOwnerRemember() calls in the code in > between, otherwise the entry reserved by the ResourceOwnerEnlarge() call > might be used up by the intervening ResourceOwnerRemember() and not be > available at the intended ResourceOwnerRemember() call anymore. The longer > the code path between them is, the harder it is to verify that. This seems to work towards a future where only one kind of resource can be reserved ahead of time. That doesn't strike me as great. > Instead of having a separate array/hash for each resource kind, use a > single array and hash to hold all kinds of resources. This makes it > possible to introduce new resource "kinds" without having to modify the > ResourceOwnerData struct. In particular, this makes it possible for > extensions to register custom resource kinds. As a goal I like this. However, I'm not quite sold on the implementation. Two main worries: 1) As far as I can tell, the way ResourceOwnerReleaseAll() now works seems to assume that within a phase the reset order does not matter. I don't think that's a good assumption. I e.g. have a patch to replace InProgressBuf with resowner handling, and in-progress IO errors should be processed before before pins are released. 2) There's quite a few resource types where we actually don't need an entry in an array, because we can instead add a dlist_node to the resource - avoiding memory overhead and making removal cheap. I have a few pending patches that use that approach, and this doesn't really provide a path for that anymore. I did try out the benchmark from https://postgr.es/m/20221029200025.w7bvlgvamjfo6z44%40awork3.anarazel.de and the patches performed well, slightly better than my approach of allocating some initial memory for each resarray. Greetings, Andres Freund
Commits
-
Make RelationFlushRelation() work without ResourceOwner during abort
- e6cd85772647 17.0 landed
-
Fix bug in bulk extending temp relation after failure
- d212957254de 17.0 landed
-
Add missing PGDLLIMPORT markings
- c6b86eaa55ff 17.0 landed
-
Add test_dsa module.
- 325f54033e59 17.0 landed
-
Clear CurrentResourceOwner earlier in CommitTransaction.
- c21e6e2fd48c 17.0 landed
-
Fix dsa.c with different resource owners.
- a8b330ffb6f7 17.0 landed
-
Fix bug in the new ResourceOwner implementation.
- 8f4a1ab471e6 17.0 landed
-
Change pgcrypto to use the new ResourceOwner mechanism.
- cd694f60dc97 17.0 landed
-
Use a faster hash function in resource owners.
- 954e43564d99 17.0 landed
-
Make ResourceOwners more easily extensible.
- b8bff07daa85 17.0 landed
-
Move a few ResourceOwnerEnlarge() calls for safety and clarity.
- b70c2143bbbe 17.0 landed