Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ibdRM-0000EH-89 for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Dec 2019 04:36:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ibdRK-0003LK-Hp for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Dec 2019 04:36:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ibdRI-0003L9-Oy for pgsql-bugs@lists.postgresql.org; Mon, 02 Dec 2019 04:36:02 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ibdRD-0004gw-NA for pgsql-bugs@postgresql.org; Mon, 02 Dec 2019 04:36:00 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 11DB5964; Sun, 1 Dec 2019 23:35:52 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sun, 01 Dec 2019 23:35:52 -0500 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=3lsl9ddRRM6GhHoN7ebkOaGV6DV VP1IiOxjH4EYsuQ8=; b=OGyWm8FHLavYHvEnAJRDnS16JMbay/mAXOst1yJ//r/ AJTo2FWy4aLxPsQCmKa4pXPGmE5VQkBAz9BOCDh+mz7aYQnMnkTYkWVRfqORTpYg gseXI1GOqbcm+/Y1rcIcD1NWjdEqIIgH/sY5UdlkKn/Z+yMTevN8lcy3tJpv/G9K Lc+ZNUZuP4tbaFFFeoFo3QTFm3rxrOeP8oOe+N8R+U5U4rbiE2/X4Fcuo7jVpQ0x MOo19B3i/Trm9DH2kFcZC+OR3pUXi6dMu524EQTz/sZgwf2vBNMTFz+wf4hzaWnb E+JmX/nDUcGKgNBxgFYpUypKUplJwEBDA0ye3iViE+Q== 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=3lsl9d dRRM6GhHoN7ebkOaGV6DVVP1IiOxjH4EYsuQ8=; b=GAZ+BIcAri2a5MzS+iIfAc LYWTm56yGMlF3rjum4N9YWtlYthjpChHtDihbDpz2wQwrLUs9I7GKDE5zNuQeugy JNAX0tllFkafBk8GcBjNiCTWxlmKKZizrZXmYH9BO815JQbS5Nk7sitMTHEUyBCJ GnqqPJcIQxfK+MwB/WprpDOyaJ4JPfDHh4dTTRJHgPml9lcr8jtN9X7q8xICswzS 3dcfT+9vxH1j5oQXWHCwTMVVd4iksGbpaneGGR6mW9cmSR5lff9Wqy9JcTQwCvoe JAk2UrHcm8LW3+4BvuOKrAvfno5/cQqK1OR1Yy3cjghwP4y7GO0Y5+6vD0VWP2WQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudejgedgjeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucfkphepuddukedrvdeguddrvdegkedrudegleenucfrrghr rghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiienucevlh hushhtvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (mp76f1f895.ap.nuro.jp [118.241.248.149]) by mail.messagingengine.com (Postfix) with ESMTPA id DEE538005A; Sun, 1 Dec 2019 23:35:49 -0500 (EST) Date: Mon, 2 Dec 2019 13:35:47 +0900 From: Michael Paquier To: Grigory Smolkin Cc: Pg Bugs Subject: Re: logical replication: could not create file "state.tmp": File exists Message-ID: <20191202043547.GE1696@paquier.xyz> References: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="A9z/3b/E4MkkD+7G" Content-Disposition: inline In-Reply-To: <08bbfab1-a61d-3750-fc18-4ab2c1aa7f09@postgrespro.ru> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --A9z/3b/E4MkkD+7G Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Nov 30, 2019 at 03:09:39PM +0300, Grigory Smolkin wrote: > I`ve digged a bit into this problem, and it`s turned out that in > SaveSlotToPath() temp file for replication slot is opened with 'O_CREAT | > O_EXCL' flags, which makes this routine as not very reentrant. What did you see as I/O problem before facing the actual error reported here? Was it just ENOSPC, a fsync failure, or just a failure in closing the fd? The first pattern is mostly what I guess happened, still a fsync failure would not trigger a PANIC here (actually we really should do that!), but I am raising a different thread about that issue. > Since an exclusive lock is taken before temp file creation, I think it > should be safe to replace O_EXCL with O_TRUNC. > Script to reproduce and patch are attached. Agreed. I prefer the O_TRUNC option because that's less code churn. =20 Also, as it can still be useful to have a look at the temporary state file after a crash or a failure, doing unlink() in the error code paths is no good option IMO. Have others thoughts or objections to share? -- Michael --A9z/3b/E4MkkD+7G Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl3klKMACgkQnvQgOdby QH2wog//UTidu8V4DCBjseT33aq9QzYbONJklaqmNIdsZIe+3j7ctT2qhmBpcbzC DDAVJmAIuU/Ji21Vo3jDVMVDuDEU3e+Wk3qvs3PgKKRQ16zaMTeFj5FqPL9JpXU+ mF/UidKttzihS1o0+ZR/bIJStL6p563Llkz7RBVIBLk9zPAcIC4dTHMPy6/EZfZg odQe2z0qnFGuEj30rXn655IJwZs48TSWRMSmz7pfSK/hyXGBjhYIb7x5dzkKDvCK aqxWWN5xALbY5nSLiKU6qfJw/FRzuOQv1vBYEqI4xAxwGFcHr6kWUzgt5nuobhNY ZDro2jCfvCE04wD/NyP8HAAAtG5LekGGsG9cBubqE+ie3pzgrEZZnQYBvJV8EANT 6TP6zVL3YN/ZYVQ5avX9ehemS0dxNpx96+swBhzthEoRc/9qXWpzNk/57tmNDpNJ lJxW3VVVI35RtBzoWieAZTp06dBf93JEAH2XO+ek9ZD7P8rVZPEOgVqK3XsJn8xR APNn83bQwAOiV0G1pY8ctsMcq2XczSmatu5h+5rIK+pHAElHzcbCHwAhFVbJM8rs MvZBszg6rBVX96U/3eZcapjAHYgckQXucgLaJiomejDNQxK2gWRxdKzx1QN2m78L 1PSg178Qz4OYlCbg5MWChujlSm4PKahC01cwoXCVHAgplaPDV2I= =J11v -----END PGP SIGNATURE----- --A9z/3b/E4MkkD+7G--