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 1t3zFN-00FlEA-Ul for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Oct 2024 14:55:33 +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 1t3zFM-00487d-8b for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Oct 2024 14:55:32 +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 1t3zFL-00487V-Uo for pgsql-hackers@lists.postgresql.org; Thu, 24 Oct 2024 14:55:32 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t3zFI-002kbW-SX for pgsql-hackers@postgresql.org; Thu, 24 Oct 2024 14:55:31 +0000 Received: from [192.168.11.5] (p3718202-ipxg13301funabasi.chiba.ocn.ne.jp [114.166.227.202]) by oss.nttdata.com (Postfix) with ESMTPSA id B0D7161B7C; Thu, 24 Oct 2024 23:55:22 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at oss.nttdata.com Message-ID: <88bed945-d8e3-4a28-ba9d-9eb3edde2d17@oss.nttdata.com> Date: Thu, 24 Oct 2024 23:55:22 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Fix for consume_xids advancing XIDs incorrectly To: Masahiko Sawada Cc: Yushi Ogiwara , Pgsql Hackers References: <2a62f138c9dcb6fcf5889b076d123aa2@oss.nttdata.com> <50ee82a96ac0935de88f9a5ef021f04d@oss.nttdata.com> <57b588db6017ba20e67980fefa388b86@oss.nttdata.com> Content-Language: en-US From: Fujii Masao 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 On 2024/10/24 5:23, Masahiko Sawada wrote: >> if (xids_left > 2000 && >> consumed - last_reported_at < REPORT_INTERVAL && >> MyProc->subxidStatus.overflowed) >> { >> int64 consumed_by_shortcut = consume_xids_shortcut(); >> >> if (consumed_by_shortcut > 0) >> { >> consumed += consumed_by_shortcut; >> continue; >> } >> } >> >> By the way, this isn't directly related to the proposed patch, but while reading >> the xid_wraparound code, I noticed that consume_xids_common() could potentially >> return an unexpected XID if consume_xids_shortcut() returns a value greater >> than 2000. Based on the current logic, consume_xids_common() should always return >> a value less than 2000, so the issue I'm concerned about shouldn't occur. > > Good point. Yes, the function doesn't return a value greater than 2000 > as long as we do "distance = Min(distance, COMMIT_TS_XACTS_PER_PAGE - > rem);". But it's true with <= 16KB block sizes. > >> Still, >> would it be worth adding an assertion to ensure that consume_xids_common() never >> returns a value greater than 2000? > > While adding an assertion makes sense to me, another idea is to set > last_xid even in the shortcut path. That way, it works even with 32KB > block size. Agreed on making xid_wraparound compatible with a 32k block size. As you pointed out, with 32k blocks, XidSkip() can return values greater than 2000. So, the first step is to adjust the following if-condition by increasing "2000" to a higher value. Since XidSkip() can return up to 3276 (based on COMMIT_TS_XACTS_PER_PAGE (BLCKSZ / 10) with 32k blocks), we could, for instance, update "2000" to "4000." if (xids_left > 2000 && consumed - last_reported_at < REPORT_INTERVAL && MyProc->subxidStatus.overflowed) To ensure lastxid is set even in the shortcut case, what about modifying XidSkip() so it returns "distance - 1" instead of "distance"? This change would make consume_xids_common() run at least one more loop cycle, triggering GetNewTransactionId() and setting lastxid correctly. consumed = XidSkip(nextXid); if (consumed > 0) TransamVariables->nextXid.value += (uint64) consumed; BTW, the code snippet above in consume_xids_shortcut() could potentially set the next XID to a value below FirstNormalTransactionId? If yes, we should account for FirstNormalFullTransactionId when increasing the next XID, similar to how FullTransactionIdAdvance() handles it. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION