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 1gh84H-0002ZU-Uu for pgsql-bugs@arkaria.postgresql.org; Wed, 09 Jan 2019 07:14:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gh84G-0001iP-9u for pgsql-bugs@arkaria.postgresql.org; Wed, 09 Jan 2019 07:14:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gh84E-0001iH-5H for pgsql-bugs@lists.postgresql.org; Wed, 09 Jan 2019 07:14:24 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gh849-0000QT-Sv for pgsql-bugs@lists.postgresql.org; Wed, 09 Jan 2019 07:14:20 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D727325416; Wed, 9 Jan 2019 02:14:16 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 09 Jan 2019 02:14:16 -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=IrMLemC5GGI/zSMjfSdPOaROMqW KXYuN92tHeT+QTcA=; b=jdOS3y+r3UBZkQO3l5JdO1fq0iQgE+zbgYqdxRdLfK2 2DzeofFW1IoYhiT1sl+keAhYgBqC3PcDzU+yDCI4+7TjbwgJyPObQeFAtGxdQHAu 8YHGDRzEzXdS666AH9Mn0oeu08VVdpmoMXxujjADtUJbpIJz+dlehMTnQx9bb6gw Vp6iCcMkS2U0AM7E6F8HbxcZjgv6Taz6F3v4X1QwNdha1R1WtE37phwPViALIWj7 dKhqtE5Y3MmTzuH927sFPTJTpWhuH3I2EFl4ol9BpHp/W8ZW2EjJe3Q6v9GArzEm JBPMCBEDLPdhEM5y1x+GeeKM3ltlztIqihyOB2FITng== 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=IrMLem C5GGI/zSMjfSdPOaROMqWKXYuN92tHeT+QTcA=; b=uyn+YFGJ63KtgEWi/U9/tn 5tVL6KH7yB+MgW1HRiV1Ea1SMwvYnPxZmdSWUoTXcVJZ2dfWHohbbbkFPiCZ/2JA r9RGHcYB+XCskMpSK+M/LKKz0E2eKBxy5NwFSCWApB+NTdBd1NZxeApRcfJD5klq sb2yBvBnWh0T+AAObFnSmVFFqNJEWpsyoD5/yaxdaRa4Vt3JFoPcWW/s2hIg9KAV NC9muJ5h1HrwQb/DGiHyEm14W83GK7HHwG3G94sWZ1sNGS2TrviXXVCLceMDqYm0 xfRDg8LVA1xXHy1+DUZFpX+tIwESt+6Nfb40DQoPeyM2qE4sGiJ4FS5A7qJjDP7w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrfedtgddutdekucdltddurdegtdekrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhht necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhepff fhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghq uhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecukfhppeeiuddrvd duhedrudefjedrudeivdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhes phgrqhhuihgvrhdrgiihiienucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (c137162.net61215.cablenet.ne.jp [61.215.137.162]) by mail.messagingengine.com (Postfix) with ESMTPA id D4F84100BA; Wed, 9 Jan 2019 02:14:13 -0500 (EST) Date: Wed, 9 Jan 2019 16:14:11 +0900 From: Michael Paquier To: "lichuancheng@highgo.com" Cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #15567: Wal receiver process restart failed when a damaged wal record arrived at standby. Message-ID: <20190109071411.GA23045@paquier.xyz> References: <15567-a9ff747c5e7c031c@postgresql.org> <2018122913081786371813@highgo.com> <2019010317504815140834@highgo.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="SUOF0GtieIMvvwua" Content-Disposition: inline In-Reply-To: <2019010317504815140834@highgo.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --SUOF0GtieIMvvwua Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jan 03, 2019 at 05:50:48PM +0800, lichuancheng@highgo.com wrote: >> I read the code about startup process and walreciver process. >> When a damaged wal record arrived: >> 1.The startup process shutdown the walreciver process use function Shutd= ownWalRcv(). >> 2.The startup process start the walreciver process use funtion RequestXL= ogStreaming() by signal PMSIGNAL_START_WALRECEIVER. >> 3.The startup process try to read wal record.=20 >> And now reciver process does not startup completely,so the startup proc= ess read the damaged wal record another times. >> And startup process set walrcv->walRcvState =3D WALRCV_STOPPED use func= tion ShutdownWalRcv(). >> 4.go to 2. >> That's the infinite cycle. >=20 > And now i do a patch in mail attachment to solve the bug. =20 > I test it on pg10.5 and work well. So the take of the patch is to make sure that the WAL receiver has been correctly started if the startup process requested one before trying to replay more WAL records. Now it seems to me that you do not close all the gaps here. The WAL receiver could finish starting, but still not have the time to stream up to the point where the startup process could consume things safely. The patch makes somewhat sure that the gap is closed by applying a timeout of 1s, still in environments with more latency it would make the failure still happen. Wouldn't it be better instead to make sure that the startup process does not try to use once again the same record where the failure happened before the WAL receiver confirms that it has flushed something newer than the LSN position which was known as bad? One problem may be that upon restart we reset receivedUpto, and that visibly we may want to be more careful with its handling to avoid successive failures so as the startup process does not bump repeatitively into the same bogus record. Looking at the code, the computation looks quite safe though (I need to double-check to be 100% sure), so isn't the origin of the problem just that the WAL segment =66rom the primary is corrupted, and that what gets streamed is broken at its origin point, preventing the standby to move on? You may want to double-check that as well.. As a side note, the patch is incorrect for a couple of things though: 1) Formatting of comments and indentation. 2) Please be careful of whitespaces. 3) Usually no more than 72-80 characters per line. 4) Why a wait phase of 1s? 5) And much worse, the WAL receiver status cannot be looked at without taking its mutex lock first, so this makes the logic look at something which may be concurrently updated. Oops. 6) Still the patch is incorrect per the reasons above ;) -- Michael --SUOF0GtieIMvvwua Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlw1n0IACgkQnvQgOdby QH3qeA//e4r8v/JhWlQ3vLKxqifH9JBZMihIiklBYH8bLFrx3/IxQW/F5ZHOQTV/ 2Umaa4Lj44VxIVox0V7YiFLqngv9pab3/+qGIOXztMAMEm6+KseDrYFs6kkDscGw JPawayOA/KWCjWyIjeVEj5XwOgFnWu+l+NR0fbkr3W7MbTQ4/OIPWTmJJtcgJCuC XlICuoskPGq0MJFEvMFwTimXQWljMmE+NYgJqfPuvZceSXliAKjOuFpvAWOoXe3y vhigKigbAFZh2m7aaMHjdzHYlg+p/T4k8X+7/4xHgExAADET/V0TrzahzZRe4mUc 8k60aQaGTcHedu6hXg/k6+OEjNtVu9x53gSQ1EIuXAUWB+ABSa7c8cP1lUmYqx2p 1tuIyiD6oZUEV4PrmImHKbBbGakwsMkGFTPbjmS5qube005AxvwGCs7nHraFUMME TyslFsSCDtc6tteJ9jQbeau0ReytBvRu+nYn+nZCWAOVsUodX0Lv/XxW2pnh0QGN zXlMCoL/mfe+lEWwnLeiqsBSR7xHjSI1xA7QR6oYCEWRkmjGZSCB0hWuEShpYeaK 4TB/WvhhWMX9ObMfro1Txiybz0xjUyklOKNTuqH3FqULSDn4inZZY7+1T3NKRVdL mxYiR4rK5ElrKRmKaSUnAYng7hr/Yypp2JoDSZ11CrBhzPlz7D0= =SspJ -----END PGP SIGNATURE----- --SUOF0GtieIMvvwua--