postgresql/src
Fujii Masao 614b7f18b3 Fix "invalid spinlock number: 0" error in pg_stat_wal_receiver.
Commit 2c8dd05d6c added the atomic variable writtenUpto into
walreceiver's shared memory information. It's initialized only
when walreceiver started up but could be read via pg_stat_wal_receiver
view anytime, i.e., even before it's initialized. In the server built
with --disable-atomics and --disable-spinlocks, this uninitialized
atomic variable read could cause "invalid spinlock number: 0" error.

This commit changed writtenUpto so that it's initialized at
the postmaster startup, to avoid the uninitialized variable read
via pg_stat_wal_receiver and fix the error.

Also this commit moved the read of writtenUpto after the release
of spinlock protecting walreceiver's shared variables. This is
necessary to prevent new spinlock from being taken by atomic
variable read while holding another spinlock, and to shorten
the spinlock duration. This change leads writtenUpto not to be
consistent with the other walreceiver's shared variables protected
by a spinlock. But this is OK because writtenUpto should not be
used for data integrity checks.

Back-patch to v13 where commit 2c8dd05d6c introduced the bug.

Author: Fujii Masao
Reviewed-by: Michael Paquier, Thomas Munro, Andres Freund
Discussion: https://postgr.es/m/7ef8708c-5b6b-edd3-2cf2-7783f1c7c175@oss.nttdata.com
2021-02-18 23:28:15 +09:00
..
backend Fix "invalid spinlock number: 0" error in pg_stat_wal_receiver. 2021-02-18 23:28:15 +09:00
bin Add psql completion for [ NO ] DEPENDS ON EXTENSION 2021-02-17 11:50:58 +09:00
common Add result size as argument of pg_cryptohash_final() for overflow checks 2021-02-15 10:18:34 +09:00
fe_utils Generalize parallel slot result handling. 2021-02-05 16:08:45 -05:00
include Allow specifying CRL directory 2021-02-18 07:59:10 +01:00
interfaces Allow specifying CRL directory 2021-02-18 07:59:10 +01:00
makefiles Remove libpq.rc, use win32ver.rc for libpq 2020-01-15 15:06:12 +01:00
pl Remove extra increment of plpgsql's statement counter for FOR loops. 2021-02-02 14:35:12 -05:00
port pg_attribute_no_sanitize_alignment() macro 2021-02-12 17:23:35 +03:00
template Further tweaking of PG_SYSROOT heuristics for macOS. 2021-01-20 12:07:23 -05:00
test Fix "invalid spinlock number: 0" error in pg_stat_wal_receiver. 2021-02-18 23:28:15 +09:00
timezone Update time zone data files to tzdata release 2021a. 2021-01-24 16:29:47 -05:00
tools Allow multiple xacts during table sync in logical replication. 2021-02-12 07:41:51 +05:30
tutorial Doc, more or less: uncomment tutorial example that was fixed long ago. 2021-01-13 16:00:03 -05:00
.gitignore
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in Introduce --with-ssl={openssl} as a configure option 2021-02-01 19:19:44 +09:00
Makefile.shlib Add PostgreSQL home page to --help output 2020-02-28 13:12:21 +01:00
nls-global.mk NLS: Fix backend gettext triggers 2019-09-23 09:04:20 +02:00