Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/backend/access/appendonly/aomd.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ struct truncate_ao_callback_ctx
void
mdunlink_ao(RelFileNodeBackend rnode, ForkNumber forkNumber, bool isRedo)
{
int ret;
const char *path = relpath(rnode, forkNumber);

/*
Expand Down Expand Up @@ -294,6 +295,19 @@ mdunlink_ao(RelFileNodeBackend rnode, ForkNumber forkNumber, bool isRedo)
pfree(segPath);
}

/*
* Delete or truncate the first segment. See mdunlinkfork also.
*/
if (RelFileNodeBackendIsTemp(rnode))
{
/* Next unlink the file, unless it was already found to be missing */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!

Minor comments below:

int ret; is declared at function scope.
Better to be scoped inside the if block, or removed entirely since it's only checked against < 0 immediately.

ret = unlink(path);
if (ret < 0 && errno != ENOENT)
ereport(WARNING,
(errcode_for_file_access(),
errmsg("could not remove file \"%s\": %m", path)));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also unlink the segment files beyond segment 0?

How about modifying mdunlink_ao_base_relfile() and mdunlink_ao_perFile() to check RelFileNodeBackendIsTemp(rnode) and unlink immediately (mirroring the heap mdunlinkfork pattern), rather than appending a separate unlink at the end of mdunlink_ao?

Something like

  if (!unlinkFiles->isRedo)
  {
      if (RelFileNodeBackendIsTemp(unlinkFiles->rnode))
      {
          ret = unlink(baserel);
          if (ret < 0 && errno != ENOENT)
              ereport(WARNING, ...);
      }
      else
      {
          // Existing truncate + deferred unlink logic
          ...
      }
  }

pfree((void *) path);
}

Expand Down
Loading