*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.148 2009/06/26 20:29:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/smgr/md.c,v 1.149 2009/08/05 18:01:54 heikki Exp $
*
*-------------------------------------------------------------------------
*/
MdfdVec *seg);
static void register_unlink(RelFileNode rnode);
static MdfdVec *_fdvec_alloc(void);
+static char *_mdfd_segpath(SMgrRelation reln, ForkNumber forknum,
+ BlockNumber segno);
static MdfdVec *_mdfd_openseg(SMgrRelation reln, ForkNumber forkno,
BlockNumber segno, int oflags);
static MdfdVec *_mdfd_getseg(SMgrRelation reln, ForkNumber forkno,
errno = save_errno;
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not create relation %s: %m", path)));
+ errmsg("could not create file \"%s\": %m", path)));
}
}
* Delete or truncate the first segment.
*/
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)));
+ }
+ }
else
{
/* truncate(2) would be easier here, but Windows hasn't got it */
}
else
ret = -1;
- }
- if (ret < 0)
- {
- if (!isRedo || errno != ENOENT)
+ if (ret < 0 && errno != ENOENT)
ereport(WARNING,
(errcode_for_file_access(),
- errmsg("could not remove relation %s: %m", path)));
+ errmsg("could not truncate file \"%s\": %m", path)));
}
/*
* Delete any additional segments.
*/
- else
+ if (ret >= 0)
{
char *segpath = (char *) palloc(strlen(path) + 12);
BlockNumber segno;
if (errno != ENOENT)
ereport(WARNING,
(errcode_for_file_access(),
- errmsg("could not remove segment %u of relation %s: %m",
- segno, path)));
+ errmsg("could not remove file \"%s\": %m", segpath)));
break;
}
}
if (blocknum == InvalidBlockNumber)
ereport(ERROR,
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
- errmsg("cannot extend relation %s beyond %u blocks",
+ errmsg("cannot extend file \"%s\" beyond %u blocks",
relpath(reln->smgr_rnode, forknum),
InvalidBlockNumber)));
if (FileSeek(v->mdfd_vfd, seekpos, SEEK_SET) != seekpos)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not seek to block %u of relation %s: %m",
- blocknum,
- relpath(reln->smgr_rnode, forknum))));
+ errmsg("could not seek to block %u in file \"%s\": %m",
+ blocknum, FilePathName(v->mdfd_vfd))));
if ((nbytes = FileWrite(v->mdfd_vfd, buffer, BLCKSZ)) != BLCKSZ)
{
if (nbytes < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not extend relation %s: %m",
- relpath(reln->smgr_rnode, forknum)),
+ errmsg("could not extend file \"%s\": %m",
+ FilePathName(v->mdfd_vfd)),
errhint("Check free disk space.")));
/* short write: complain appropriately */
ereport(ERROR,
(errcode(ERRCODE_DISK_FULL),
- errmsg("could not extend relation %s: wrote only %d of %d bytes at block %u",
- relpath(reln->smgr_rnode, forknum),
+ errmsg("could not extend file \"%s\": wrote only %d of %d bytes at block %u",
+ FilePathName(v->mdfd_vfd),
nbytes, BLCKSZ, blocknum),
errhint("Check free disk space.")));
}
}
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not open relation %s: %m", path)));
+ errmsg("could not open file \"%s\": %m", path)));
}
}
if (FileSeek(v->mdfd_vfd, seekpos, SEEK_SET) != seekpos)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not seek to block %u of relation %s: %m",
- blocknum, relpath(reln->smgr_rnode, forknum))));
+ errmsg("could not seek to block %u in file \"%s\": %m",
+ blocknum, FilePathName(v->mdfd_vfd))));
nbytes = FileRead(v->mdfd_vfd, buffer, BLCKSZ);
if (nbytes < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not read block %u of relation %s: %m",
- blocknum, relpath(reln->smgr_rnode, forknum))));
+ errmsg("could not read block %u in file \"%s\": %m",
+ blocknum, FilePathName(v->mdfd_vfd))));
/*
* Short read: we are at or past EOF, or we read a partial block at
else
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
- errmsg("could not read block %u of relation %s: read only %d of %d bytes",
- blocknum, relpath(reln->smgr_rnode, forknum),
+ errmsg("could not read block %u in file \"%s\": read only %d of %d bytes",
+ blocknum, FilePathName(v->mdfd_vfd),
nbytes, BLCKSZ)));
}
}
if (FileSeek(v->mdfd_vfd, seekpos, SEEK_SET) != seekpos)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not seek to block %u of relation %s: %m",
- blocknum, relpath(reln->smgr_rnode, forknum))));
+ errmsg("could not seek to block %u in file \"%s\": %m",
+ blocknum, FilePathName(v->mdfd_vfd))));
nbytes = FileWrite(v->mdfd_vfd, buffer, BLCKSZ);
if (nbytes < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not write block %u of relation %s: %m",
- blocknum, relpath(reln->smgr_rnode, forknum))));
+ errmsg("could not write block %u in file \"%s\": %m",
+ blocknum, FilePathName(v->mdfd_vfd))));
/* short write: complain appropriately */
ereport(ERROR,
(errcode(ERRCODE_DISK_FULL),
- errmsg("could not write block %u of relation %s: wrote only %d of %d bytes",
+ errmsg("could not write block %u in file \"%s\": wrote only %d of %d bytes",
blocknum,
- relpath(reln->smgr_rnode, forknum),
+ FilePathName(v->mdfd_vfd),
nbytes, BLCKSZ),
errhint("Check free disk space.")));
}
if (v->mdfd_chain == NULL)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not open segment %u of relation %s: %m",
- segno,
- relpath(reln->smgr_rnode, forknum))));
+ errmsg("could not open file \"%s\": %m",
+ _mdfd_segpath(reln, forknum, segno))));
}
v = v->mdfd_chain;
if (InRecovery)
return;
ereport(ERROR,
- (errmsg("could not truncate relation %s to %u blocks: it's only %u blocks now",
+ (errmsg("could not truncate file \"%s\" to %u blocks: it's only %u blocks now",
relpath(reln->smgr_rnode, forknum),
nblocks, curnblk)));
}
if (FileTruncate(v->mdfd_vfd, 0) < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not truncate relation %s to %u blocks: %m",
- relpath(reln->smgr_rnode, forknum),
- nblocks)));
+ errmsg("could not truncate file \"%s\": %m",
+ FilePathName(v->mdfd_vfd))));
+
if (!isTemp)
register_dirty_segment(reln, forknum, v);
v = v->mdfd_chain;
if (FileTruncate(v->mdfd_vfd, (off_t) lastsegblocks * BLCKSZ) < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not truncate relation %s to %u blocks: %m",
- relpath(reln->smgr_rnode, forknum),
+ errmsg("could not truncate file \"%s\" to %u blocks: %m",
+ FilePathName(v->mdfd_vfd),
nblocks)));
if (!isTemp)
register_dirty_segment(reln, forknum, v);
if (FileSync(v->mdfd_vfd) < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not fsync segment %u of relation %s: %m",
- v->mdfd_segno,
- relpath(reln->smgr_rnode, forknum))));
+ errmsg("could not fsync file \"%s\": %m",
+ FilePathName(v->mdfd_vfd))));
v = v->mdfd_chain;
}
}
* Don't see one at the moment, but easy to change the test
* here if so.
*/
- path = relpath(entry->tag.rnode, entry->tag.forknum);
+ path = _mdfd_segpath(reln, entry->tag.forknum,
+ entry->tag.segno);
if (!FILE_POSSIBLY_DELETED(errno) ||
failures > 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not fsync segment %u of relation %s: %m",
- entry->tag.segno, path)));
+ errmsg("could not fsync file \"%s\": %m", path)));
else
ereport(DEBUG1,
(errcode_for_file_access(),
- errmsg("could not fsync segment %u of relation %s but retrying: %m",
- entry->tag.segno, path)));
+ errmsg("could not fsync file \"%s\" but retrying: %m",
+ path)));
pfree(path);
/*
if (errno != ENOENT)
ereport(WARNING,
(errcode_for_file_access(),
- errmsg("could not remove relation %s: %m", path)));
+ errmsg("could not remove file \"%s\": %m", path)));
}
pfree(path);
if (FileSync(seg->mdfd_vfd) < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not fsync segment %u of relation %s: %m",
- seg->mdfd_segno,
- relpath(reln->smgr_rnode, forknum))));
+ errmsg("could not fsync file \"%s\": %m",
+ FilePathName(seg->mdfd_vfd))));
}
}
}
/*
- * Open the specified segment of the relation,
- * and make a MdfdVec object for it. Returns NULL on failure.
+ * Return the filename for the specified segment of the relation. The
+ * returned string is palloc'd.
*/
-static MdfdVec *
-_mdfd_openseg(SMgrRelation reln, ForkNumber forknum, BlockNumber segno,
- int oflags)
+static char *
+_mdfd_segpath(SMgrRelation reln, ForkNumber forknum, BlockNumber segno)
{
- MdfdVec *v;
- int fd;
- char *path,
- *fullpath;
+ char *path,
+ *fullpath;
path = relpath(reln->smgr_rnode, forknum);
else
fullpath = path;
+ return fullpath;
+}
+
+/*
+ * Open the specified segment of the relation,
+ * and make a MdfdVec object for it. Returns NULL on failure.
+ */
+static MdfdVec *
+_mdfd_openseg(SMgrRelation reln, ForkNumber forknum, BlockNumber segno,
+ int oflags)
+{
+ MdfdVec *v;
+ int fd;
+ char *fullpath;
+
+ fullpath = _mdfd_segpath(reln, forknum, segno);
+
/* open the file */
fd = PathNameOpenFile(fullpath, O_RDWR | PG_BINARY | oflags, 0600);
return NULL;
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not open segment %u of relation %s (target block %u): %m",
- nextsegno,
- relpath(reln->smgr_rnode, forknum),
+ errmsg("could not open file \"%s\" (target block %u): %m",
+ _mdfd_segpath(reln, forknum, nextsegno),
blkno)));
}
}
if (len < 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not seek to end of segment %u of relation %s: %m",
- seg->mdfd_segno, relpath(reln->smgr_rnode, forknum))));
+ errmsg("could not seek to end of file \"%s\": %m",
+ FilePathName(seg->mdfd_vfd))));
/* note that this calculation will ignore any partial block at EOF */
return (BlockNumber) (len / BLCKSZ);
}