Thread: a litter question about mdunlinkfiletag function

a litter question about mdunlinkfiletag function

From
px shi
Date:

Hi, hackers

When calculating the path, forknum is hardcoded as MAIN_FORKNUM:

/* Compute the path. */
p = relpathperm(ftag->rnode, MAIN_FORKNUM);


But since the ftag structure already contains forknum:

typedef struct FileTag
{
int16 handler; /* SyncRequestHandler value, saving space */
int16 forknum; /* ForkNumber, saving space */
RelFileNode rnode;
uint32 segno;
} FileTag;


Wouldn’t it be more flexible to use the value from the ftag structure directly?


Best regards, 

Pixian Shi

Re: a litter question about mdunlinkfiletag function

From
Bruce Momjian
Date:
On Mon, Sep 30, 2024 at 10:43:17AM +0800, px shi wrote:
> Hi, hackers
> 
> When calculating the path, forknum is hardcoded as MAIN_FORKNUM:
> 
> /* Compute the path. */
> p = relpathperm(ftag->rnode, MAIN_FORKNUM);
> 
> 
> But since the ftag structure already contains forknum:
> 
> typedef struct FileTag
> {
> int16 handler; /* SyncRequestHandler value, saving space */
> int16 forknum; /* ForkNumber, saving space */
> RelFileNode rnode;
> uint32 segno;
> } FileTag;
> 
> 
> Wouldn’t it be more flexible to use the value from the ftag structure directly?

You will find other places where relpathperm() is called without having
a FileTag structure available, e.g. ReorderBufferProcessTXN().

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  When a patient asks the doctor, "Am I going to die?", he means 
  "Am I going to die soon?"



Re: a litter question about mdunlinkfiletag function

From
px shi
Date:
You will find other places where relpathperm() is called without having
a FileTag structure available, e.g. ReorderBufferProcessTXN().

I apologize for the confusion. What I meant to say is that in the mdunlinkfiletag() function, the forknum is currently hardcoded as MAIN_FORKNUM when calling relpathperm(). While mdunlinkfiletag currently only handles MAIN_FORKNUM, wouldn’t it be more flexible to retrieve the forknum from the ftag structure instead?


Bruce Momjian <bruce@momjian.us> 于2024年10月15日周二 04:59写道:
On Mon, Sep 30, 2024 at 10:43:17AM +0800, px shi wrote:
> Hi, hackers
>
> When calculating the path, forknum is hardcoded as MAIN_FORKNUM:
>
> /* Compute the path. */
> p = relpathperm(ftag->rnode, MAIN_FORKNUM);
>
>
> But since the ftag structure already contains forknum:
>
> typedef struct FileTag
> {
> int16 handler; /* SyncRequestHandler value, saving space */
> int16 forknum; /* ForkNumber, saving space */
> RelFileNode rnode;
> uint32 segno;
> } FileTag;
>
>
> Wouldn’t it be more flexible to use the value from the ftag structure directly?

You will find other places where relpathperm() is called without having
a FileTag structure available, e.g. ReorderBufferProcessTXN().

--
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

  When a patient asks the doctor, "Am I going to die?", he means
  "Am I going to die soon?"

Re: a litter question about mdunlinkfiletag function

From
Matthias van de Meent
Date:
On Tue, 15 Oct 2024 at 04:50, px shi <spxlyy123@gmail.com> wrote:
>>
>> You will find other places where relpathperm() is called without having
>> a FileTag structure available, e.g. ReorderBufferProcessTXN().
>
>
> I apologize for the confusion. What I meant to say is that in the mdunlinkfiletag() function, the forknum is
currentlyhardcoded as MAIN_FORKNUM when calling relpathperm(). While mdunlinkfiletag currently only handles
MAIN_FORKNUM,wouldn’t it be more flexible to retrieve the forknum from the ftag structure instead? 

I just noticed this mail thread as I was searching the archives for
other mentions of `mdunlinkfiletag` when doing some more digging on
uses of that function, to back my own bug report of what looks like
the same issue. See [0].

As was explained to me by Thomas, the reason why MAIN_FORKNUM is
hardcoded here (and why ftag.segno is also ignored) is that this code
is only ever reached for FileTag values with forknum=MAIN_FORKNUM (and
segno is also always 0) with the code in Postgres' repository. The
patch proposed in [0] is supposed to make that more clear to
developers.

I suspect the code will be further updated to include the correct fork
number and segment number when there is a need to unlink
non-MAIN_FORKNUM or non-segno=0 files in mdunlinkfiletag.

Kind regards,

Matthias van de Meent

[0]
https://www.postgresql.org/message-id/flat/CAEze2WiWt%2B9%2BOnqW1g9rKz0gqxymmt%3Doe6pKAEDrutdfpDMpTw%40mail.gmail.com