Re: pgstat_reset_remove_files ignores its argument

Lists: pgsql-hackers
From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: pgstat_reset_remove_files ignores its argument
Date: 2013-08-14 04:13:11
Message-ID: CAMkU=1wbk947=-pAosDMX5VC+sQw9W4ttq6RM9rXu=MjNeEQKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

in 9.3 and 9.4, pgstat_reset_remove_files uses the global variable
pgstat_stat_directory rather than the argument it is passed, "directory".
On crash recovery, this means the tmp directory gets cleared twice and the
permanent pg_stat doesn't get cleared at all.

It seems like the obvious one line change would fix it, but I haven't
tested it because I don't know how to cause a crash without pg_stat already
being empty.

pgstat_reset_remove_files(const char *directory)
{
DIR *dir;
struct dirent *entry;
char fname[MAXPGPATH];

dir = AllocateDir(pgstat_stat_directory);

Cheers,

Jeff


From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgstat_reset_remove_files ignores its argument
Date: 2013-08-16 19:38:09
Message-ID: CA+Tgmoa+0F7fnY7v1PZZarK4hd07r48yCbg1R+KSXbzYzdAoVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, Aug 14, 2013 at 12:13 AM, Jeff Janes <jeff(dot)janes(at)gmail(dot)com> wrote:
> in 9.3 and 9.4, pgstat_reset_remove_files uses the global variable
> pgstat_stat_directory rather than the argument it is passed, "directory".
> On crash recovery, this means the tmp directory gets cleared twice and the
> permanent pg_stat doesn't get cleared at all.
>
> It seems like the obvious one line change would fix it, but I haven't tested
> it because I don't know how to cause a crash without pg_stat already being
> empty.

I think there are three lines to change, as in the attached patch.

Am I wrong?

...Robert

Attachment Content-Type Size
pgstat-reset-remove-files.patch application/octet-stream 859 bytes

From: Tomas Vondra <tv(at)fuzzy(dot)cz>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: pgstat_reset_remove_files ignores its argument
Date: 2013-08-16 19:47:51
Message-ID: 520E81E7.7040103@fuzzy.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 16.8.2013 21:38, Robert Haas wrote:
> On Wed, Aug 14, 2013 at 12:13 AM, Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
> wrote:
>> in 9.3 and 9.4, pgstat_reset_remove_files uses the global variable
>> pgstat_stat_directory rather than the argument it is passed,
>> "directory". On crash recovery, this means the tmp directory gets
>> cleared twice and the permanent pg_stat doesn't get cleared at
>> all.
>>
>> It seems like the obvious one line change would fix it, but I
>> haven't tested it because I don't know how to cause a crash without
>> pg_stat already being empty.
>
> I think there are three lines to change, as in the attached patch.
>
> Am I wrong?
>
> ...Robert

I think the patch is OK.

Tomas


From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgstat_reset_remove_files ignores its argument
Date: 2013-08-19 18:02:59
Message-ID: CAMkU=1zoiMWkYFZ+Q3Lo_F-GfcKh=MnAsAKyHKfBHU_YBm6S3g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, Aug 16, 2013 at 12:38 PM, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Wed, Aug 14, 2013 at 12:13 AM, Jeff Janes <jeff(dot)janes(at)gmail(dot)com> wrote:
>> in 9.3 and 9.4, pgstat_reset_remove_files uses the global variable
>> pgstat_stat_directory rather than the argument it is passed, "directory".
>> On crash recovery, this means the tmp directory gets cleared twice and the
>> permanent pg_stat doesn't get cleared at all.
>>
>> It seems like the obvious one line change would fix it, but I haven't tested
>> it because I don't know how to cause a crash without pg_stat already being
>> empty.
>
> I think there are three lines to change, as in the attached patch.
>
> Am I wrong?

No, you are right, I too realized I missed a couple more spots. Your
patch looks just like the one I eventually arrived at, before I got
distracted thinking about how to implement the regex
/^(global|db_\d+)\.stat$/ in C and forgot to post a correction.

Is the regex code in src/backend/regex allowed to be used from "flat"
C code, or does it have to be in the context of a transaction, memory
context, etc.?

Cheers,

Jeff


From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgstat_reset_remove_files ignores its argument
Date: 2013-08-19 18:06:07
Message-ID: 20130819180607.GG9264@eldon.alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Jeff Janes escribió:

> No, you are right, I too realized I missed a couple more spots. Your
> patch looks just like the one I eventually arrived at, before I got
> distracted thinking about how to implement the regex
> /^(global|db_\d+)\.stat$/ in C and forgot to post a correction.
>
> Is the regex code in src/backend/regex allowed to be used from "flat"
> C code, or does it have to be in the context of a transaction, memory
> context, etc.?

See 20130819180437(dot)GF9264(at)eldon(dot)alvh(dot)no-ip(dot)org .. the only thing missing
there is the $, AFAICT.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services