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 1t9QMJ-00A4JQ-7U for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Nov 2024 14:53:11 +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 1t9QMG-009yEh-II for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Nov 2024 14:53:09 +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.94.2) (envelope-from ) id 1t9QMF-009yEZ-5f for pgsql-hackers@lists.postgresql.org; Fri, 08 Nov 2024 14:53:08 +0000 Received: from fhigh-a2-smtp.messagingengine.com ([103.168.172.153]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t9QMC-000ouR-Mf for pgsql-hackers@postgresql.org; Fri, 08 Nov 2024 14:53:06 +0000 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 12B0311400EF; Fri, 8 Nov 2024 09:53:03 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 08 Nov 2024 09:53:03 -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=1731077583; x=1731163983; bh=WMzzDSkXGx i0IjJAmWPrUoIOasFXrKSyS3XxaKOLSAY=; b=ptdqx/4bOlSaPG/vYlOMIGwlN4 daw+BVR6fvwmUtqtFo1veoVnKFiv7eiULXwieLZjvLjcAvQyz2bfKKefYPpnYqJj 0GKxm/bj76xWHNVEFNwo+GHkOl5Hak5KiAWI/CS/T0RHHyLdUNUIr+mJ6sMu9Zdy LzgVO3MbgBDZlA8yFwF0qWR3ULOESro9Ai9Equ71o9vnR0unyNZvMbNuOLYTQ0M4 qh43HPbsIdxjkNfzC1QhRdWLX35/aAhBAFy8m0NEzaZAddwKss43OyKH/XDmC1gt tlWRqpxD5LZ9QsrKO3ZIuhziPMTKuLrPNlX+c7HgzHanKKkBkPPt0/wu4y6Q== 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= 1731077583; x=1731163983; bh=WMzzDSkXGxi0IjJAmWPrUoIOasFXrKSyS3X xaKOLSAY=; b=LVKeTs6dh9itJtZEkSusvwRzPmr0Z66mZWvuSXW+R2rAR5IonmD WfefbZzZdqxlI6xhq1Kuw7+IYVL8lCkUQHusqVzAaJX7ojtu10b0+a4MY1MEtm+w 83kj+hcy8u545fXmxC4HIdPnuUUWKmYY3FhWx/V3xsrfoj0aK2SYV+ByUumzL0Cz mEyDBIL3+OyKFjc9buEfViduBbkE3fHR+QdECaKpuKfnVuZIdeCANWS0kv9yLOtR 0vAmI34xfUwQmB4VHLXXmVn6rLVLuRTAlzo73dfYvnkhG9pks9QPtJEynbWwPxwF 91rTlAeuh6ocPPKx9sOkqfvhPcn1Ki4kVtQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrtdeigdeiiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdfstddttddvnecu hfhrohhmpeetnhgurhgvshcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlh druggvqeenucggtffrrghtthgvrhhnpeeffffgledvffegtdevlefgtdeggffhvdekgfeg teeiveejkeetudelveejhfeugeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghlrdguvgdpnhgspghrtghp thhtohepjedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohephhhouhiijhdrfhhnsh htsehfuhhjihhtshhurdgtohhmpdhrtghpthhtoheprghmihhtrdhkrghpihhlrgduiees ghhmrghilhdrtghomhdprhgtphhtthhopehshhhvvghtrgdrmhgrlhhikhesghhmrghilh drtghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhq lhdrohhrghdprhgtphhtthhopegrlhgvkhhsrghnuggvrhesthhimhgvshgtrghlvgdrtg homhdprhgtphhtthhopehtohhmrghssehvohhnughrrgdrmhgvpdhrtghpthhtohepjhgr nhesfihifegtkhdrihhnfhho X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 8 Nov 2024 09:53:02 -0500 (EST) Date: Fri, 8 Nov 2024 09:53:01 -0500 From: Andres Freund To: "Zhijie Hou (Fujitsu)" Cc: Amit Kapila , Aleksander Alekseev , pgsql-hackers , shveta malik , "tomas@vondra.me" , Jan Wieck 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: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2024-11-08 09:08:55 +0000, Zhijie Hou (Fujitsu) wrote: > On Friday, November 8, 2024 2:20 AM Andres Freund wrote: > > 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. > > I understand your concern and appreciate the feedback. I've made some > adjustments to the patch by directly placing the code to adjust the commit > timestamp within the spinlock, aiming to keep it as efficient as possible. The > changes have resulted in just a few extra lines. Would this approach be > acceptable to you ? No, not at all. I think it's basically not acceptable to add any nontrivial instruction to the locked portion of ReserveXLogInsertLocation(). Before long we're going to have to replace that spinlocked instruction with atomics, which will make it impossible to just block while holding the lock anyway. IMO nothing that touches core xlog insert infrastructure is acceptable for this. Greetings, Andres Freund