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 1jPK9p-0001se-Dx for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Apr 2020 06:07:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jPK0z-0000f1-DQ for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Apr 2020 05:58:13 +0000 Received: from makus.postgresql.org ([72.32.157.229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPK0z-0000Yt-6U for pgsql-hackers@lists.postgresql.org; Fri, 17 Apr 2020 05:58:13 +0000 Received: from mail-pg1-f193.google.com ([209.85.215.193]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jPJmH-0005RA-0A for pgsql-hackers@postgresql.org; Fri, 17 Apr 2020 05:43:18 +0000 Received: by mail-pg1-f193.google.com with SMTP id t11so588894pgg.2 for ; Thu, 16 Apr 2020 22:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=oiXQuCG4xqYF/1vT5ut0Qbk4M07X6XfJi7Xo72SbOMA=; b=LLGY5WQ0OXqql75lwDP3deC82rRymB6DPcwYq54Bd5iC+eGH6km0EQLoznZ1h317cT tNsIdTwSrniYJCiAaVCFRdtRjTQV+wa/X6ac+2Pa98Iq3dEXcKQUmJ9jtijGplGhi74v UMaNxhns+jQ9Lt8OjKp1F4mdq3gqDxAGq7daQ= 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=oiXQuCG4xqYF/1vT5ut0Qbk4M07X6XfJi7Xo72SbOMA=; b=hmRJPHHATDR6ICOcS1EI5ue82xAhvcP+UJLqW605OEXCD5cj4cA2lbG35CiMecicG4 Fk+8U9X1vqmE7zJ1uJnjMNT6gdjfaysy29/WIu8QcqLvvdL1Sn44XF68LBlAMtBNPVha vZceRT3QchsqfVv//YHvHCU3LBDnuef7unzcBZwjqExci2HIBGlypM08Kcx9yfZx0JcB zBRtjoqHXhV5WypPj5hjb5ArJOpyi2NrTMXdkSTE3kIRPe+A5qA9U5vR4PosIS/+W39C pMsD2Iy5Re/jXdb1l6zJTVsupbgPnTpM7BbYBgDl1447XV513YHqa6tk3FKWc6iTiqxv RcYQ== X-Gm-Message-State: AGi0Puakd+8DZlDfF3tWgo+Jf9NnbQlI3BwWlYOCFDaX9f6LU3BIonhz NYQQst2KhETgmfm3NuUodfzLvw== X-Google-Smtp-Source: APiQypIuYhVCwbHT+DCsGc5WH7Nd0WC6l7RZIPfxj6woM00vhj8bNhDPQIe+NweYB06Un6Xl3nPUgw== X-Received: by 2002:aa7:8f36:: with SMTP id y22mr1553628pfr.162.1587102108938; Thu, 16 Apr 2020 22:41:48 -0700 (PDT) Received: from rfd.leadboat.com (108-233-125-46.lightspeed.sntcca.sbcglobal.net. [108.233.125.46]) by smtp.gmail.com with ESMTPSA id a99sm4492031pje.35.2020.04.16.22.41.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Apr 2020 22:41:48 -0700 (PDT) Date: Thu, 16 Apr 2020 22:41:46 -0700 From: Noah Misch To: Tom Lane , Fujii Masao Cc: pgsql-hackers@postgresql.org Subject: Re: 001_rep_changes.pl stalls Message-ID: <20200417054146.GA1061007@rfd.leadboat.com> References: <20200406063649.GA3738151@rfd.leadboat.com> <20200414013849.GA886648@rfd.leadboat.com> <8807.1586828716@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8807.1586828716@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Apr 13, 2020 at 09:45:16PM -0400, Tom Lane wrote: > Noah Misch writes: > > This seems to have made the following race condition easier to hit: > > https://www.postgresql.org/message-id/flat/20200206074552.GB3326097%40rfd.leadboat.com > > https://www.postgresql.org/message-id/flat/21519.1585272409%40sss.pgh.pa.us > > Yeah, I just came to the same guess in the other thread. > > > While I don't think that indicates anything wrong with the fix for $SUBJECT, > > creating more buildfarm noise is itself bad. I am inclined to revert the fix > > after a week. Not immediately, in case it uncovers lower-probability bugs. > > I'd then re-commit it after one of those threads fixes the other bug. Would > > anyone like to argue for a revert earlier, later, or not at all? > > I don't think you should revert. Those failures are (just) often enough > to be annoying but I do not think that a proper fix is very far away. That works for me, but an actual defect may trigger a revert. Fujii Masao reported high walsender CPU usage after this patch. The patch caused idle physical walsenders to use 100% CPU. When caught up, the WalSndSendDataCallback for logical replication, XLogSendLogical(), sleeps until more WAL is available. XLogSendPhysical() just returns when caught up. No amount of WAL is too small for physical replication to dispatch, but logical replication needs the full xl_tot_len of a record. Some options: 1. Make XLogSendPhysical() more like XLogSendLogical(), calling WalSndWaitForWal() when no WAL is available. A quick version of this passes tests, but I'll need to audit WalSndWaitForWal() for things that are wrong for physical replication. 2. Make XLogSendLogical() more like XLogSendPhysical(), returning when insufficient WAL is available. This complicates the xlogreader.h API to pass back "wait for this XLogRecPtr", and we'd then persist enough state to resume decoding. This doesn't have any advantages to make up for those. 3. Don't avoid waiting in WalSndLoop(); instead, fix the stall by copying the WalSndKeepalive() call from WalSndWaitForWal() to WalSndLoop(). This risks further drift between the two wait sites; on the other hand, one could refactor later to help avoid that. 4. Keep the WalSndLoop() wait, but condition it on !logical. This is the minimal fix, but it crudely punches through the abstraction between WalSndLoop() and its WalSndSendDataCallback. I'm favoring (1). Other preferences?