Reduce the scope of volatile qualifiers

Commit c66a7d75e6 introduced a new "cast discards ‘volatile’"
warning (-Wcast-qual) in vac_truncate_clog().

Instead of making use of unvolatize(), remove the warning by reducing the
scope of the volatile qualifier (added in commit 2d2e40e3be) to only
2 fields.

Also do the same for vac_update_datfrozenxid(), since the intent of
commit f65ab862e3 was to prevent the same kind of race condition that
commit 2d2e40e3be was fixing.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Suggested-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/aZ3a%2BV82uSfEjDmD%40ip-10-97-1-34.eu-west-3.compute.internal
This commit is contained in:
Peter Eisentraut 2026-03-03 10:01:44 +01:00
parent 2a525cc97e
commit f2d7570cdd

View file

@ -1665,9 +1665,11 @@ vac_update_datfrozenxid(void)
while ((classTup = systable_getnext(scan)) != NULL)
{
volatile FormData_pg_class *classForm = (Form_pg_class) GETSTRUCT(classTup);
TransactionId relfrozenxid = classForm->relfrozenxid;
TransactionId relminmxid = classForm->relminmxid;
Form_pg_class classForm = (Form_pg_class) GETSTRUCT(classTup);
volatile TransactionId *relfrozenxid_p = &classForm->relfrozenxid;
volatile TransactionId *relminmxid_p = &classForm->relminmxid;
TransactionId relfrozenxid = *relfrozenxid_p;
TransactionId relminmxid = *relminmxid_p;
/*
* Only consider relations able to hold unfrozen XIDs (anything else
@ -1869,9 +1871,11 @@ vac_truncate_clog(TransactionId frozenXID,
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{
volatile FormData_pg_database *dbform = (Form_pg_database) GETSTRUCT(tuple);
TransactionId datfrozenxid = dbform->datfrozenxid;
TransactionId datminmxid = dbform->datminmxid;
Form_pg_database dbform = (Form_pg_database) GETSTRUCT(tuple);
volatile TransactionId *datfrozenxid_p = &dbform->datfrozenxid;
volatile TransactionId *datminmxid_p = &dbform->datminmxid;
TransactionId datfrozenxid = *datfrozenxid_p;
TransactionId datminmxid = *datminmxid_p;
Assert(TransactionIdIsNormal(datfrozenxid));
Assert(MultiXactIdIsValid(datminmxid));