pgsql: Fix bogus cache-invalidation logic in logical replication worker

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix bogus cache-invalidation logic in logical replication worker
Дата
Msg-id E1kIZyJ-0005ev-3K@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix bogus cache-invalidation logic in logical replication worker.

The code recorded cache invalidation events by zeroing the "localreloid"
field of affected cache entries.  However, it's possible for an inval
event to occur even while we have the entry open and locked.  So an
ill-timed inval could result in "cache lookup failed for relation 0"
errors, if the worker's code tried to use the cleared field.  We can
fix that by creating a separate bool field to record whether the entry
needs to be revalidated.  (In the back branches, cram the bool into
what had been padding space, to avoid an ABI break in the somewhat
unlikely event that any extension is looking at this struct.)

Also, rearrange the logic in logicalrep_rel_open so that it
does the right thing in cases where table_open would fail.
We should retry the lookup by name in that case, but we didn't.

The real-world impact of this is probably small.  In the first place,
the error conditions are very low probability, and in the second place,
the worker would just exit and get restarted.  We only noticed because
in a CLOBBER_CACHE_ALWAYS build, the failure can occur repeatedly,
preventing the worker from making progress.  Nonetheless, it's clearly
a bug, and it impedes a useful type of testing; so back-patch to v10
where this code was introduced.

Discussion: https://postgr.es/m/1032727.1600096803@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3d65b0593c5578014f62e09d4008006f1783f64d

Modified Files
--------------
src/backend/replication/logical/relation.c | 71 ++++++++++++++++++------------
src/include/replication/logicalrelation.h  | 11 ++++-
2 files changed, 53 insertions(+), 29 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Fujii Masao
Дата:
Сообщение: pgsql: Add leader_pid field into the example of file_fdw for csvlog.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Avoid unnecessary recursion to child tables in ALTER TABLE SET N