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 1jS0ZV-0005pR-DS for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Apr 2020 15:48:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jS0ZS-0007r4-QX for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Apr 2020 15:48:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jS0ZS-0007q1-CY for pgsql-hackers@lists.postgresql.org; Fri, 24 Apr 2020 15:48:54 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jS0ZO-000897-2P for pgsql-hackers@postgresql.org; Fri, 24 Apr 2020 15:48:52 +0000 Received: by mail-qk1-x742.google.com with SMTP id t3so10642785qkg.1 for ; Fri, 24 Apr 2020 08:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=Dg0QypkLPmkY6HiDYxtaFAqoYfRBo4BZaL18EYGFkwo=; b=Ep6m3WTCwpOMsT5j2KO5RGk/YUho9v2KmPlJL7n4dB5MIS6/kk3GjecMUgXgjkTUv8 O3A1+jLVZWMjWwQAWDm1yEcFfdPGGnH3Yng0u0aiV0FEc6tFudvJJ1bjTOI+57QM022c De+9ask1rmVV1O45nspw4Nnf/ROlrqk/DwnXqa+yEd5mRb8+mqtO+6uwj/2qirHVkaDC U6f71+EZBH2FEXX1R0+G2ggdnMcqIYG9XjUmQQ2ziTTjGgvPEa3zk+he16FlVemGK4h/ y/hg4wkSXxGA+tFQrBmaLgD/P499++gxsmlIpPMbRZzoFXnYPjgOxYJOOlugu7aFlCCF 0alg== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=Dg0QypkLPmkY6HiDYxtaFAqoYfRBo4BZaL18EYGFkwo=; b=siRK404ARx0v7q3F4/57+im6zxVYCgmNPEqvgYoLYJubnnZIwpIO32jWM4K/W9mIyI BmsL6wRdPncv2sKN1q/yVfEdIhRKBEtA47+8OEtsc8KsMloRLQpyHbyCHjo4LblT1X1k 3zE/QBGvva89RILhbjyFSl+gb8cMhRlyWKnx6MbdoWbgUuN6DgmRbNIPfkU2ZEHuHDOd LXlcn5sk4iD0ggkDuGaE2ZmGIy2edfTOeqsf5MFhAfrHnIeeIhXZPEAiKeNNZcQjAI/e 3gCKWas/X2jwLO1qmNXmuq+Cx5BgjKEX7LTtDzBniZcFJZqYVebbXH7xkGGRxlxmHRYw tqQQ== X-Gm-Message-State: AGi0PuaKlmkQ51X5OPf9PErhlfg38sAxjMLUjlmhr/Xmu4U5NudZWasQ DLJ4GO+TMS4MLR+76Qwe6V9bjw== X-Google-Smtp-Source: APiQypKIsqwLvBYaPhNUJRT1Vofuc0EjaVnjZMwR3Z44uxLkmqvNRn+dg6h9C960bbNWFSQ/UKbnPQ== X-Received: by 2002:a05:620a:844:: with SMTP id u4mr9718665qku.20.1587743329105; Fri, 24 Apr 2020 08:48:49 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id g6sm4203442qtc.52.2020.04.24.08.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 08:48:48 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 9F64830162D; Fri, 24 Apr 2020 11:48:46 -0400 (-04) Date: Fri, 24 Apr 2020 11:48:46 -0400 From: Alvaro Herrera To: Kyotaro Horiguchi Cc: andres@anarazel.de, ah@cybertec.at, michael@paquier.xyz, pgsql-hackers@postgresql.org Subject: Re: 2pc leaks fds Message-ID: <20200424154846.GA28188@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200424.153651.401853964209886273.horikyota.ntt@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Apr-24, Kyotaro Horiguchi wrote: > At Thu, 23 Apr 2020 19:16:03 -0400, Alvaro Herrera wrote in > > Here's a first attempt at that. The segment_open/close callbacks are > > now given at XLogReaderAllocate time, and are passed the XLogReaderState > > pointer. I wrote a comment to explain that the page_read callback can > > use WALRead() if it wishes to do so; but if it does, then segment_open > > has to be provided. segment_close is mandatory (since we call it at > > XLogReaderFree). > I modestly object to such many call-back functions. FWIW I'm writing > this with [1] in my mind. > [1] https://www.postgresql.org/message-id/20200422.101246.331162888498679491.horikyota.ntt%40gmail.com Hmm. Looking at your 0001, I think there's nothing in that patch that's not compatible with my proposed API change. 0002 is a completely different story of course; but that patch is a radical change of spirit for xlogreader, in the sense that it's no longer a "reader", but rather just an interpreter of bytes from a WAL byte sequence into WAL records; and shifts the responsibility of the actual reading to the caller. That's why xlogreader no longer receives the page_read callback (and why it doesn't need the segment_open, segment_close callbacks). I have to admit that until today I hadn't realized that that's what your patch series was doing. I'm not familiar with how you intend to implement WAL encryption on top of this, but on first blush I'm not liking this proposed design too much. > An open-callback is bound to a read-callback. A close-callback is > bound to the way the read-callback opens a segment (or the > open-callback). I'm afraid that only adding "cleanup" callback might > be sufficient. Well, the complaint is that the current layering is weird, in that there are two levels at which we pass callbacks: one is XLogReaderAllocate, where you specify the page_read callback; and the other layer is inside the page_read callback, if that layer uses the WALRead auxiliary function. The thing that my patch is doing is pass all three callbacks at the XLogReaderAllocate level. So when xlogreader drills down to read_page, xlogreader already has the segment_open callback handy if it needs it. Conceptually, this seems more sensible. I think a "cleanup" callback might also be sensible in general terms, but we have a problem with the specifics -- namely that the "state" that we need to clean up (the file descriptor of the open segment) is part of xlogreader's state. And we obviously cannot remove the FD from XLogReaderState, because when we need the FD to do things with it to obtain data from the file. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services