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 1meQAK-0002Zo-Fc for pgsql-hackers@arkaria.postgresql.org; Sat, 23 Oct 2021 23:11:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1meQAG-0001wj-TU for pgsql-hackers@arkaria.postgresql.org; Sat, 23 Oct 2021 23:11:00 +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 1meQAF-0001nf-AZ for pgsql-hackers@lists.postgresql.org; Sat, 23 Oct 2021 23:11:00 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1meQAB-0008JB-IB for pgsql-hackers@lists.postgresql.org; Sat, 23 Oct 2021 23:10:58 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id CAE3A3200A2E; Sat, 23 Oct 2021 19:10:51 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sat, 23 Oct 2021 19:10:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=jc0oBH7P8qkpMAPbcSDRGcAZJuK RLEoION8GmCAIPb8=; b=A1+3Y1P+OQBypZ068JSsyvZWhJAc50Zdyu8IbuNH8Ql YqtFg0f8bzsZeUvVLeGUuD+93Ze6XjQjYHPJAjcTWp//613yAH6RQrMyTT72vpkz 5RKfWIZwM1LkLP7fdsbA4LtTJ3gatk5xNeUZD+2Nd0fpOallX3hA/abDHqoVtEv4 S34zDHwU4E5V+0bxBeIk5BtuKpcsMF3rVMRApEk1BSd0JXXiW9joEvLzFzrYTkj5 LLaMNtM+tfROchSe2IfAnjCvYeHc59YpHANfHwswiKBDNvj3/wm70SNnhB5dneXy ecZ9EPSsL7Dhu2z6mkZu8WatoCdXOdcHhDztS5PjqzQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=jc0oBH 7P8qkpMAPbcSDRGcAZJuKRLEoION8GmCAIPb8=; b=E4pjmSBrhhtxQ0N0Q/drAp jZxn4PlZM9VxSUapWDpY8x3swiS9D/EqlIWqJUbPFkUGE0v2tC1+JgEfeX1QmbSC ls6DVsiHZsI+luK4d+mlUW6x9S6V7/ePQJ48bgCDs2sJecbYWf6/zmbHU8NsizE1 iyhwCgGwv9MT1SqlgIc4Iwi10xOCByCwvQ/dVnqKOkQi1PHWWwmDjXrLj+wpGiUE bC9M21+NeczK77bR3GRjIqTEHAMhVbR4mF/sfdXK2FnSDsmSjtMM0tuhQ8fSivPE dEb13AUA/AXdpmcdB7qhrj288jz7rgtN6kDYVSVO3oj/0rA7JwuagOr/jNu2VLlQ == X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvdefuddgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpedvgeduuefhtdeuleettdevjeeh heeiveeuieegleetgeeljeelieeuieehgeevhfenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 23 Oct 2021 19:10:49 -0400 (EDT) Date: Sun, 24 Oct 2021 08:10:44 +0900 From: Michael Paquier To: Bharath Rupireddy Cc: Ronan Dunklau , PostgreSQL Hackers , Kyotaro Horiguchi , Masahiko Sawada Subject: Re: pg_receivewal starting position Message-ID: References: <5336539.LvFx2qVVIh@aivenronan> <4126495.44csPzL39Z@aivenronan> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="0YoTBNT/JdY9aH9G" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0YoTBNT/JdY9aH9G Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Oct 23, 2021 at 10:46:30PM +0530, Bharath Rupireddy wrote: > 1) It's better to initialize nulls with false, we can avoid setting > them to true. The instances where the columns are not nulls is going > to be more than the columns with null values, so we could avoid some > of nulls[i] = false; instructions. I don't think that this is an improvement in this case as in the default case we'd return a tuple full of NULL values if the slot does not exist, so the existing code is simpler when we don't look at the slot contents. > 2) As I previously mentioned, we are not copying the slot contents > while holding the spinlock, it's just we are taking the memory address > and releasing the lock, so there is a chance that the memory we are > looking at can become unavailable or stale while we access > slot_contents. So, I suggest we do the memcpy of the *slot to > slot_contents. I'm sure the memcpy ing the entire ReplicationSlot > contents will be costlier, so let's just take the info that we need > (data.database, data.restart_lsn) into local variables while we hold > the spin lock The style of the patch is consistent with what we do in other areas (see pg_get_replication_slots as one example). > + /* Copy slot contents while holding spinlock */ > + SpinLockAcquire(&slot->mutex); > + slot_contents = *slot; And what this does is to copy the contents of the slot into a local area (note that we use a NameData pointing to an area with NAMEDATALEN). Aka if the contents of *slot are changed by whatever reason (this cannot change as of the LWLock acquired), what we have saved is unchanged as of this command's context. > 3) The data that the new command returns to the client can actually > become stale while it is captured and in transit to the client as we > release the spinlock and other backends can drop or alter the info. > So, it's better we talk about this in the documentation of the new > command and also in the comments saying "clients will have to deal > with it." The same can be said with IDENTIFY_SYSTEM when the flushed location becomes irrelevant. I am not sure that this has any need to apply here. We could add that this is useful to get a streaming start position though. > 4) How about we be more descriptive about the error added? This will > help identify for which replication slot the command has failed from > tons of server logs which really help in debugging and analysis. > I suggest we have this: > errmsg("cannot use \"%s\" command with logical replication slot > \"%s\"", "READ_REPLICATION_SLOT", cmd->slotname); > instead of just a plain, non-informative, generic message: > errmsg("cannot use \"%s\" with logical replication slots", Yeah. I don't mind adding the slot name in this string. -- Michael --0YoTBNT/JdY9aH9G Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmF0lnQACgkQnvQgOdby QH1bjg/+PzrV40um2sX9U02C5sqvxJb8Vg3NgiOz+y7sNhqBN+YESaERSeOvcSMB tox8oDh9SqE3wukWKJk/0T0mx9SABKfPyID/dL7+RmKoOXuPS3PCkx7vZIiFIj0Y jgsn3lGPljrvWUFULKIiQ4RcvHhG1/DJVXmeLDLmP4ZkmXs8Y99KSYuF/zRqK2bj gOLUa1Is2pbvq5L8X3pgSmZLBBht76A61KE9swyzahTQDZ5Zln/PoaCdihyjDZAP 06V2V0/kXT3Bukr/yOgx3tbpQCuW9pX+QhnNmf04rGUXkYyXzY3IBSSAFSV9gHoX L4dq1074pZrSBtQMkjNk6gxuD8Fgxoe2CTvlgXSOgAPnn5QK81dMNwmg5wOKLa98 FXcPXHL0kli0yfzp43CukNz3lbIkG/g2iRDtQ4m2fFgCQnQwMqZbucue6jXFx2R8 7VEYprIDb6MMosc1eKlXzTEI3bFpkrQW/bwUAnD0aEWE4afkX7OM7fkQTU990Xq/ pW9HEuYVT/eMlrHs8TrokyDv6F6rrtABdt9ZmwPKwY18stoD6sKUre9sZAjDkheU 14kI8ewD48Z4t1NPqjAbenf3pzeqvV1F3JE59LC85+9UX5CXJJQ8LS9KQzU/t5lB bAKw4fCN8XEssCJkLjAqHGUHLq195lCj/uhwuSj1Nt6ClkcLSVw= =4inJ -----END PGP SIGNATURE----- --0YoTBNT/JdY9aH9G--