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 1k00XM-0008WR-7b for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Jul 2020 10:39:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k00XJ-0002la-Gj for pgsql-hackers@arkaria.postgresql.org; Mon, 27 Jul 2020 10:39:13 +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 1k00XJ-0002lT-3b for pgsql-hackers@lists.postgresql.org; Mon, 27 Jul 2020 10:39:13 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1k00XC-0003aC-Bp for pgsql-hackers@postgresql.org; Mon, 27 Jul 2020 10:39:12 +0000 Received: by mail-io1-xd41.google.com with SMTP id a5so1160255ioa.13 for ; Mon, 27 Jul 2020 03:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Qpo90H2cyA22f01Tb1UkeEx5KxKrBCqqj4OBVJ7a7bk=; b=AkVbhlBRpsLerkLEQfS4hFfko4vkE+puoMIUzCnLxh4KWdwqlTkxey5nSyGub/vXlO UYFLOXcLfdFsngaQeEcoyHujXTyL/FWCcyInwmt2gXfyOhys8FiZyEsx5abYgtmMqe03 MqTarAVB458w+8AbW73jdPN97bPwDAUAJjGSUi/OisIiq4NwAUTc9Ghcu11Gr/FQqLrU GQrsHg/CUwyZM8YCBOz3/IHchvHwGKu6mPWBnhsm7EQYWbLjJ68AL0AxKs4j8j90Tb8q YvsSmgWIg1kHS53quZ8SCCiDzXDPTHX7juSXZucaYOeaZ4txaP/L/uo3nT7f7Ul9syc3 kEHg== 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=Qpo90H2cyA22f01Tb1UkeEx5KxKrBCqqj4OBVJ7a7bk=; b=IwskeobC5topAZJR20zpfTsIyTQdYHszq5ttrMXjDJWazALvFCEFXphX21+JzuhIZv siBqZnEA4A48V322TlHn2fIeQEZMJDQe+3SKeeat0BT8UParRp43bKVCGaH9bqe2CQU0 7AhKNd1PMqWBnktyhkL/0fzjxpn54Fcpf0fZIPob3dslqeebRFcVR/h0KMzIbMrPEhMm 7ow5SzCkgaJBtYKiRCqrcsHrBT/G6GPjog7eey39r6qBV/F2Vc2v3vPWWSt+6b5rsuMn oZz9ODLjeOoERK7kiuJh77TEsrT5WxIz54pjScZeZ5lHBI5eFbmNhpsnC0R/FyVvUYmF JMlw== X-Gm-Message-State: AOAM532U5q3kAJzuG/I016yMAGEJ7yPNF2b3Xj/7bEA3aURoxsbAX5Lt +lzwL7FdVy06L7R4/+rwrV2wLA== X-Google-Smtp-Source: ABdhPJytIW+sdpc28ACL1TfEOEFdnXWhNEI0QDLbMSU7FD2zRQQf5eSHGGGt4x+KdTuqijC5NQ2Hgg== X-Received: by 2002:a6b:2c8:: with SMTP id 191mr16724416ioc.41.1595846344690; Mon, 27 Jul 2020 03:39:04 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id y12sm8024084ilm.38.2020.07.27.03.39.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Jul 2020 03:39:03 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id D830480017D; Mon, 27 Jul 2020 05:39:02 -0500 (CDT) Date: Mon, 27 Jul 2020 05:39:02 -0500 From: Justin Pryzby To: Thomas Munro Cc: pgsql-hackers , "Bossart, Nathan" Subject: Re: shared tempfile was not removed on statement_timeout Message-ID: <20200727103902.GM4286@telsasoft.com> References: <20200721043258.GE5748@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Jul 27, 2020 at 08:00:46PM +1200, Thomas Munro wrote: > On Tue, Jul 21, 2020 at 4:33 PM Justin Pryzby wrote: > > /* > > * clean up a spool structure and its substructures. > > */ > > static void > > _bt_spooldestroy(BTSpool *btspool) > > { > > + void *fileset = tuplesort_shared_fileset(btspool->sortstate); > > + if (fileset) > > + SharedFileSetDeleteAll(fileset); > > tuplesort_end(btspool->sortstate); > > pfree(btspool); > > } > > Why can't tuplesort_end do it? Because then I think the parallel workers remove their own files, with tests failing like: +ERROR: could not open temporary file "0.0" from BufFile "0": No such file or directory I look around a bit more and came up with this, which works, but I don't know enough to say if it's right. diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 5f6420efb2..f89d42f475 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -3344,6 +3344,7 @@ walkdir(const char *path, struct stat fst; int sret; + usleep(99999); CHECK_FOR_INTERRUPTS(); if (strcmp(de->d_name, ".") == 0 || diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index 3c49476483..c6e5e6d00b 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -1387,6 +1387,9 @@ tuplesort_free(Tuplesortstate *state) void tuplesort_end(Tuplesortstate *state) { + if (state->shared && state->shared->workersFinished == state->nParticipants) + SharedFileSetDeleteAll(&state->shared->fileset); + tuplesort_free(state); /*