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 1tAPei-00Fagd-Ar for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 08:20:15 +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 1tAPef-00CVPe-3c for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Nov 2024 08:20:13 +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 1tAPee-00CVPV-Pn for pgsql-hackers@lists.postgresql.org; Mon, 11 Nov 2024 08:20:13 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tAPec-001GUp-S2 for pgsql-hackers@postgresql.org; Mon, 11 Nov 2024 08:20:12 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-5ee354637b4so2552832eaf.3 for ; Mon, 11 Nov 2024 00:20:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731313210; x=1731918010; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=N5sGHz6cFe/h+XrGS6E+2CU3SvqGEyOi9ofldxODzTg=; b=EIAmdN1GjejVU5q9HQM9Qr1x5XRkudT14zWQ04TXBTSFVVtOkF/qny2nadWKqLLudy nthkd/yaEYVkdh9MwUmj+YHeGUVmTGEOjPEfom8I4kygL91HlrpAE51xXTaKa014OMA/ TISBQhHsKFRWjs3ohIpc08rabmwpg/hR2zYvg8D2N11AOg69WodkNcg4wtly7Cq+oCYS Z+Crb39L9G7Y92Hq+oKGDqd93I6ySm5eKzSxKBQfg3q4bmekm36dfghMVWE99Z2CtXN+ FvErIJLiw+WdfBulVh5tukzqQ0LyT9Gb2WZaAa25Ztu1iYo9p7weafRbPEEqEWicIrPH b3iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731313210; x=1731918010; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N5sGHz6cFe/h+XrGS6E+2CU3SvqGEyOi9ofldxODzTg=; b=Db3WItCI08B224ZNe6GukkP2OdDlRrg8Ih1d7ZrPXPrxMDJ5rH4jVbjU/q0VstLjot hhPpJLCIe0PI1bMbo/wc+FeIeyXwyd5MTESJtp3T7+E/ZSObM0VKVcYnp1VRxH5/yn7T fm35tPZpFn8n0LavkSPcjIh+5uE/CL1dkkauFO2qoe1qfs2OYpjRhMk4zz2tufwX0drT +IoGz0ILYA9vhWoFkN05afTX2TlUNQ1x2WRQX4PDrkHqjiLwy/nM6Z+1ZlmcitF++umW c+Dh+MItsmHzy5YR8s6N7nyVNY5z0/rZRlLTZLa3zFXZH34vBLzUVOsKFcTp11p3GXGR dhfw== X-Forwarded-Encrypted: i=1; AJvYcCVltBsrYcRb91fdWtnxMRSMKIgkx8mWCayfqNw4H1TP1rZbF22sGKkbugtFSK86PDwSgTuNDkn2aClZC5uT@postgresql.org X-Gm-Message-State: AOJu0YwhjPhLwB0a4BAZqbqwxSH6CMfv9ND1Q4YhWSeIWEzwdPG6l2Q5 ALeqFQGltHoxoWCCpdlhm0KXNDT9Qsuusu0jN2h8vbpNAlHfxU7efE+xFAkONvBblyjE/JytQrd SELgoheUZaOrKFsVPmiQjvEKB6IU= X-Google-Smtp-Source: AGHT+IFxHVIIf3SxJ+XKrGPoTWPqry500Z/8LYW1Ota+4coJcmfIrBetQm7jGz/uYVDxXLHumDAAiqf7yhTPF2QqpvY= X-Received: by 2002:a05:6820:1a0e:b0:5ee:bb2:bdc3 with SMTP id 006d021491bc7-5ee57ba8dbfmr7770226eaf.2.1731313210026; Mon, 11 Nov 2024 00:20:10 -0800 (PST) MIME-Version: 1.0 References: <9f7f4def-7ea8-4ad3-83e7-a8cc9d18c58a@wi3ck.info> In-Reply-To: From: Amit Kapila Date: Mon, 11 Nov 2024 13:49:58 +0530 Message-ID: Subject: Re: Commit Timestamp and LSN Inversion issue To: Andres Freund Cc: "Zhijie Hou (Fujitsu)" , Aleksander Alekseev , pgsql-hackers , shveta malik , "tomas@vondra.me" , Jan Wieck Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Nov 8, 2024 at 8:23=E2=80=AFPM Andres Freund w= rote: > > On 2024-11-08 09:08:55 +0000, Zhijie Hou (Fujitsu) wrote: > > > > > > I think it's *completely* unacceptable to call a hook inside > > > ReserveXLogInsertLocation, with the spinlock held, no less. That's th= e 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 com= mit > > timestamp within the spinlock, aiming to keep it as efficient as possib= le. 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 nontrivi= al > instruction to the locked portion of ReserveXLogInsertLocation(). > > Before long we're going to have to replace that spinlocked instruction wi= th > atomics, which will make it impossible to just block while holding the lo= ck > anyway. > > IMO nothing that touches core xlog insert infrastructure is acceptable fo= r > this. > I can't think of a solution other than the current proposal where we do both the operations (reserve WAL space for commit and adjust commit_timestamp, if required) together to resolve LSN<->Timestamp invertion issue. Please let us know if you have any other ideas for solving this. Even, if we want to change ReserveXLogInsertLocation to make the locked portion an atomic operation, we can still do it for records other than commit. Now, if we don't have any other solution for LSN<->Timestamp inversion issue, changing the entire locked portion to atomic will close the door to solving this problem forever unless we have some other way to solve it which can make it difficult to rely on commit_timestamps for certain scenarios. --=20 With Regards, Amit Kapila.