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.98.2) (envelope-from ) id 1xE5V4-00000000uSm-07XH for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Oct 2026 13:46:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xE5V2-000000005W6-03P5 for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Oct 2026 13:46: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.98.2) (envelope-from ) id 1xE5V1-000000005Vx-3311 for pgsql-hackers@lists.postgresql.org; Tue, 06 Oct 2026 13:46:31 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1xE5Uz-00000000igT-1fDD for pgsql-hackers@lists.postgresql.org; Tue, 06 Oct 2026 13:46:31 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-48c4649b35bso2976364f8f.3 for ; Tue, 06 Oct 2026 06:46:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791294386; x=1791899186; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=U5eDotDu9Ov8LUJtqgYoEjufnyjPdl2QDjujO8qy6hk=; b=gfRVbsWO/qXVv3AI16L3oHg/LK44nTwnCBMtFO4TAdJRsNMFhFXEIlAJ6Yx5D+Q95Z pP/mCPSAPst1jd9mFZXHHpFoc3NTvNhg5EAOF42QsvIiMY0EY9ziD0EqzFhWqe5MEu8J nMhPPh35RtN41t4m+en+CbYK7f5tcFciBoB7hs9PedK31YPOnyHR7wSIQ2LNmUvXhsdt kr73oTmMYb0UH1/1Sy6oqugW6rdFFIaT/Hw84s3B9nTcUi5pZmG6hMByLPtP0fq23+1G l4wdOAfVW6+J7G6LITyWY9QxheVEBq6D1trXlqkehFDyxlNmQaf4vlWpxhXO5wAnPvbs EoOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791294386; x=1791899186; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=U5eDotDu9Ov8LUJtqgYoEjufnyjPdl2QDjujO8qy6hk=; b=voq8FsZfDPp6bdaoj1QUka6nIBmsJCK07DGodVlz5qZBX11uYLeemkgzMj7g8YlnRK 0SdycmqLVRGl5DFo+9Tf6w80CCio/oPloPbBtYJKO2no139ZjCU6UhYR/4J7qHJEVhHW NKeso5ICVPz0zEC4TC7Wru3/a1dxqIA+aHjLrLVy6qH04yUBnZZJNKXWlDtMFqlwRmEB 4JLVZOotR7M/e57d9Xe+nktpFmMV2HRh2M2JZjylM07/0tHKWgS1tfudFw4BceHyjXmq jwzKiT+BsJBnPGOQQCQ8/SPdep1Mom7CirlCPU9wjb1A8SEylZzrKQ9xQX6Y2De60Qx6 8p1A== X-Forwarded-Encrypted: i=1; AKwUvBxUOJ9O7N7gmIxpuVieGwBKz3jJYFwKOjEnRaPCRwUhIg9AtX9ZythlYrj1x1P7NAb37LGdiIv30ZTfvlPO@lists.postgresql.org X-Gm-Message-State: AFq9FYJQexXDgL2pgYxmDBcpaiRX0IoW2jDaNTnNoXc+zVgOvGd/SQ/m QOSiuhVfEGyVccOHkYdWlME3yQE/DGl9eTKSpDO6QOYJPAbzYd2L1l/D X-Gm-Gg: AYBFou2fMIxIHDS5+eCF/5EY/vJz9kuQdncQZ+FN7YwqBV4TpEP0qR8O7buIeMWUqmk kgBSZQRnKfOVgwoRPt1D/3zbICbhtKH8UGhW8MokFwlgA5MxMfP5rHdMu0E3YXo//LOEXh5qsdk NLYvFZUXAvx7oG3ll4/BLdTW99QkppfIvS0EELgYfAz6AXKuA51pE8umfmLKk10roNJmBpmAcZf dQfXxDdb/+nlCjnC/5KscUI0vGokEDWKOt02WvhiOO5h5A+/IBAaL1NyneCGv4VfybSG1L4JRdG 6G93y0gunKXW6TgHxQ8RmRp50fKfQvZyBMTOJ8ZcTwyZ/Wu1NuOfLRhVFyy/5FLfiW+vplOmrSA t5BJmVo9fvQPVWI7T/YGd2S2rLslBR2KUBqs95fajF5czey/GR4xfBeacVU3XHmeWXv04cu3bBU SSK6/fZg8WFS4XTuAyeDm3p8IqVfFhKAg3npxvyixE0MHbkchRUhDFPUUxAZj8oNJe+bgUqTZbM hYyArFbd4d1u7DciR7cqGEPWNZuEMZNn1U0CxnPGu8dpxicxUVQ2LQvBA== X-Received: by 2002:a05:6000:454b:b0:48c:7142:68b6 with SMTP id ffacd0b85a97d-48c714268famr155003f8f.48.1791294386172; Tue, 06 Oct 2026 06:46:26 -0700 (PDT) Received: from bdtpg (ec2-15-237-197-144.eu-west-3.compute.amazonaws.com. [15.237.197.144]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c62289e77sm10795866f8f.21.2026.10.06.06.46.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 06:46:25 -0700 (PDT) Date: Tue, 6 Oct 2026 13:46:24 +0000 From: Bertrand Drouvot To: Ashutosh Sharma Cc: shveta malik , JoongHyuk Shin , Amit Kapila , Rui Zhao , pgsql-hackers@lists.postgresql.org Subject: Re: Persist slot invalidations before publishing them Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Tue, Oct 06, 2026 at 03:46:24PM +0530, Ashutosh Sharma wrote: > Hi, > > On Mon, Oct 5, 2026 at 6:54 PM Bertrand Drouvot > wrote: > > > > Hi, > > > > On Mon, Oct 05, 2026 at 03:22:53PM +0530, Ashutosh Sharma wrote: > > > Thanks. I'll review again once the updated patch is posted. > > > > Thanks! Here it is. > > Thanks, the attached patch looks good overall. Thanks for looking at it! > I only have a couple of > concerns as of now, feel free to disregard them if you do not think > they are worth addressing. > > 1) Although assertions are useful, some appear redundant across the > three layers of the slot invalidation path: > > - cause != RS_INVAL_NONE is asserted in both > ReplicationSlotPersistInvalidation() and SaveInvalidatedSlotToPath(). > - I/O lock ownership is asserted in those two functions and > conditionally in SaveSlotToPathInternal(). > - The clear_restart_lsn constraint is asserted in both the public and > internal functions. > - cause == RS_INVAL_NONE || elevel >= ERROR is already guaranteed by > the wrapper functions, since SaveInvalidatedSlotToPath() always passes > ERROR. > > I think some of these assertions could be removed, particularly the > following ones: > > static void > SaveInvalidatedSlotToPath(ReplicationSlot *slot, const char *dir, > ReplicationSlotInvalidationCause cause, > bool clear_restart_lsn) > { > Assert(cause != RS_INVAL_NONE); > Assert(LWLockHeldByMeInMode(&slot->io_in_progress_lock, LW_EXCLUSIVE)); I'm inclined to keep them. They check the preconditions at different layers. There are similar caller/callee examples in the tree, for example: SnapBuildSnapDecRefcount() / SnapBuildFreeSnapshot() MemoryContextReset() / MemoryContextResetOnly() MemoryContextDelete() / MemoryContextDeleteOnly() SyncRepWakeQueue() / SyncRepQueueIsOrderedByLSN() In particular, the cause assertion prevents RS_INVAL_NONE from reaching the regular save path and trying to acquire the lock already held by the caller. > > 2) SaveSlotToPathInternal() currently has several conditional branches > distinguishing between the normal-save and invalidation-save paths. It > might be worth considering whether this distinction can be simplified, > making the function easier to follow. I replied to a similar suggestion from Shveta in [1]. > Other than these points, the current patch set looks good to me. I > will spend some more time reviewing it and report back if I find > anything else worth mentioning. Thanks! [1]: https://www.postgresql.org/message-id/asSkN5GOEOKQZs9w%40bdtpg Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com