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 1rseF4-008Lqf-FP for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Apr 2024 07:44:07 +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 1rseF3-006bZd-6Y for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Apr 2024 07:44:05 +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 1rseF2-006bZ7-T8 for pgsql-hackers@lists.postgresql.org; Fri, 05 Apr 2024 07:44:04 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rseF0-000kWZ-0L for pgsql-hackers@lists.postgresql.org; Fri, 05 Apr 2024 07:44:04 +0000 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-516c547fb4eso2558070e87.0 for ; Fri, 05 Apr 2024 00:44:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712303041; x=1712907841; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=nZiaV6qvroX1EHNy0+3d7M8q3FEKsiwlG2TLRVWczJk=; b=XfS7e0EU5vPUnltCDnCaDFMDN2NVPNArWMWXqvjtVPhCNY4TwU+x4JYjRZtdMhSvFS 0OkPfsWr9wE9j0T5rd6ubVnoJsiphOqBvo/3bqTK3CjbvhgIPidRjBYHICULoIJ1qKKS /cjFGpcb1xS/YYJFbp3oYnRl9ZJjxuugt8JqDGpNYqzKDCPLlRtM8bDxltPF/hjxm3HN A4lakYw/S6Dvg4IdGmZSgn5aXPS8pwgsVWMGKQsrClshlApEAidSjFQpnk2aEanFcgHK s+o7HmucsZQradoKKFzoBjFBLd1lJtBjOIzQTUahCXoNiX/tqCuNLfIKIU5sfcfH0D0u fKog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712303041; x=1712907841; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nZiaV6qvroX1EHNy0+3d7M8q3FEKsiwlG2TLRVWczJk=; b=TbWMr6KLJQ/wzpMLIV94130pT7xjSZG1eTG+lzBjGiw0moIbTbDbJgXns0slSL3rC0 YFxYS0F6SeNUDUIZEeGpDYR4S0Sam75082rEjarHm16qy2W6hk/EE9iJnSau+bb0XFNY PboPQLvaBPfGrUgiiuuVjJYU/iGFV0NuIEbpWuopwWba6MYYl6rvNLrbvs/IyjKO4LK2 mUM+927wHsFRczcYvex7YM4pIsWkyXvHzkYtXRst0NU0Txr6YhiemyMg+2YxLqYGMY83 9cCohYeUhlmJl+u1meeVtcOcYZU42HlSeDq8fwo0eqHHNQ40VYpLhPq9FFQ194CuvfhD GuvQ== X-Forwarded-Encrypted: i=1; AJvYcCVZJOjXRWKteooTXZ1wzucmLjlhn1jPS3t+5tRHAigaZsFs2aJjZacccr8uMbg7GGvLa6rMAvisbgjyqUshJsLYFBKmaLvV35ySPrSv3NKLbLD1 X-Gm-Message-State: AOJu0YzzSn5jr3v+M9Dpm+IBvcxByMSA1xlQtZwwDAGYktg0om5+zT1C WfX+LgLtN48IrCxD6r3pdwomjeYrapftczB3Q+tduflIjRwAXwW/WQ5KDHUp X-Google-Smtp-Source: AGHT+IEDGrIwcgrTFjXBA5OGFpRC6UJ4Bbufg1MpS2H6BcdJiLtEr2aPm7O7dBdQa6iBLWn1KwQu1A== X-Received: by 2002:a05:651c:211a:b0:2d6:edfd:2bbd with SMTP id a26-20020a05651c211a00b002d6edfd2bbdmr709763ljq.51.1712303040619; Fri, 05 Apr 2024 00:44:00 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id y10-20020a1c4b0a000000b004162061c704sm5284784wma.29.2024.04.05.00.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 00:44:00 -0700 (PDT) Date: Fri, 5 Apr 2024 07:43:58 +0000 From: Bertrand Drouvot To: Bharath Rupireddy Cc: shveta malik , Masahiko Sawada , Amit Kapila , Nathan Bossart , PostgreSQL Hackers Subject: Re: Introduce XID age and inactive timeout based replication slot invalidation 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 Fri, Apr 05, 2024 at 11:21:43AM +0530, Bharath Rupireddy wrote: > On Wed, Apr 3, 2024 at 9:57 PM Bertrand Drouvot > wrote: > Please find the attached v36 patch. Thanks! A few comments: 1 === + + The timeout is measured from the time since the slot has become + inactive (known from its + inactive_since value) until it gets + used (i.e., its active is set to true). + That's right except when it's invalidated during the checkpoint (as the slot is not acquired in CheckPointReplicationSlots()). So, what about adding: "or a checkpoint occurs"? That would also explain that the invalidation could occur during checkpoint. 2 === + /* If the slot has been invalidated, recalculate the resource limits */ + if (invalidated) + { /If the slot/If a slot/? 3 === + * NB - this function also runs as part of checkpoint, so avoid raising errors s/NB - this/NB: This function/? (that looks more consistent with other comments in the code) 4 === + * Note that having a new function for RS_INVAL_INACTIVE_TIMEOUT cause instead I understand it's "the RS_INVAL_INACTIVE_TIMEOUT cause" but reading "cause instead" looks weird to me. Maybe it would make sense to reword this a bit. 5 === + * considered not active as they don't actually perform logical decoding. Not sure that's 100% accurate as we switched in fast forward logical in 2ec005b4e2. "as they perform only fast forward logical decoding (or not at all)", maybe? 6 === + if (RecoveryInProgress() && slot->data.synced) + return false; + + if (replication_slot_inactive_timeout == 0) + return false; What about just using one if? It's more a matter of taste but it also probably reduces the object file size a bit for non optimized build. 7 === + /* + * Do not invalidate the slots which are currently being synced from + * the primary to the standby. + */ + if (RecoveryInProgress() && slot->data.synced) + return false; I think we don't need this check as the exact same one is done just before. 8 === +sub check_for_slot_invalidation_in_server_log +{ + my ($node, $slot_name, $offset) = @_; + my $invalidated = 0; + + for (my $i = 0; $i < 10 * $PostgreSQL::Test::Utils::timeout_default; $i++) + { + $node->safe_psql('postgres', "CHECKPOINT"); Wouldn't be better to wait for the replication_slot_inactive_timeout time before instead of triggering all those checkpoints? (it could be passed as an extra arg to wait_for_slot_invalidation()). 9 === # Synced slot mustn't get invalidated on the standby, it must sync invalidation # from the primary. So, we must not see the slot's invalidation message in server # log. ok( !$standby1->log_contains( "invalidating obsolete replication slot \"lsub1_sync_slot\"", $standby1_logstart), 'check that syned slot has not been invalidated on the standby'); Would that make sense to trigger a checkpoint on the standby before this test? I mean I think that without a checkpoint on the standby we should not see the invalidation in the log anyway. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com