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.94.2) (envelope-from ) id 1qTAki-008f45-Sc for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Aug 2023 00:39:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qTAkh-00CYsR-CI for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Aug 2023 00:39:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qTAkh-00CYsI-3H for pgsql-hackers@lists.postgresql.org; Tue, 08 Aug 2023 00:39:11 +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 1qTAke-001Bqf-Cm for pgsql-hackers@lists.postgresql.org; Tue, 08 Aug 2023 00:39:10 +0000 Received: from oss.nttdata.com (localhost [127.0.0.1]) by oss.nttdata.com (Postfix) with ESMTPA id 958C56084B; Tue, 8 Aug 2023 09:39:02 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at oss.nttdata.com MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 08 Aug 2023 09:39:02 +0900 From: Masahiro Ikeda To: Michael Paquier Cc: Andres Freund , Bharath Rupireddy , Tristan Partin , pgsql-hackers@lists.postgresql.org Subject: Re: Support to define custom wait events for extensions In-Reply-To: References: <446d286f3272437df705ee69ad0d8793@oss.nttdata.com> <171b38978ae8a21e5635998d9bfedbf6@oss.nttdata.com> <20230801032349.aaiuvhtrcvvcwzcx@awork3.anarazel.de> <9cc4136f9e3629a2ffc8ac66b4de3f31@oss.nttdata.com> User-Agent: Roundcube Webmail/1.4.11 Message-ID: <2373bd1fe4d0156649dc5794a86fe94e@oss.nttdata.com> X-Sender: ikedamsh@oss.nttdata.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-08-08 08:54, Michael Paquier wrote: > On Wed, Aug 02, 2023 at 06:34:15PM +0900, Masahiro Ikeda wrote: >> On 2023-08-01 12:23, Andres Freund wrote: >>> This is why the scheme as implemented doesn't really make sense to >>> me. >>> It'd be >>> much easier to use if we had a shared hashtable with the identifiers >>> than >>> what's been merged now. >>> >>> In plenty of cases it's not realistic for an extension library to run >>> in >>> each >>> backend, while still needing to wait for things. >> >> OK, I'll try to make a PoC patch. > > Hmm. There are a few things to take into account here: > - WaitEventExtensionShmemInit() should gain a dshash_create(), to make > sure that the shared table is around, and we are going to have a > reference to it in WaitEventExtensionCounterData, saved from > dshash_get_hash_table_handle(). > - The hash table entries could just use nextId as key to look at the > entries, with entries added during WaitEventExtensionNew(), and use as > contents the name of the wait event. We are going to need a fixed > size for these custom strings, but perhaps a hard limit of 256 > characters for each entry of the hash table is more than enough for > most users? > - WaitEventExtensionRegisterName() could be removed, I guess, replaced > by a single WaitEventExtensionNew(), as of: > uint32 WaitEventExtensionNew(const char *event_name); > - GetWaitEventExtensionIdentifier() needs to switch to a lookup of the > shared hash table, based on the eventId. > > All that would save from the extra WaitEventExtensionRegisterName() > needed in the backends to keep a track of the names, indeed. Thank you for pointing the direction of implementation. I am thinking a bit that we also need another hash where the key is a custom string. For extensions that have no dependencies with shared_preload_libraries, I think we need to avoid that WaitEventExtensionNew() is called repeatedly and a new eventId is issued each time. So, is it better to have another hash where the key is a custom string and uniqueness is identified by it to determine if a new eventId should be issued? Regards, -- Masahiro Ikeda NTT DATA CORPORATION