Re: hyrax vs. RelationBuildPartitionDesc
Amit Langote <amitlangote09@gmail.com>
From: Amit Langote <amitlangote09@gmail.com>
To: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Michael Paquier <michael@paquier.xyz>, Robert Haas <robertmhaas@gmail.com>,
Alvaro Herrera <alvherre@2ndquadrant.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2019-04-15T14:57:48Z
Lists: pgsql-hackers
On Mon, Apr 15, 2019 at 5:05 PM Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> wrote: > On 2019/04/15 2:38, Tom Lane wrote: > > So the point here is that that reasoning is faulty. You *cannot* assume, > > no matter how strong a lock or how many pins you hold, that a relcache > > entry will not get rebuilt underneath you. Cache flushes happen > > regardless. And unless relcache.c takes special measures to prevent it, > > a rebuild will result in moving subsidiary data structures and thereby > > breaking any pointers you may have pointing into those data structures. > > > > For certain subsidiary structures such as the relation tupdesc, > > we do take such special measures: that's what the "keep_xxx" dance in > > RelationClearRelation is. However, that's expensive, both in cycles > > and maintenance effort: it requires having code that can decide equality > > of the subsidiary data structures, which we might well have no other use > > for, and which we certainly don't have strong tests for correctness of. > > It's also very error-prone for callers, because there isn't any good way > > to cross-check that code using a long-lived pointer to a subsidiary > > structure is holding a lock that's strong enough to guarantee non-mutation > > of that structure, or even that relcache.c provides any such guarantee > > at all. (If our periodic attempts to reduce lock strength for assorted > > DDL operations don't scare the pants off you in this connection, you have > > not thought hard enough about it.) So I think that even though we've > > largely gotten away with this approach so far, it's also a half-baked > > kluge that we should be looking to get rid of, not extend to yet more > > cases. > > Thanks for the explanation. > > I understand that simply having a lock and a nonzero refcount on a > relation doesn't prevent someone else from changing it concurrently. > > I get that we want to get rid of the keep_* kludge in the long term, but > is it wrong to think, for example, that having keep_partdesc today allows > us today to keep the pointer to rd_partdesc as long as we're holding the > relation open or refcnt on the whole relation such as with > PartitionDirectory mechanism? Ah, we're also trying to fix the memory leak caused by the current design of PartitionDirectory. AIUI, the design assumes that the leak would occur in fairly rare cases, but maybe not so? If partitions are frequently attached/detached concurrently (maybe won't be too uncommon if reduced lock levels encourages users) causing the PartitionDesc of a given relation changing all the time, then a planning session that's holding the PartitionDirectory containing that relation would leak as many PartitionDescs as there were concurrent changes, I guess. I see that you've proposed to change the PartitionDirectory design to copy PartitionDesc as way of keeping it around instead holding the relation open, but having to resort to that would be unfortunate. Thanks, Amit
Commits
-
Load relcache entries' partitioning data on-demand, not immediately.
- 5b9312378e2f 13.0 landed
-
Prevent memory leaks associated with relcache rd_partcheck structures.
- d4c50b4b1f86 10.8 landed
- 5f1433ac5e7f 12.0 landed
- 089e4d405d0f 11.3 landed
-
Don't copy PartitionBoundInfo in set_relation_partition_info.
- c8151e642368 12.0 landed
-
Further reduce memory footprint of CLOBBER_CACHE_ALWAYS testing.
- d3f48dfae42f 12.0 landed
-
Fix some oversights in commit 2455ab488.
- de570047993b 12.0 landed
-
Defend against leaks into RelationBuildPartitionDesc.
- 2455ab48844c 12.0 landed
-
Allow ATTACH PARTITION with only ShareUpdateExclusiveLock.
- 898e5e3290a7 12.0 cited