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 1rnc6h-00E9Za-QS for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 10:26:40 +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 1rnc6g-002Eik-BF for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 10:26:38 +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 1rnc6f-002Eib-Vw for pgsql-hackers@lists.postgresql.org; Fri, 22 Mar 2024 10:26:38 +0000 Received: from mail-oa1-x33.google.com ([2001:4860:4864:20::33]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rnc6c-005pWH-MY for pgsql-hackers@lists.postgresql.org; Fri, 22 Mar 2024 10:26:37 +0000 Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-221a4f9557dso1158944fac.2 for ; Fri, 22 Mar 2024 03:26:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711103195; x=1711707995; darn=lists.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=8eDCBNnZ3ltkfnTqXNgl1C0kQEBFCo2pesRUugFKo2s=; b=AZWxrIaOi+q+1nOn5GKzPjdWduXj2ETnwvNlTTb4kYxgM3jEvPFCAuU3rDhDn8qO6g MYiMzhYl/54z7NkTf8ehmv9oXbDKhxmAsIECRcdv7QsicdYBf7JXBWjhkcZrWwXLYDyJ RbGsiZvWPe4CE4/sBpCFv3H+rSEIuR9WE/gzeaLyV/hewt/z8BgHgerXy/89cpPZMXfD zA6OXMIca3gutW60OZRQUZrZycvJnHP0W3DyudHXDYXxmSgoh4vNJ2iOrlzEbRSjpgKF RM59GFctSbKDAMI1c2ebTuVWdyoZXOAGx2xE1WaBVfZMJIM0UoxG9uIYlIHzOienBfgS WwZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711103195; x=1711707995; 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=8eDCBNnZ3ltkfnTqXNgl1C0kQEBFCo2pesRUugFKo2s=; b=O3IM8yJQoGZ3zG8uhtrJVHRqfloNQptE8FklIeENxPM5vXo38XsCJshk3GOvVLBP+l z/MF450X/bUyU6x2LMwjBaiDKdV8DndNop3461/U3RmQIiCOOeLUYh1sAactNOck/n0j +BrtJGD/HodXOL5yXE4a5hBhTwu1FW2H7tye/PnEMsKSVmLZFMECd0t8CcUiDlJnsfBe 7DMfiHa7kxCgf5BFNYAjnECVty7ulis3wVrNm0VpNilvHFOBlIHRju7MUMfGBTWl+0j7 crMafltraD1fIqFRTEgpTB5X3LXzOkvrsRovPcdmRwJbeU924tCWeR+jxsz6ISdnZ6+z VOwA== X-Forwarded-Encrypted: i=1; AJvYcCV3c/ew7cYGGE1PzJyEn5UBzsmbSfVhyE/50OjsxdppgNMidXAfgZz1cj8XAKdZkxl1YNDkHzMjqjqMo5qomnatEf2XDHW3AvLNNQeM9mDS3kBj X-Gm-Message-State: AOJu0YyZpsNiDDGBN6Gnj7tz0qqKPKyJ9dxgIU+d1K/xG312qe1zy4W7 wvT2RMDLTcUKcr7jmKjW8cAG28ZOfcc6ADF+zMhFaTcayVck5PqfBmTkCC4jLdraeKIaSkksSHj W0b7jxah7ZPuEWOKuAoRqrEszHGw= X-Google-Smtp-Source: AGHT+IHApQHXHRbjM9TJ7sIcWWw9/4VkeHtCpae6+RSv30tu52lqdOFkRsZnD9byl6keyWDXyGzNGBKwWBn2npUNncU= X-Received: by 2002:a05:6870:a696:b0:229:f814:ff20 with SMTP id i22-20020a056870a69600b00229f814ff20mr58218oam.53.1711103195005; Fri, 22 Mar 2024 03:26:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Amit Kapila Date: Fri, 22 Mar 2024 15:56:23 +0530 Message-ID: Subject: Re: Introduce XID age and inactive timeout based replication slot invalidation To: Bertrand Drouvot Cc: Bharath Rupireddy , Nathan Bossart , PostgreSQL Hackers 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, Mar 22, 2024 at 3:15=E2=80=AFPM Bertrand Drouvot wrote: > > On Fri, Mar 22, 2024 at 01:45:01PM +0530, Bharath Rupireddy wrote: > > 1 =3D=3D=3D > > @@ -691,6 +699,13 @@ ReplicationSlotRelease(void) > ConditionVariableBroadcast(&slot->active_cv); > } > > + if (slot->data.persistency =3D=3D RS_PERSISTENT) > + { > + SpinLockAcquire(&slot->mutex); > + slot->last_inactive_at =3D GetCurrentTimestamp(); > + SpinLockRelease(&slot->mutex); > + } > > I'm not sure we should do system calls while we're holding a spinlock. > Assign a variable before? > > 2 =3D=3D=3D > > Also, what about moving this here? > > " > if (slot->data.persistency =3D=3D RS_PERSISTENT) > { > /* > * Mark persistent slot inactive. We're not freeing it, just > * disconnecting, but wake up others that may be waiting for it. > */ > SpinLockAcquire(&slot->mutex); > slot->active_pid =3D 0; > SpinLockRelease(&slot->mutex); > ConditionVariableBroadcast(&slot->active_cv); > } > " > > That would avoid testing twice "slot->data.persistency =3D=3D RS_PERSISTE= NT". > That sounds like a good idea. Also, don't we need to consider physical slots where we don't reserve WAL during slot creation? I don't think there is a need to set inactive_at for such slots. If we agree, probably checking restart_lsn should suffice the need to know whether the WAL is reserved or not. > > 5 =3D=3D=3D > > Most of the fields that reflect a time (not duration) in the system views= are > xxxx_time, so I'm wondering if instead of "last_inactive_at" we should us= e > something like "last_inactive_time"? > How about naming it as last_active_time? This will indicate the time at which the slot was last active. --=20 With Regards, Amit Kapila.