Improve error detection capability in proclists.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 8 Jan 2018 23:07:04 +0000 (18:07 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 8 Jan 2018 23:07:04 +0000 (18:07 -0500)
commitea8e1bbc538444d373cf712a0f5188c906b71a9d
treea544902d0b3aa43be7900eb341b8c13673d13c27
parenteeb3c2df429c943b2f8d028d110b55ac0a53dc75
Improve error detection capability in proclists.

Previously, although the initial state of a proclist_node is expected
to be next == prev == 0, proclist_delete_offset would reset nodes to
next == prev == INVALID_PGPROCNO when removing them from a list.
This is the same state that a node in a singleton list has, so that
it's impossible to distinguish not-in-a-list from in-a-list.  Change
proclist_delete_offset to reset removed nodes to next == prev == 0,
making it possible to distinguish those cases, and then add Asserts
to the list add and delete functions that the supplied node isn't
or is in a list at entry.  Also tighten assertions about the node
being in the particular list (not some other one) where it is possible
to check that in O(1) time.

In ConditionVariablePrepareToSleep, since we don't expect the process's
cvWaitLink to already be in a list, remove the more-or-less-useless
proclist_contains check; we'd rather have proclist_push_tail's new
assertion fire if that happens.

Improve various comments related to proclists, too.

Patch by me, reviewed by Thomas Munro.  This isn't back-patchable, since
there could theoretically be inlined copies of proclist_delete_offset in
third-party modules.  But it's only improving debuggability anyway.

Discussion: https://postgr.es/m/CAEepm=0NWKehYw7NDoUSf8juuKOPRnCyY3vuaSvhrEWsOTAa3w@mail.gmail.com
src/backend/storage/lmgr/condition_variable.c
src/include/storage/proclist.h
src/include/storage/proclist_types.h