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 1t976k-007q9m-WF for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 18:19:50 +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 1t976h-00113u-K1 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2024 18:19:48 +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 1t976h-00112f-AT for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2024 18:19:47 +0000 Received: from fhigh-a5-smtp.messagingengine.com ([103.168.172.156]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t976e-000iTC-0I for pgsql-hackers@postgresql.org; Thu, 07 Nov 2024 18:19:47 +0000 Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id A6F1B1140118; Thu, 7 Nov 2024 13:19:43 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-10.internal (MEProxy); Thu, 07 Nov 2024 13:19:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; 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=fm3; t=1731003583; x=1731089983; bh=Ajy3kjoaHK 0tiQFo6CXHHQWZeJVaUm3Bu3P/VMr/B+o=; b=KcoFXGhI3BcCtF2+mBMOXDZqFn UNHn5SWimjz74OCPKTIViq4igEGMx4nMGJh5RudDDSpflS7xNu9ex82lz0c5LRz8 latFQKJa+bKAPksesAVnDCMZiTFRXEX9LI59gytfk+d8H+Wa+NUKdaBuP9udmy4J p9lCVWjW8dAN9emBn9CxiRl2oavV/UdNpclwO1sY6m6waFAMjgfbqD/GwL6haWMX 1OdESMPZAC/UEWm9jihHgCeFOoeTOOVKcHPnJyF/NkKwFX4zJO5sodwSPbYmV9tD 07mRAIy9ZGfSrrjD49ralIukeclfv5I24Y3Ou/WFXjwS1n0kjYtGKpwfbuhA== 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=fm3; t= 1731003583; x=1731089983; bh=Ajy3kjoaHK0tiQFo6CXHHQWZeJVaUm3Bu3P /VMr/B+o=; b=GObZt1UN71+XBJ0dATx5sLfdPHcnrmW9/RFM6LDW4B+5LI2PKkB Sf4EUCSaJhMV+iG2WED/bB/4UF/dMcJcltylLqgZKuCD8G6MUNbRsbG4fcU4E05z iD1WcxW6xDM0t6IBxGDgw1/TYTSisZI7qEIrAe+79s1DSqD62prYPLjxMpG5l1Zf 4hCnSQ9opz0Vp9hL40kVrGMQXXhEtCEU0hZv6GdkrEaijtbYTUPUTuD87aWlS0Ei ow12/+IkAQW4ud2ComJaQBMyMf4tNymccTGkQjCOsD7XFlibf+We0h8CNUpymTQ8 Nm2ja8yZ/BZdv0isg3UHjG1zBiDM7Ca1VoA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtdeggdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkfhggtggujgesthdtsfdttddtvden ucfhrhhomheptehnughrvghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivg hlrdguvgeqnecuggftrfgrthhtvghrnhepfeffgfelvdffgedtveelgfdtgefghfdvkefg geetieevjeekteduleevjefhueegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgt phhtthhopeejpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehhohhuiihjrdhfnh hsthesfhhujhhithhsuhdrtghomhdprhgtphhtthhopegrmhhithdrkhgrphhilhgrudei sehgmhgrihhlrdgtohhmpdhrtghpthhtohepshhhvhgvthgrrdhmrghlihhksehgmhgrih hlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghs qhhlrdhorhhgpdhrtghpthhtoheprghlvghkshgrnhguvghrsehtihhmvghstggrlhgvrd gtohhmpdhrtghpthhtohepthhomhgrshesvhhonhgurhgrrdhmvgdprhgtphhtthhopehj rghnseifiheftghkrdhinhhfoh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 7 Nov 2024 13:19:43 -0500 (EST) Date: Thu, 7 Nov 2024 13:19:42 -0500 From: Andres Freund To: Jan Wieck Cc: Amit Kapila , Aleksander Alekseev , pgsql-hackers , shveta malik , "Zhijie Hou (Fujitsu)" , tomas@vondra.me Subject: Re: Commit Timestamp and LSN Inversion issue Message-ID: References: <9f7f4def-7ea8-4ad3-83e7-a8cc9d18c58a@wi3ck.info> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9f7f4def-7ea8-4ad3-83e7-a8cc9d18c58a@wi3ck.info> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2024-11-05 08:58:36 -0500, Jan Wieck wrote: > The attached solution is minimally invasive because it doesn't move the > timestamp generation (clock_gettime() call) into the critical section of > ReserveXLogInsertLocation() that is protected by a spinlock. Instead it > keeps track of the last commit-ts written to WAL in shared memory and simply > bumps that by one microsecond if the next one is below or equal. There is > one extra condition in that code section plus a function call by pointer for > every WAL record. In the unlikely case of encountering a stalled or > backwards running commit-ts, the expensive part of recalculating the CRC of > the altered commit WAL-record is done later, after releasing the spinlock. I > have not been able to measure any performance impact on a machine with 2x > Xeon-Silver (32 HT cores). I think it's *completely* unacceptable to call a hook inside ReserveXLogInsertLocation, with the spinlock held, no less. That's the most contended section of code in postgres. Even leaving that aside, something with a spinlock held is never a suitable place to call a hook. As the header comments say: * Keep in mind the coding rule that spinlocks must not be held for more * than a few instructions. In particular, we assume it is not possible * for a CHECK_FOR_INTERRUPTS() to occur while holding a spinlock, and so * it is not necessary to do HOLD/RESUME_INTERRUPTS() in these macros. I'm also quite certain that we don't want to just allow to redirect XLogInsert to some random function. WAL logging is very crucial code and allowing to randomly redirect it to something we don't know about will make it harder to write correct WAL logging code and makes already quite complicated code even more complicated. > This will work fine until we have systems that can sustain a commit rate of > one million transactions per second or higher for more than a few > milliseconds. It's sustainable for many minutes today. Greetings, Andres Freund