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 1rSDyL-00CCmK-M6 for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2024 10:25:38 +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 1rSDyK-00Bh0R-NX for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2024 10:25:36 +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 1rSDyK-00Bh0J-A7 for pgsql-hackers@lists.postgresql.org; Tue, 23 Jan 2024 10:25:36 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rSDyC-003HaY-S6 for pgsql-hackers@lists.postgresql.org; Tue, 23 Jan 2024 10:25:35 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id 6CB595C026B for ; Tue, 23 Jan 2024 05:25:27 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Tue, 23 Jan 2024 05:25:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1706005527; x=1706091927; bh=rZ5vat2IMNBC2pamlOyYi6BSA6Ws tUfjFd5wx2tUpkk=; b=GfusDgo2HbQYgvPqo/VGmkjUrnbYNXqiB1veo9DYbD4t r5z4dS/v43Kcw7WHEFxxLc3q7sIbND4XhxfjtY28yDeyQzpSaRTo8jaAR6974fwz 4TNYSPopCNlLMasIwvBHLWqdfO6ePCVmgeeCZgXekQsSRqWIFg2eDG/aB2mPUJYd dw4Bd3w06ZqdKdGvmQZUPGoYzzSBlwYZosc/2SLSaEIznU1J1kjEm/O0YdtjcU7j LTO26iaFFF41nf9X/Ncz9WtTP81xtflQPzpgXZhkvAumjQs6MFnH0m/bOVKkft8z dCbCG0cxBxsYLTNIjlrt9cXIqQUSj8M9EjcfecOwPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekkedgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfesmhekreertddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnhepkeeklefhtdefhfevhfetieejveffleevudduheefffffveff vddukeeikeefieeinecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgv rhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 23 Jan 2024 05:25:27 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1706005525; bh=akG1/gj8D3mD+J5MO1ZoNDbd+8fX1YgaKG8WC5oyCwA=; h=Date:From:To:Subject:From; b=YZx4XlERvKIf1u7s9RMub6Jj27YtYdNhrmweqCfY0eHRKFDkyQIWBFXUCx/CVi6VD AE+vmZT2WJqEsTtctrdBPNiGe8grBdvlu2435TUAwfQX/8Ro1e7JN7Ml4ld2aPOP75 5Vpl/Hi3YDH++m/6g+eZXwsoxnP1/0jz1qEgTqvZPeKJcrumJ5INHEmHe9wg1l1jul 2DW0/qgnolVfLjKa+9iJfKFtd4pBYQ4iG+P17zacL443g2rg6FEeAKlWy53YmRvqgu qVLCgYzUTw/79mL8os0S/JUKGwfcLWitveU1VOBpDQqw0c4GYU1HhN5rZrnj+EBmmq 62P5McGy2F1/A== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 78C7898; Tue, 23 Jan 2024 11:25:25 +0100 (CET) Date: Tue, 23 Jan 2024 11:25:25 +0100 From: Alvaro Herrera To: Pg Hackers Subject: make BuiltinTrancheNames less ugly Message-ID: <202401231025.gbv4nnte5fmm@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="aqtqopkpiduoph6v" Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --aqtqopkpiduoph6v Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit This array of tranche names is looking pretty ugly these days, and it'll get worse as we add more members to it. I propose to use C99 designated initializers, like we've done for other arrays. Patch attached. The way I've coded in this patch, it means the array will now have 52 NULL pointers at the beginning. I don't think this is a big deal and makes the code prettier. I see two alternatives: 1. Avoid all those NULLs by making each definition uglier (subtract NUM_INDIVIDUAL_LWLOCKS from each array index) _and_ the usage of the array by subtracting the same amount. This saves 208 bytes at the expense of making the code worse. 2. More invasively, rework generate-lwlocknames.pl so that both lwlocks and these builtin tranche names appear in a single array. (We could do so by #include'ing lwlocknames.c at the top of the array). Now, having written this proposal, I'm leaning towards idea 2 myself, but since the patch here is less invasive, it seems worth having as evidence. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "People get annoyed when you try to debug them." (Larry Wall) --aqtqopkpiduoph6v Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-Use-designated-initializers-for-BuiltinTrancheNames.patch" From 037fc293b359fbe7dfffcdaf8d5816daa82c0ddd Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 23 Jan 2024 10:36:14 +0100 Subject: [PATCH] Use designated initializers for BuiltinTrancheNames --- src/backend/storage/lmgr/lwlock.c | 97 +++++++++++-------------------- 1 file changed, 33 insertions(+), 64 deletions(-) diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 2f2de5a562..98fa6035cc 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -132,72 +132,41 @@ StaticAssertDecl(LW_VAL_EXCLUSIVE > (uint32) MAX_BACKENDS, extern const char *const IndividualLWLockNames[]; /* in lwlocknames.c */ static const char *const BuiltinTrancheNames[] = { - /* LWTRANCHE_XACT_BUFFER: */ - "XactBuffer", - /* LWTRANCHE_COMMITTS_BUFFER: */ - "CommitTsBuffer", - /* LWTRANCHE_SUBTRANS_BUFFER: */ - "SubtransBuffer", - /* LWTRANCHE_MULTIXACTOFFSET_BUFFER: */ - "MultiXactOffsetBuffer", - /* LWTRANCHE_MULTIXACTMEMBER_BUFFER: */ - "MultiXactMemberBuffer", - /* LWTRANCHE_NOTIFY_BUFFER: */ - "NotifyBuffer", - /* LWTRANCHE_SERIAL_BUFFER: */ - "SerialBuffer", - /* LWTRANCHE_WAL_INSERT: */ - "WALInsert", - /* LWTRANCHE_BUFFER_CONTENT: */ - "BufferContent", - /* LWTRANCHE_REPLICATION_ORIGIN_STATE: */ - "ReplicationOriginState", - /* LWTRANCHE_REPLICATION_SLOT_IO: */ - "ReplicationSlotIO", - /* LWTRANCHE_LOCK_FASTPATH: */ - "LockFastPath", - /* LWTRANCHE_BUFFER_MAPPING: */ - "BufferMapping", - /* LWTRANCHE_LOCK_MANAGER: */ - "LockManager", - /* LWTRANCHE_PREDICATE_LOCK_MANAGER: */ - "PredicateLockManager", - /* LWTRANCHE_PARALLEL_HASH_JOIN: */ - "ParallelHashJoin", - /* LWTRANCHE_PARALLEL_QUERY_DSA: */ - "ParallelQueryDSA", - /* LWTRANCHE_PER_SESSION_DSA: */ - "PerSessionDSA", - /* LWTRANCHE_PER_SESSION_RECORD_TYPE: */ - "PerSessionRecordType", - /* LWTRANCHE_PER_SESSION_RECORD_TYPMOD: */ - "PerSessionRecordTypmod", - /* LWTRANCHE_SHARED_TUPLESTORE: */ - "SharedTupleStore", - /* LWTRANCHE_SHARED_TIDBITMAP: */ - "SharedTidBitmap", - /* LWTRANCHE_PARALLEL_APPEND: */ - "ParallelAppend", - /* LWTRANCHE_PER_XACT_PREDICATE_LIST: */ - "PerXactPredicateList", - /* LWTRANCHE_PGSTATS_DSA: */ - "PgStatsDSA", - /* LWTRANCHE_PGSTATS_HASH: */ - "PgStatsHash", - /* LWTRANCHE_PGSTATS_DATA: */ - "PgStatsData", - /* LWTRANCHE_LAUNCHER_DSA: */ - "LogicalRepLauncherDSA", - /* LWTRANCHE_LAUNCHER_HASH: */ - "LogicalRepLauncherHash", - /* LWTRANCHE_DSM_REGISTRY_DSA: */ - "DSMRegistryDSA", - /* LWTRANCHE_DSM_REGISTRY_HASH: */ - "DSMRegistryHash", + [LWTRANCHE_XACT_BUFFER] = "XactBuffer", + [LWTRANCHE_COMMITTS_BUFFER] = "CommitTsBuffer", + [LWTRANCHE_SUBTRANS_BUFFER] = "SubtransBuffer", + [LWTRANCHE_MULTIXACTOFFSET_BUFFER] = "MultiXactOffsetBuffer", + [LWTRANCHE_MULTIXACTMEMBER_BUFFER] = "MultiXactMemberBuffer", + [LWTRANCHE_NOTIFY_BUFFER] = "NotifyBuffer", + [LWTRANCHE_SERIAL_BUFFER] = "SerialBuffer", + [LWTRANCHE_WAL_INSERT] = "WALInsert", + [LWTRANCHE_BUFFER_CONTENT] = "BufferContent", + [LWTRANCHE_REPLICATION_ORIGIN_STATE] = "ReplicationOriginState", + [LWTRANCHE_REPLICATION_SLOT_IO] = "ReplicationSlotIO", + [LWTRANCHE_LOCK_FASTPATH] = "LockFastPath", + [LWTRANCHE_BUFFER_MAPPING] = "BufferMapping", + [LWTRANCHE_LOCK_MANAGER] = "LockManager", + [LWTRANCHE_PREDICATE_LOCK_MANAGER] = "PredicateLockManager", + [LWTRANCHE_PARALLEL_HASH_JOIN] = "ParallelHashJoin", + [LWTRANCHE_PARALLEL_QUERY_DSA] = "ParallelQueryDSA", + [LWTRANCHE_PER_SESSION_DSA] = "PerSessionDSA", + [LWTRANCHE_PER_SESSION_RECORD_TYPE] = "PerSessionRecordType", + [LWTRANCHE_PER_SESSION_RECORD_TYPMOD] = "PerSessionRecordTypmod", + [LWTRANCHE_SHARED_TUPLESTORE] = "SharedTupleStore", + [LWTRANCHE_SHARED_TIDBITMAP] = "SharedTidBitmap", + [LWTRANCHE_PARALLEL_APPEND] = "ParallelAppend", + [LWTRANCHE_PER_XACT_PREDICATE_LIST] = "PerXactPredicateList", + [LWTRANCHE_PGSTATS_DSA] = "PgStatsDSA", + [LWTRANCHE_PGSTATS_HASH] = "PgStatsHash", + [LWTRANCHE_PGSTATS_DATA] = "PgStatsData", + [LWTRANCHE_LAUNCHER_DSA] = "LogicalRepLauncherDSA", + [LWTRANCHE_LAUNCHER_HASH] = "LogicalRepLauncherHash", + [LWTRANCHE_DSM_REGISTRY_DSA] = "DSMRegistryDSA", + [LWTRANCHE_DSM_REGISTRY_HASH] = "DSMRegistryHash", }; StaticAssertDecl(lengthof(BuiltinTrancheNames) == - LWTRANCHE_FIRST_USER_DEFINED - NUM_INDIVIDUAL_LWLOCKS, + LWTRANCHE_FIRST_USER_DEFINED, "missing entries in BuiltinTrancheNames[]"); /* @@ -775,7 +744,7 @@ GetLWTrancheName(uint16 trancheId) /* Built-in tranche? */ if (trancheId < LWTRANCHE_FIRST_USER_DEFINED) - return BuiltinTrancheNames[trancheId - NUM_INDIVIDUAL_LWLOCKS]; + return BuiltinTrancheNames[trancheId]; /* * It's an extension tranche, so look in LWLockTrancheNames[]. However, -- 2.39.2 --aqtqopkpiduoph6v--