Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dflVo-0000zw-Un for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Aug 2017 11:20:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dflVo-0004T3-8C for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Aug 2017 11:20:24 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dflVm-0004Rm-UF for pgsql-hackers@postgresql.org; Thu, 10 Aug 2017 11:20:22 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dflVj-00052C-4Y for pgsql-hackers@postgresql.org; Thu, 10 Aug 2017 11:20:22 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id C321C21C1D14; Thu, 10 Aug 2017 14:20:17 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from mail.postgrespro.ru (unknown [192.168.27.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 92DE221C175E; Thu, 10 Aug 2017 14:20:17 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1502364017; bh=2tWSo74/90sm9KZyLlFFN9EoNuBXlHHHGnbcPbt4BgE=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=IM5NHQuf3DALaqzlsf9FX6SdfRNS/rGP7AhQaPVSxvCxHaMslJZlvah63ODV5y2Sz i2l1zT30EOBO0vCSIPn/zTyt1hI5tc61z8M8lWkTC2bsxVXlOGj0ergcb9C0yLUV0h qE2OtyYzRQfoLk0HZm8WWHnatvu1XkZJGT4rZhU8= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 10 Aug 2017 14:20:17 +0300 From: Sokolov Yura To: Petr Jelinek Cc: pgsql-hackers@postgresql.org, craig@2ndquadrant.com Subject: Re: Walsender timeouts and large transactions Organization: Postgres Professional In-Reply-To: <6259a2a9-e683-c3a6-2da8-249b862d8099@2ndquadrant.com> References: <20170802173558.1342.32988.pgcf@coridan.postgresql.org> <6259a2a9-e683-c3a6-2da8-249b862d8099@2ndquadrant.com> Message-ID: X-Sender: funny.falcon@postgrespro.ru User-Agent: Roundcube Webmail/1.2.4 List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2017-08-09 16:23, Petr Jelinek wrote: > On 02/08/17 19:35, Yura Sokolov wrote: >> The following review has been posted through the commitfest >> application: >> make installcheck-world: tested, passed >> Implements feature: not tested >> Spec compliant: not tested >> Documentation: not tested >> >> There is no check for (last_reply_timestamp <= 0 || wal_sender_timeout >> <= 0) as in other places >> (in WalSndKeepaliveIfNecessary for example). >> >> I don't think moving update of 'now' down to end of loop body is >> correct: >> there are calls to ProcessConfigFile with SyncRepInitConfig, >> ProcessRepliesIfAny that can >> last non-negligible time. It could lead to over sleeping due to larger >> computed sleeptime. >> Though I could be mistaken. >> >> I'm not sure about moving `if (!pg_is_send_pending())` in a body loop >> after WalSndKeepaliveIfNecessary. >> Is it necessary? But it looks harmless at least. >> > > We also need to do actual timeout handing so that the timeout is not > deferred to the end of the transaction (Which is why I moved `if > (!pg_is_send_pending())` under WalSndCheckTimeOut() and > WalSndKeepaliveIfNecessary() calls). > If standby really stalled, then it will not read from socket, and then `pg_is_sendpending` eventually will return false, and timeout will be checked. If standby doesn't stall, then `last_reply_timestamp` will be updated in `ProcessRepliesIfAny`, and so timeout will not be triggered. Do I understand correctly, or I missed something? >> Could patch be reduced to check after first `if >> (!pg_is_sendpending())` ? like: >> >> if (!pq_is_send_pending()) >> - return; >> + { >> + if (last_reply_timestamp <= 0 || wal_sender_timeout <= 0) >> + { >> + CHECK_FOR_INTERRUPTS(); >> + return; >> + } >> + if (now <= TimestampTzPlusMilliseconds(last_reply_timestamp, >> wal_sender_timeout / 2)) >> + return; >> + } >> >> If not, what problem prevents? > > We should do CHECK_FOR_INTERRUPTS() independently of pq_is_send_pending > so that it's possible to stop walsender while it's processing large > transaction. In this case CHECK_FOR_INTERRUPTS will be called after wal_sender_timeout/2. (This diff is for first appearance of `pq_is_send_pending` in a function). If it should be called more often, then patch could be simplier: if (!pq_is_send_pending()) - return; + { + CHECK_FOR_INTERRUPTS(); + if (last_reply_timestamp <= 0 || wal_sender_timeout <= 0 || + now <= TimestampTzPlusMilliseconds(last_reply_timestamp, wal_sender_timeout / 2)) + return; + } (Still, I could be mistaken, it is just suggestion). Is it hard to add test for case this patch fixes? With regards, -- Sokolov Yura aka funny_falcon Postgres Professional: https://postgrespro.ru The Russian Postgres Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers