Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qJUeX-0002yK-Bp for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Jul 2023 07:52:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qJUeV-0008WA-Rw for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Jul 2023 07:52:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qJUeV-0008VD-IL for pgsql-hackers@lists.postgresql.org; Wed, 12 Jul 2023 07:52:47 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qJUeS-003dHT-FT for pgsql-hackers@lists.postgresql.org; Wed, 12 Jul 2023 07:52:46 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTPA id 8E6656063B; Wed, 12 Jul 2023 16:52:38 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at oss.nttdata.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=_817a8f20dec13726f45d6480eaf38b70" Content-Transfer-Encoding: 7bit Date: Wed, 12 Jul 2023 16:52:38 +0900 From: Masahiro Ikeda To: Michael Paquier Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Support to define custom wait events for extensions In-Reply-To: References: <135feae32cd28f9fb555fe46acb939a0@oss.nttdata.com> User-Agent: Roundcube Webmail/1.4.11 Message-ID: X-Sender: ikedamsh@oss.nttdata.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --=_817a8f20dec13726f45d6480eaf38b70 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On 2023-07-11 16:45, Michael Paquier wrote: > On Fri, Jun 23, 2023 at 05:56:26PM +0900, Masahiro Ikeda wrote: >> I updated the patches to handle the warning mentioned >> by PostgreSQL Patch Tester, and removed unnecessary spaces. > > I have begun hacking on that, and the API layer inspired from the > LWLocks is sound. I have been playing with it in my own extensions > and it is nice to be able to plug in custom wait events into > pg_stat_activity, particularly for bgworkers. Finally. Great! > The patch needed a rebase after the recent commit that introduced the > automatic generation of docs and code for wait events. It requires > two tweaks in generate-wait_event_types.pl, feel free to double-check > them. Thanks for rebasing. I confirmed it works with the current master. I know this is a little off-topic from what we're talking about here, but I'm curious about generate-wait_event_types.pl. # generate-wait_event_types.pl - # An exception is required for LWLock and Lock as these don't require - # any C and header files generated. + # An exception is required for Extension, LWLock and Lock as these don't + # require any C and header files generated. die "wait event names must start with 'WAIT_EVENT_'" if ( $trimmedwaiteventname eq $waiteventenumname + && $waiteventenumname !~ /^Extension/ && $waiteventenumname !~ /^LWLock/ && $waiteventenumname !~ /^Lock/); In my understanding, the first column of the row for WaitEventExtension in wait_event_names.txt can be any value and the above code should not die. But if I use the following input, it falls on the last line. # wait_event_names.txt Section: ClassName - WaitEventExtension WAIT_EVENT_EXTENSION "Extension" "Waiting in an extension." Extension "Extension" "Waiting in an extension." EXTENSION "Extension" "Waiting in an extension." If the behavior is unexpected, we need to change the current code. I have created a patch for the areas that I felt needed to be changed. - 0001-change-the-die-condition-in-generate-wait_event_type.patch (In addition to the above, "$continue = ",\n";" doesn't appear to be necessary.) > Some of the new structures and routine names don't quite reflect the > fact that we have wait events for extensions, so I have taken a stab > at that. Sorry. I confirmed the change. > Note that the test module test_custom_wait_events would crash if > attempting to launch a worker when not loaded in > shared_preload_libraries, so we'd better have some protection in > wait_worker_launch() (this function should be renamed as well). OK, I will handle it. Since Andres gave me other comments for the test module, I'll think about what is best. > Attached is a rebased patch that I have begun tweaking here and > there. For now, the patch is moved as waiting on author. I have > merged the test module with the main patch for the moment, for > simplicity. A split is straight-forward as the code paths touched are > different. > > Another and *very* important thing is that we are going to require > some documentation in xfunc.sgml to explain how to use these routines > and what to expect from them. Ikeda-san, could you write some? You > could look at the part about shmem and LWLock to get some > inspiration. OK. Yes, I planned to write documentation. Regards, -- Masahiro Ikeda NTT DATA CORPORATION --=_817a8f20dec13726f45d6480eaf38b70 Content-Transfer-Encoding: base64 Content-Type: text/x-diff; name=0001-change-the-die-condition-in-generate-wait_event_type.patch Content-Disposition: attachment; filename=0001-change-the-die-condition-in-generate-wait_event_type.patch; size=1100 RnJvbSA1MTk4ZmM2MzAyYTNiZjQyMzIyNTJiMjNiNDVkMzlkOTg3ZTczNmJjIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBNYXNhaGlybyBJa2VkYSA8bWFzYWhpcm8uaWtlZGEudXNAaGNv Lm50dC5jby5qcD4KRGF0ZTogV2VkLCAxMiBKdWwgMjAyMyAxNjoyODoyNyArMDkwMApTdWJqZWN0 OiBbUEFUQ0hdIGNoYW5nZSB0aGUgZGllIGNvbmRpdGlvbiBpbiBnZW5lcmF0ZS13YWl0X2V2ZW50 X3R5cGVzLnBsCgotLS0KIHNyYy9iYWNrZW5kL3V0aWxzL2FjdGl2aXR5L2dlbmVyYXRlLXdhaXRf ZXZlbnRfdHlwZXMucGwgfCA1ICsrLS0tCiAxIGZpbGUgY2hhbmdlZCwgMiBpbnNlcnRpb25zKCsp LCAzIGRlbGV0aW9ucygtKQoKZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3V0aWxzL2FjdGl2aXR5 L2dlbmVyYXRlLXdhaXRfZXZlbnRfdHlwZXMucGwgYi9zcmMvYmFja2VuZC91dGlscy9hY3Rpdml0 eS9nZW5lcmF0ZS13YWl0X2V2ZW50X3R5cGVzLnBsCmluZGV4IDZkMWEyYWY0MmEuLmZiZTAxMTAz OWEgM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