for (fork = 0; fork <= MAX_FORKNUM; fork++)
{
- if (smgrexists(srel, fork))
- {
- XLogDropRelation(xlrec->xnodes[i], fork);
- smgrdounlink(srel, fork, true);
- }
+ XLogDropRelation(xlrec->xnodes[i], fork);
+ smgrdounlink(srel, fork, true);
}
smgrclose(srel);
}
for (fork = 0; fork <= MAX_FORKNUM; fork++)
{
- if (smgrexists(srel, fork))
- {
- XLogDropRelation(xlrec->xnodes[i], fork);
- smgrdounlink(srel, fork, true);
- }
+ XLogDropRelation(xlrec->xnodes[i], fork);
+ smgrdounlink(srel, fork, true);
}
smgrclose(srel);
}
srel = smgropen(pending->relnode, pending->backend);
for (i = 0; i <= MAX_FORKNUM; i++)
{
- if (smgrexists(srel, i))
- smgrdounlink(srel, i, false);
+ smgrdounlink(srel, i, false);
}
smgrclose(srel);
}
* number until it's safe, because relfilenode assignment skips over any
* existing file.
*
- * If isRedo is true, it's okay for the relation to be already gone.
+ * All the above applies only to the relation's main fork; other forks can
+ * just be removed immediately, since they are not needed to prevent the
+ * relfilenode number from being recycled. Also, we do not carefully
+ * track whether other forks have been created or not, but just attempt to
+ * unlink them unconditionally; so we should never complain about ENOENT.
+ *
+ * If isRedo is true, it's unsurprising for the relation to be already gone.
* Also, we should remove the file immediately instead of queuing a request
* for later, since during redo there's no possibility of creating a
* conflicting relation.
if (isRedo || forkNum != MAIN_FORKNUM)
{
ret = unlink(path);
- if (ret < 0)
- {
- if (!isRedo || errno != ENOENT)
- ereport(WARNING,
- (errcode_for_file_access(),
- errmsg("could not remove file \"%s\": %m", path)));
- }
+ if (ret < 0 && errno != ENOENT)
+ ereport(WARNING,
+ (errcode_for_file_access(),
+ errmsg("could not remove file \"%s\": %m", path)));
}
else
{
ereport(WARNING,
(errcode_for_file_access(),
errmsg("could not truncate file \"%s\": %m", path)));
+
+ /* Register request to unlink first segment later */
+ register_unlink(rnode);
}
/*
}
pfree(path);
-
- /* Register request to unlink first segment later */
- if (!isRedo && forkNum == MAIN_FORKNUM)
- register_unlink(rnode);
}
/*