Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlcQZ-0000pC-8Z for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jun 2020 18:04:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jlcQY-0005yX-3t for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jun 2020 18:04:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlcQX-0005yQ-OM for pgsql-hackers@lists.postgresql.org; Wed, 17 Jun 2020 18:04:45 +0000 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jlcQU-0004qO-Lr for pgsql-hackers@lists.postgresql.org; Wed, 17 Jun 2020 18:04:45 +0000 Received: by mail-qk1-x743.google.com with SMTP id q2so2964145qkb.2 for ; Wed, 17 Jun 2020 11:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=Ft4L1OXe8t/AepNqFEbgFsu29oVpzfXf90o8ruJxpOo=; b=FaVY5UOToyhI7/bohltNngGqCojGRaMR1pfWL57zGO5Atlp+l4DX+S1a0nKMsAVmHA q3C++bIBX21a/p/LYfCeq70ykOAjO5BziGxoEyWo2/dKfS/4FRf9LHpt3q3as6kwfvrY eXZdxerVqFkfmnC1j57a7fCSHUdCmQv6k3Ev1NZ/1arohAga9Im+zTUlJtJqsj6IcfZJ 0PeVO+CTctUJ6S2PeHV52hU12zt8hxjiVwsYFpiIx4GRY23Z+b8lxsfocWKFI4RzadA9 ap5Dqyl4lcxiuWHXlimkeZc6hktYsnmM5phQ9bHgUw8KjNYhcCpnKiLk+DPqt3CevO3i O0mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Ft4L1OXe8t/AepNqFEbgFsu29oVpzfXf90o8ruJxpOo=; b=c1H/3niB3tvL8lFFHGC+LzHVcwCt4jG4ybdcLnkY39FvHJrOuV3jjZjA3WAFdfcFP7 Vlav8otJc9WJn95gyXQ2UYNG6NiaKf9OryTNGujuWHC6rOuA2VihSB7FGAmXiXntOEZB xdmrxNRK/RsgSuYeXhQPodame+7XQpQQA0L0aTUKb5VqDGZs7kLq4pNTevABdfK80EDX dgl8ZFZpbMPTcXbaTGYmJcak4e9jQNA49UWquLydgsoAA99MV70W+hdQZlj8rYVMgjx4 v2CZrTmbeRDpMG2X8n99+Kbi5VrVyNdXlqvELjyB9/0ltHnZcVOak17Lu7gTbRcfI+/9 49Ng== X-Gm-Message-State: AOAM533XmQ3DVvNt1lm7wBdl46mJ0SWvK05LnhJnlho2bhhrsvDshrXY 6oNhHZF3XcVc3i02T7RQgQgAHw== X-Google-Smtp-Source: ABdhPJyyF6zqcbaGtYPYfg9BJyFChl2pNakRiVNQ4IOlAKh11jU7AUnB6q2sfe03FuxfsOQQdNGIEA== X-Received: by 2002:a37:6513:: with SMTP id z19mr27751057qkb.234.1592417080830; Wed, 17 Jun 2020 11:04:40 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id k17sm628946qtb.5.2020.06.17.11.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2020 11:04:39 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id B3BA52A3AD3; Wed, 17 Jun 2020 14:04:37 -0400 (-04) Date: Wed, 17 Jun 2020 14:04:37 -0400 From: Alvaro Herrera To: Fujii Masao Cc: Kyotaro Horiguchi , pgsql-hackers@lists.postgresql.org Subject: Re: Review for GetWALAvailability() Message-ID: <20200617180437.GA1812@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="r5Pyd7+fXNt84Ff3" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --r5Pyd7+fXNt84Ff3 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit I think passing the slot name when the slot is also passed is useless and wasteful; it'd be better to pass NULL for the name and ignore the strcmp() in that case -- in fact I suggest to forbid passing both name and slot. (Any failure there would risk raising an error during checkpoint, which is undesirable.) So I propose the following tweaks to your patch, and otherwise +1. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --r5Pyd7+fXNt84Ff3 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="tweak.patch" diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index b94e11a8e7..d99d0e9b42 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -383,24 +383,25 @@ ReplicationSlotAcquireInternal(ReplicationSlot *slot, const char *name, ReplicationSlot *s; int active_pid; + AssertArg((slot == NULL) ^ (name == NULL)); + retry: Assert(MyReplicationSlot == NULL); LWLockAcquire(ReplicationSlotControlLock, LW_SHARED); /* - * Search for the slot with the specified name if the slot to - * acquire is not given. If the slot is not found, we either - * return -1 or error out. + * Search for the slot with the specified name if the slot to acquire is + * not given. If the slot is not found, we either return -1 or error out. */ - s = (slot == NULL) ? SearchNamedReplicationSlot(name) : slot; - if (s == NULL || !s->in_use || strcmp(name, NameStr(s->data.name)) != 0) + s = slot ? slot : SearchNamedReplicationSlot(name); + if (s == NULL || !s->in_use || + (name && strcmp(name, NameStr(s->data.name)) != 0)) { + LWLockRelease(ReplicationSlotControlLock); + if (behavior == SAB_Inquire) - { - LWLockRelease(ReplicationSlotControlLock); return -1; - } ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("replication slot \"%s\" does not exist", name))); @@ -1161,8 +1162,7 @@ restart: * we have to wait on that CV for the process owning * the slot to be terminated, later. */ - wspid = ReplicationSlotAcquireInternal(s, NameStr(slotname), - SAB_Inquire); + wspid = ReplicationSlotAcquireInternal(s, NULL, SAB_Inquire); /* * Exit the loop if we successfully acquired the slot or --r5Pyd7+fXNt84Ff3--