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 1tAsZV-000bim-Lp for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Nov 2024 15:12:49 +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 1tAsZS-007LnA-PX for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Nov 2024 15:12:47 +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 1tAsZS-007Ln1-8k for pgsql-hackers@lists.postgresql.org; Tue, 12 Nov 2024 15:12:47 +0000 Received: from mail-qv1-xf2e.google.com ([2607:f8b0:4864:20::f2e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tAsZP-001VJN-WD for pgsql-hackers@postgresql.org; Tue, 12 Nov 2024 15:12:45 +0000 Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-6cbe700dcc3so40474146d6.3 for ; Tue, 12 Nov 2024 07:12:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wi3ck-info.20230601.gappssmtp.com; s=20230601; t=1731424363; x=1732029163; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ttOaikiyJVdAeBAyD8YufIFTa2grQ67XHE8T6Bsv8Ho=; b=Z92JSHYVWCSw+aCe85eA+kHNT3pvhnghsxHfcWAgzl7tvdGnF+yvEaP0dkMD1pFvXF 4q6BrYfSqlBAScTKaasqlJKhGrPtltpU5eB8El2YeE2x+Dt8NRMQtOSUNqQF7bRZTlaz ReeSEoBwiKxY96SHnCQ0RLE2GaYvFMQQ3yReTMXYRswS9AqXeyW9edR6hY2ciByzhoO2 xQt3Y9JOzKLNp9XRA730HybmPWrtOY4zyj86E4BMPMoDreoeJ9WvUuWAtFR7pzPNZHDg mCbWCTCFxZUo/teHMV91pPQiUEq+au69sNQMMmGWWwmNiyyHqTQ7Coj0Ylv4o/aAaWXz YMRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731424363; x=1732029163; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ttOaikiyJVdAeBAyD8YufIFTa2grQ67XHE8T6Bsv8Ho=; b=Xnx06PbINh7S6syfvMMm/ws2UQHjH6nx3YU1MEBxN+W18EVUliJYfSZJv5//3saXHe YfVRAACM2tjGvSXDizIeeKOHmmlNcGaxHVPnr86eqINOeN30IbLWAh+kqdaXmKtIy7lS um9Tr0bk4cD3fG3lEvBnojKj+0OkVn1QYKKRHLk5T3usuCGNDQveR8F6ohU0JgGklfY4 jCLEWRrQGGFzrDbRhorRagkL6k6mR1gYnHxT047ozDrU3hzy4g1sXgVmBLa9waiYVk1M zrZt6TUY0fdF6+pArN707SDqCCFxtsteNFN9cddiiYtPREY8WEngKwaGteddsYXxu5R0 8F3A== X-Forwarded-Encrypted: i=1; AJvYcCUTAojb/G0g9GMV4i4xI28oCIbKzFO9fF8tLgsaXKGUKvmdScvl6T7pVU3gkMBekQXIoEf+pfJdY2FXFRJ7@postgresql.org X-Gm-Message-State: AOJu0YyeGJ++izR2mzApTQWBAj7Rz0c2ChX1tNfF/xJqNgyVtpVlaio/ vOADW1Tg0sPu0Y+IsMwhykmy2iJqNgi9eo4TzvoAHlCOD/w5nSAcNpOEPe0kJvs= X-Google-Smtp-Source: AGHT+IHkXLqaJQAGEElZ1BgC4OlWgITo1xO0U4fOGwQC8sCh0Ye5zuqcmAbMrIXu5Nu4xLO6rm8RKw== X-Received: by 2002:a05:6214:3286:b0:6cb:c54c:b782 with SMTP id 6a1803df08f44-6d39e1d04a2mr241739646d6.32.1731424362781; Tue, 12 Nov 2024 07:12:42 -0800 (PST) Received: from [172.21.0.10] (pool-108-16-53-81.phlapa.fios.verizon.net. [108.16.53.81]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d3961e076esm72382966d6.13.2024.11.12.07.12.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Nov 2024 07:12:42 -0800 (PST) Message-ID: <296b2c56-c688-41a0-a752-b242268691fd@wi3ck.info> Date: Tue, 12 Nov 2024 10:12:40 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Commit Timestamp and LSN Inversion issue To: Andres Freund Cc: Amit Kapila , Tomas Vondra , "Zhijie Hou (Fujitsu)" , Aleksander Alekseev , pgsql-hackers , shveta malik , Jan Wieck References: <9f7f4def-7ea8-4ad3-83e7-a8cc9d18c58a@wi3ck.info> <11ee3489-40ba-45d6-ba6a-7c3def725e84@vondra.me> <00f7cfb2-e3a6-4bd7-b19c-fd75d3838049@wi3ck.info> Content-Language: en-US From: Jan Wieck In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, On 11/12/24 08:55, Andres Freund wrote: > Hi, > > On 2024-11-12 08:51:49 -0500, Jan Wieck wrote: >> On 11/11/24 23:21, Amit Kapila wrote: >> > As the inversion issue can mainly hamper logical replication-based >> > solutions we can do any of this additional work under spinlock only >> > when the current record is a commit record (which the currently >> > proposed patch is already doing) and "wal_level = logical" and also >> > can have another option at the subscription level to enable this new >> > code path. I am not sure what is best but just sharing the ideas here. >> >> It can indeed be reduced to one extra *unlikely* if test only for commit >> records and only when WAL level is "logical". Without those two being true >> there would be zero impact on ReserveXLogInsertLocation(). > > No, the impact would be far larger, because it would make it impractical to > remove this bottleneck by using atomic instructions in > ReserveXLogInsertLocation(). It doesn't make sense to make it harder to > resolve one of the core central bottlenecks in postgres for a niche feature > like this. Sorry, but this is just not a viable path. The current section of code covered by the spinlock performs the following operations: - read CurrBytePos (shmem) - read PrevBytePos (shmem) - store CurrBytePos in PrevBytePos - increment CurrBytePos by size In addition there is ReserveXLogSwitch() that is far more complex and is guarded by the same spinlock because both functions manipulate the same shared memory variables. With that in mind, how viable is the proposal to replace these code sections in both functions with atomic operations? Best Regards, Jan