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 1keJVi-0005kw-DJ for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Nov 2020 15:00:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1keJVf-0007r7-8a for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Nov 2020 15:00:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1keJVe-0007r0-VX for pgsql-hackers@lists.postgresql.org; Sun, 15 Nov 2020 15:00:07 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1keJVb-0004Pg-Lt for pgsql-hackers@postgresql.org; Sun, 15 Nov 2020 15:00:06 +0000 Received: by mail-lj1-x231.google.com with SMTP id 142so3071530ljj.10 for ; Sun, 15 Nov 2020 07:00:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=mnmhMJapkeqL5DtIA3JRSAGkh+XaT4YynIHKRP7DG8s=; b=JYGPpk0VUtaK51J0HHw2CqWq+Ci14IjscbdJCvPpKxx73U+lMnbb5SrBYA5OVXbbAv ymxMWU7LI/E32I/eSbhvfiYJ85tJQOtXNxryHrq5gQ2t22X9vSqvJY/pOk36ybk0a+Zt 3uguL/E2JDiZbzCYeLWghX56Bj7gqNHO1YZqm2arg5IberuYDKplW1/QqaHhxTTN6rT2 YE6CH01W3ipkA3TSCVoCw/SxbrWV4/0RAVBoEEq41QvjdX4HC9uF1/gk77+rG9ZQZ2x9 BpojtiMNZqOUEoMhqJ/s0viqAXLdEIpaAvCY97I7wM3xi3St/ta0SgU7EdDNu6TRmBdL lhpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=mnmhMJapkeqL5DtIA3JRSAGkh+XaT4YynIHKRP7DG8s=; b=Lfh+IFLV7CbIdyd4Jl4QzoVEnOBB2QYPur9ryr+Wm8LrIF9tDvX3/q6ItQimmch7gu 0zSBEl3rqm5rJt1R2natDuUCrc9uVdYWxdCD3c4auWmFo0Dw+RnTt4NAb3yW9zCgns/z zUpW9jakXXUnkYJNgIXTajfi+IPhdm9o54DsZ6VjaNOplQrfklyQzvRp7f6pm2yfyrdz jX3U4NJIFoPu/JCjbYSbok/MQzlhW3X4acBYn9BJTwPklrH4c0bSP+kmZLW4cxXx2FHx sb/PXx6dj8DF3472c34YtwzijIT7e0u3Zmq4+TWVimhwfpMh6K9aMIgccb/JVSJx7mt8 uuHQ== X-Gm-Message-State: AOAM530Y3GL+iCC4Ev9KUTjtOMbo6ZaGhObUIukNig5RsQjepW+YkXnu AXsniZ1eLYETv6bOPFQBnIDTV0FROEk= X-Google-Smtp-Source: ABdhPJwtZXO88bq0AyODeyLbd09rzWy9y84G1Azta8AxwB/5Jm2x/bHL4nL5oV3u7zBGRQ+p0P21WQ== X-Received: by 2002:a2e:998e:: with SMTP id w14mr2256290lji.100.1605452402488; Sun, 15 Nov 2020 07:00:02 -0800 (PST) Received: from [1.0.0.7] ([178.155.6.8]) by smtp.gmail.com with ESMTPSA id a8sm1418250ljq.77.2020.11.15.07.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 Nov 2020 07:00:02 -0800 (PST) Subject: Re: More time spending with "delete pending" From: Alexander Lakhin To: Justin Pryzby Cc: pgsql-hackers References: <20201115011112.GW30691@telsasoft.com> <979f4ee6-9960-e37f-f3ee-f458e87777b0@gmail.com> Message-ID: Date: Sun, 15 Nov 2020 18:00:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <979f4ee6-9960-e37f-f3ee-f458e87777b0@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 15.11.2020 08:00, Alexander Lakhin wrote: > And it rises another question, what if pg_ls_dir_files() is called for a > directory where hundreds or thousands of files are really inaccessible > due to restrictions? > I mean that using CreateFile() in the modified stat() implementation can > be rather expensive for an arbitrary file (and worse yet, for many files). > On the positive side, for now pg_ls_dir_files() is called only from > pg_ls_logdir, pg_ls_waldir, pg_ls_tmpdir, pg_ls_archive_statusdir, where > having a bunch of files that are inaccessible for the postgres user is > not expected anyway. I've missed the fact that pg_ls_dir_files() just fails on first error, so the existing coding would not cause performance issues. But such behavior is somewhat dubious, because having an inaccessible file in a directory of interest would make any of those calls fail > But probably getting directory contents with correct file sizes (>4GB) > in pg_ls_dir_files() can be implemented without calling > CreateFile()/stat() at all (as ProcMon shows, the "dir" command doesn't > call CreateFile() (or any other system function) for each file in the > target directory). As I've found out, readdir() replacement for Windows in fact gets all the needed information (correct file size, attributes...) in WIN32_FIND_DATA, but it just leaves it inside and returns only fields of the dirent structure. So pg_ls_dir_files() (that calls ReadDir()/readdir()) needs to get this information again, that leads to opening a file on Windows. I think it can be done more effectively by adding a new function ReadDirExtendedInfo(), that will additionally accept a pointer to "struct dirent_extra" with fields {valid (indicating that the structure is filled), attributes, file size, mtime}. Maybe the advanced function could also invoke stat() inside (not on Windows). As to patch I proposed before, I think it's still needed to fully support the following usage pattern: stat(); if (no_error) {     do_something(); } else if (file_not_found) {     do_something_else(); } else {     error(); } Best regards, Alexander