Is element access after HASH_REMOVE ever OK? - Mailing list pgsql-hackers

From Thomas Munro
Subject Is element access after HASH_REMOVE ever OK?
Date
Msg-id CA+hUKGJ-ysnJFQJ5A67Gpj4g2Hu7W965qePF6+ReWMvn5j+Z6w@mail.gmail.com
Whole thread Raw
Responses Re: Is element access after HASH_REMOVE ever OK?
List pgsql-hackers
Hi,

After hearing from a couple of directions about systems spending too
much time scanning the local lock hash table, I wrote the trivial
patch to put them in a linked list, before learning that people have
considered that before, so I should probably go and read some history
on that and find out why it hasn't been done...

However, I noticed in passing that RemoveLocalLock() accesses
*locallock after removing it from the hash table (in assertion builds
only).  So one question I have is whether it's actually a programming
rule that you can't do that (at most you can compare the pointer
against NULL), or whether it's supposed to be
safe-if-you-know-what-you're-doing, as the existing comments hints.
Here also is a patch that does wipe_mem on removed elements, as
threatened last time this topic came up[1], which reveals the problem.
I'm also not exactly sure why it's only a WARNING if your local lock
table is out of sync, but perhaps that's in the archives too.

[1]
https://www.postgresql.org/message-id/flat/CAHut%2BPs-pL%2B%2Bf6CJwPx2%2BvUqXuew%3DXt-9Bi-6kCyxn%2BFwi2M7w%40mail.gmail.com

Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Reducing opr_sanity test's runtime under CLOBBER_CACHE_ALWAYS
Next
From: Tom Lane
Date:
Subject: Re: Is element access after HASH_REMOVE ever OK?