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 1jM5c9-0002TU-Ux for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2020 07:59:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jM5c8-0007R7-Re for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2020 07:59:12 +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 1jM5c8-0007Qx-Kc for pgsql-hackers@lists.postgresql.org; Wed, 08 Apr 2020 07:59:12 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jM5c1-0004tM-Va for pgsql-hackers@postgresql.org; Wed, 08 Apr 2020 07:59:11 +0000 Received: by mail-wm1-x343.google.com with SMTP id z6so365745wml.2 for ; Wed, 08 Apr 2020 00:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:in-reply-to:references:comments:mime-version :content-id:content-transfer-encoding:date:message-id; bh=7bzNqoQVd4WNY863u0B3id57PCqW0J0h8PDHnJRQMnM=; b=QU2UumJF6MrmCKVJUh7g35cEbva9CAMpXvCPXOUkiqitMnzY8TkaCpsOABacgWScgm vrpQWxe2IfPvkEOmapsjIHhv1gtCGPmCOZNkDaXb6mgVK5vnmsscDjXYWQhUFPZtsdBR aRRyN1+oK3YYi25u7u5eNJzADO6in/2AVLbcHDc6QYDcMC9XDGkecWK/6fujI1cTtmPm XozZ9VVMAXXkYORGt3L/puXHb7wJJqHb8xZZevG1HqHbDwR0BmaRSgrQRu3rFuecf1Cz um0qg60pn/U5Idyye1czLldhQLazkXcQBTDtIiitOocA5zBBhuawc+Tx56O4SoTmmVmF qGvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :comments:mime-version:content-id:content-transfer-encoding:date :message-id; bh=7bzNqoQVd4WNY863u0B3id57PCqW0J0h8PDHnJRQMnM=; b=JqgzMb5EVw1ZYj//nw2dAN79gsHgZcEBukvyEr8OHlhxPPvQhdtkOpkHBeGpTXWvmW lR9AAEaLbnOOrYTYYBpF53GHLy/H9/80/1x/jvLhX69u6rg8zvrNLLUPDto3sDGGGySG CWQJ1+RunHeKnqmzouSPxf2RlDBsrtzxtlT9DeNFahWLRAPbnWTex9i5EYvmMSSC8A1q iqtpygzHVuAMtB3a2R13CpHAX0GpHdi5/H0TBFbHzloCHvkg0PRUxvIbVawfNbpaOx2B dCw9jyGWXd+2onnBTSxJK9bCJoP+66i5LUQeejOORkrzve1Yf0pXyVDEKSwP9uM/AI77 YajA== X-Gm-Message-State: AGi0Pubc9olhXq0weFhApKGTeTWa+sJKlrryMGUFr4aqpUyVBbFbwst8 13y1154TND5bI9qAcTmPrVDSOw== X-Google-Smtp-Source: APiQypJaRPzzICW1ylH6MSwCy8PzcYpPbsQYqaPaoealIqCndjxqaXe9sqtOs6TrC/Z6sfF4gj+bFg== X-Received: by 2002:a7b:c250:: with SMTP id b16mr3476119wmj.100.1586332744178; Wed, 08 Apr 2020 00:59:04 -0700 (PDT) Received: from antos ([77.87.240.5]) by smtp.gmail.com with ESMTPSA id t16sm36077761wra.17.2020.04.08.00.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2020 00:59:03 -0700 (PDT) From: Antonin Houska To: Andres Freund cc: Michael Paquier , pgsql-hackers@postgresql.org, Alvaro Herrera Subject: Re: 2pc leaks fds In-reply-to: <20200408001249.2ma2x6s54xcegiu2@alap3.anarazel.de> References: <20200406025651.fpzdb5yyb7qyhqko@alap3.anarazel.de> <20200406052648.GB2066@paquier.xyz> <20200406054449.ssmrzj4fav3ewvaq@alap3.anarazel.de> <26247.1586157152@antos> <20200408001249.2ma2x6s54xcegiu2@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Tue, 07 Apr 2020 17:12:49 -0700." X-Mailer: MH-E 8.6+git; nmh 1.7; GNU Emacs 26.3.50 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <70538.1586332821.1@antos> Content-Transfer-Encoding: quoted-printable Date: Wed, 08 Apr 2020 10:00:21 +0200 Message-ID: <70539.1586332821@antos> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund wrote: > On 2020-04-06 09:12:32 +0200, Antonin Houska wrote: > > Andres Freund wrote: > > It should have allowed users to have different ways to *locate the seg= ment* > > file. The WALSegmentOpen callback could actually return file path inst= ead of > > the file descriptor and let WALRead() perform the opening/closing, but= then > > the WALRead function would need to be aware whether it is executing in= backend > > or in frontend (so it can use the correct function to open/close the f= ile). > > = > > I was aware of the problem that the correct function should be used to= open > > the file and that's why this comment was added (although "mandatory" w= ould be > > more suitable than "preferred"): > > = > > * BasicOpenFile() is the preferred way to open the segment file in ba= ckend > > * code, whereas open(2) should be used in frontend. > > */ > > typedef int (*WALSegmentOpen) (XLogSegNo nextSegNo, WALSegmentContext = *segcxt, > > TimeLineID *tli_p); > = > I don't think that BasicOpenFile() really solves anything here? If > anything it *exascerbates* the problem, because it will trigger all of > the "virtual file descriptors" for already opened Files to close() the > underlying OS FDs. So not even a fully cached table can be seqscanned, > because that tries to check the file size... Specifically for 2PC, isn't it better to close some OS-level FD of an unrelated table scan and then succeed than to ERROR immediately? Anyway, 0dc8ead46 hasn't changed this. I at least admit that the comment should not recommend particular function= , and that WALRead() should call the appropriate function to close the file, rather than always calling close(). Can we just pass the existing FD to the callback as an additional argument= , and let the callback close it? -- = Antonin Houska Web: https://www.cybertec-postgresql.com