Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVmdN-007m1A-2V for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Dec 2025 08:11:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vVmdL-00B9DM-0J for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Dec 2025 08:11:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVmdJ-00B9DB-3B for pgsql-hackers@lists.postgresql.org; Wed, 17 Dec 2025 08:11:43 +0000 Received: from fhigh-a3-smtp.messagingengine.com ([103.168.172.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVmdI-00173Y-1M for pgsql-hackers@lists.postgresql.org; Wed, 17 Dec 2025 08:11:41 +0000 Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 9FCF614000D7; Wed, 17 Dec 2025 03:11:38 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Wed, 17 Dec 2025 03:11:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1765959098; x=1766045498; bh=mSzJkZFn+v swNqXd5QxGaA06fbFRYzdjnJRTgR0NnU8=; b=aSmMg+iF7uxSvRdwJb94BIOqIP eduhNM7ihf+pdMKbGL4EcY/GKRVy99Mkd/U22W1wH97u/FTzwCXpvK2E0/Md2PPi oUvryKmWyXl3CxGp2IMIcRNLKbgwYlJuBu1aSm5FliBXNt0grwvDDQfy9XK7ouJD kHv/YlAKrFxWubQFBb3REjwtJg0IfgD8g7e+qVGKGsUy976msw7n/OzhqWi1Mqwc n9LHi1uqZ7v8ECPl1shwu0DE+PLRDDFSy5Ow8KGPjDD3dT5FpsNFczfza4fesmtj POxIMF+mmTwQnW3vFslD7vFXyZG+2rggaEg5o2yEXsRSMWJS6aEHJFzbT7sg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1765959098; x=1766045498; bh=mSzJkZFn+vswNqXd5QxGaA06fbFRYzdjnJR TgR0NnU8=; b=ySAP2Ak2rJUBL/Z/0pMEtV+Tq7hbll51z3TLpfSZtl+M2+kGSl7 nj3Gfb+XIJdVYZgDerAIKolyNG8OcdpbrdnBbPiPtLuLLUo8k8LxIhtaTOqY7ZSw 2a3LCcvkwID8elZcpVG+AaZIHrFrSfpXBpy2wLIEJ9hrB00oYPCzB2hzcYIxOGWm RQab2NCzhynzYdvB2pbYjViXj21fOuB38thlllCtpRKq6d0R512MHotkXiTkUtpV eXlCnVS4WLvZEYwIe3U97t2StRLQivm76XxY0BLohSLd2M0jXj55Dmgl+ukpnxtd fQVRndUlXNNmDZM21g9cnJEjr9FlvAVNsRg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdegvddthecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlh cuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvden ucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprghquh hivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleeifedufffhhfdtteelgeeggeff hfekueevteeigfduudevudetgfegiedvjeenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiiipdhn sggprhgtphhtthhopeegpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehpvghtvg hrsegvihhsvghnthhrrghuthdrohhrghdprhgtphhtthhopehsrghmihhmshgvihhhsehg mhgrihhlrdgtohhmpdhrtghpthhtoheplhhirdgvvhgrnhdrtghhrghosehgmhgrihhlrd gtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshht ghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 17 Dec 2025 03:11:36 -0500 (EST) Date: Wed, 17 Dec 2025 17:11:19 +0900 From: Michael Paquier To: Peter Eisentraut Cc: Sami Imseih , Chao Li , PostgreSQL Hackers Subject: Re: [Proposal] Adding callback support for custom statistics kinds Message-ID: References: <9252DA7C-C611-4A93-A484-E6CD42557C15@gmail.com> <4E61FDC4-CFBB-4116-980F-75ADD245A1F6@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="NTbI7Ttqv9v64IYC" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --NTbI7Ttqv9v64IYC Content-Type: multipart/mixed; boundary="mtY+f7cvTJXZBN8E" Content-Disposition: inline --mtY+f7cvTJXZBN8E Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Dec 17, 2025 at 08:03:36AM +0100, Peter Eisentraut wrote: > So it seems to me that either the callbacks API needs some adjustments, or > this particular implementation of the callback function is incorrect. Hmm, you are right that this is not aligned. This can be improved with one change for each callback: - It is OK with from_serialized_data() to manipulate the header data, because we want to fill a portion of the shmem data with extra data read from disk (the module wants to add a reference to a DSA stored in the shmem entry, read from the second file). So we should discard the const marker from the callback definition. - The const usage is OK for to_serialized_data(): it is better to encourage a policy where the header data cannot be manipulated. So the const needs to be kept in the definition, but I also think that we should change the module implementation so as the cast to PgStatShared_CustomVarEntry is a const. These changes result in the attached. Sami, what do you think? -- Michael --mtY+f7cvTJXZBN8E Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="custom-stats-const.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat= _internal.h index 5c1ce4d3d6af..01db3b701bdf 100644 --- a/src/include/utils/pgstat_internal.h +++ b/src/include/utils/pgstat_internal.h @@ -335,7 +335,7 @@ typedef struct PgStat_KindInfo const PgStatShared_Common *header, FILE *statfile); bool (*from_serialized_data) (const PgStat_HashKey *key, - const PgStatShared_Common *header, + PgStatShared_Common *header, FILE *statfile); =20 /* diff --git a/src/test/modules/test_custom_stats/test_custom_var_stats.c b/s= rc/test/modules/test_custom_stats/test_custom_var_stats.c index c71922dc4a8f..3dea38e3fe83 100644 --- a/src/test/modules/test_custom_stats/test_custom_var_stats.c +++ b/src/test/modules/test_custom_stats/test_custom_var_stats.c @@ -92,7 +92,7 @@ static void test_custom_stats_var_to_serialized_data(cons= t PgStat_HashKey *key, =20 /* Deserialization callback: read auxiliary entry data */ static bool test_custom_stats_var_from_serialized_data(const PgStat_HashKe= y *key, - const PgStatShared_Common *header, + PgStatShared_Common *header, FILE *statfile); =20 /* Finish callback: end of statistics file operations */ @@ -196,9 +196,10 @@ test_custom_stats_var_to_serialized_data(const PgStat_= HashKey *key, { char *description; size_t len; - PgStatShared_CustomVarEntry *entry =3D (PgStatShared_CustomVarEntry *) he= ader; bool found; uint32 magic_number =3D TEST_CUSTOM_VAR_MAGIC_NUMBER; + const PgStatShared_CustomVarEntry *entry =3D + (const PgStatShared_CustomVarEntry *) header; =20 /* * First mark the main file with a magic number, keeping a trace that some @@ -276,7 +277,7 @@ test_custom_stats_var_to_serialized_data(const PgStat_H= ashKey *key, */ static bool test_custom_stats_var_from_serialized_data(const PgStat_HashKey *key, - const PgStatShared_Common *header, + PgStatShared_Common *header, FILE *statfile) { PgStatShared_CustomVarEntry *entry; --mtY+f7cvTJXZBN8E-- --NTbI7Ttqv9v64IYC Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmlCZacACgkQnvQgOdby QH3Kog/7BWKS7PM7GhgzrQdGyKZMuEVBXC247KlPzYjiXYT0t9shhGabS0QFrThE AuB/7sQtbKwotK/nOQ7ahRgssoXYHIMVJ68sNn+OdsbzZbiQ895qED4rpOQqnL5e dKlcsDMkdvlHx3+Xq+S5vFCN4RKrZB1F3wwKz3y6eoAA1NvIGmwl2ShiiJXjkJOR 5GZG7dV6MXhAHZFABPahsl+8MCmAJINgDZLjFGRCMz4mEX6t7LaxU4ItE5s3gv/D stZsGrnoRif4Kw65Qe8WZmkfCmBXTt3EcULbMctF96+JVmN4833TPaTpk2jOHgJQ m+XTLJs3Km47PGrkmtCYyRnerQaO0WzdwgkAT1M/ALCuVOCaSJqWHSIaL05M6g8N f5KRAW+vXEuj5Lno2mOoh19xf17P64BBcLiG9nmKBI5R16zsgGgaZ5c77sb6khSz mL9kKbWMb+xLhKhmrN0mGG6urPuIAJZk/Nq64eyXHJR0/0E+k8yPg46GeM/WJ8aL A/WyOxzzc9062SM9E7uWFRHa+P+1zh4S6rh6yfsXk51BRF/UrSuiHUPb7JFjAlcT kokBxvkOi8zqa5zOeCIN/oCu0xEk/8+2R7djwaVPoQQpZnLtyD0fEuQacWGFT3AL gPgaBdAGz/x3PasJ1pGlQxhYjtxOhSoG7nrUx8fR+wdqw2nC0/s= =DN0m -----END PGP SIGNATURE----- --NTbI7Ttqv9v64IYC--