From: Peter Eisentraut Date: Tue, 3 Mar 2026 09:01:44 +0000 (+0100) Subject: Reduce the scope of volatile qualifiers X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f2d7570cdde75fd67acb279063b2701806662035;p=thirdparty%2Fpostgresql.git Reduce the scope of volatile qualifiers Commit c66a7d75e652 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 2d2e40e3bef) to only 2 fields. Also do the same for vac_update_datfrozenxid(), since the intent of commit f65ab862e3b was to prevent the same kind of race condition that commit 2d2e40e3bef was fixing. Author: Bertrand Drouvot Suggested-by: Peter Eisentraut Reviewed-by: Nathan Bossart Discussion: https://www.postgresql.org/message-id/flat/aZ3a%2BV82uSfEjDmD%40ip-10-97-1-34.eu-west-3.compute.internal --- diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 03932f45c8a..b9840637783 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -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));