mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
New file naming. Database OID is used as "tablespace" id and
relation OID is used as file node on creation but may be changed later if required. Regression Tests Approved (c) -:)))
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.85 2000/09/29 03:55:45 inoue Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.86 2000/10/16 14:52:09 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -614,6 +614,9 @@ BufferAlloc(Relation reln,
|
||||
/* record the database name and relation name for this buffer */
|
||||
strcpy(buf->blind.dbname, DatabaseName);
|
||||
strcpy(buf->blind.relname, RelationGetPhysicalRelationName(reln));
|
||||
#ifndef OLD_FILE_NAMING
|
||||
buf->blind.rnode = reln->rd_node;
|
||||
#endif
|
||||
|
||||
INIT_BUFFERTAG(&(buf->tag), reln, blockNum);
|
||||
if (!BufTableInsert(buf))
|
||||
@@ -779,10 +782,12 @@ FlushBuffer(Buffer buffer, bool release)
|
||||
Assert(PrivateRefCount[buffer - 1] > 0); /* else caller didn't pin */
|
||||
|
||||
bufHdr = &BufferDescriptors[buffer - 1];
|
||||
|
||||
bufdb = bufHdr->tag.relId.dbId;
|
||||
|
||||
Assert(bufdb == MyDatabaseId || bufdb == (Oid) NULL);
|
||||
bufrel = RelationIdCacheGetRelation(bufHdr->tag.relId.relId);
|
||||
|
||||
Assert(bufrel != (Relation) NULL);
|
||||
|
||||
SharedBufferChanged = true;
|
||||
@@ -962,12 +967,18 @@ SetBufferDirtiedByMe(Buffer buffer, BufferDesc *bufHdr)
|
||||
|
||||
if (reln == (Relation) NULL)
|
||||
{
|
||||
#ifdef OLD_FILE_NAMING
|
||||
status = smgrblindmarkdirty(DEFAULT_SMGR,
|
||||
BufferBlindLastDirtied[buffer - 1].dbname,
|
||||
BufferBlindLastDirtied[buffer - 1].relname,
|
||||
tagLastDirtied->relId.dbId,
|
||||
tagLastDirtied->relId.relId,
|
||||
tagLastDirtied->blockNum);
|
||||
BufferBlindLastDirtied[buffer - 1].dbname,
|
||||
BufferBlindLastDirtied[buffer - 1].relname,
|
||||
tagLastDirtied->relId.dbId,
|
||||
tagLastDirtied->relId.relId,
|
||||
tagLastDirtied->blockNum);
|
||||
#else
|
||||
status = smgrblindmarkdirty(DEFAULT_SMGR,
|
||||
BufferBlindLastDirtied[buffer - 1].rnode,
|
||||
tagLastDirtied->blockNum);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1017,10 +1028,10 @@ ClearBufferDirtiedByMe(Buffer buffer, BufferDesc *bufHdr)
|
||||
* the data we just wrote. This is unlikely, but possible if some
|
||||
* other backend replaced the buffer contents since we set our flag.
|
||||
*/
|
||||
if (bufHdr->tag.relId.dbId == tagLastDirtied->relId.dbId &&
|
||||
bufHdr->tag.relId.relId == tagLastDirtied->relId.relId &&
|
||||
bufHdr->tag.blockNum == tagLastDirtied->blockNum)
|
||||
BufferDirtiedByMe[buffer - 1] = false;
|
||||
if (bufHdr->tag.relId.dbId == tagLastDirtied->relId.dbId &&
|
||||
bufHdr->tag.relId.relId == tagLastDirtied->relId.relId &&
|
||||
bufHdr->tag.blockNum == tagLastDirtied->blockNum)
|
||||
BufferDirtiedByMe[buffer - 1] = false;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1136,13 +1147,21 @@ BufferSync()
|
||||
*/
|
||||
if (reln == (Relation) NULL)
|
||||
{
|
||||
#ifdef OLD_FILE_NAMING
|
||||
status = smgrblindwrt(DEFAULT_SMGR,
|
||||
bufHdr->blind.dbname,
|
||||
bufHdr->blind.relname,
|
||||
bufdb, bufrel,
|
||||
bufHdr->tag.blockNum,
|
||||
(char *) MAKE_PTR(bufHdr->data),
|
||||
true); /* must fsync */
|
||||
bufHdr->blind.dbname,
|
||||
bufHdr->blind.relname,
|
||||
bufdb, bufrel,
|
||||
bufHdr->tag.blockNum,
|
||||
(char *) MAKE_PTR(bufHdr->data),
|
||||
true); /* must fsync */
|
||||
#else
|
||||
status = smgrblindwrt(DEFAULT_SMGR,
|
||||
bufHdr->blind.rnode,
|
||||
bufHdr->tag.blockNum,
|
||||
(char *) MAKE_PTR(bufHdr->data),
|
||||
true); /* must fsync */
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1202,12 +1221,18 @@ BufferSync()
|
||||
reln = RelationIdCacheGetRelation(BufferTagLastDirtied[i].relId.relId);
|
||||
if (reln == (Relation) NULL)
|
||||
{
|
||||
#ifdef OLD_FILE_NAMING
|
||||
status = smgrblindmarkdirty(DEFAULT_SMGR,
|
||||
BufferBlindLastDirtied[i].dbname,
|
||||
BufferBlindLastDirtied[i].relname,
|
||||
BufferTagLastDirtied[i].relId.dbId,
|
||||
BufferTagLastDirtied[i].relId.relId,
|
||||
BufferTagLastDirtied[i].blockNum);
|
||||
BufferBlindLastDirtied[i].dbname,
|
||||
BufferBlindLastDirtied[i].relname,
|
||||
BufferTagLastDirtied[i].relId.dbId,
|
||||
BufferTagLastDirtied[i].relId.relId,
|
||||
BufferTagLastDirtied[i].blockNum);
|
||||
#else
|
||||
status = smgrblindmarkdirty(DEFAULT_SMGR,
|
||||
BufferBlindLastDirtied[i].rnode,
|
||||
BufferTagLastDirtied[i].blockNum);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1556,11 +1581,18 @@ BufferReplace(BufferDesc *bufHdr)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef OLD_FILE_NAMING
|
||||
status = smgrblindwrt(DEFAULT_SMGR, bufHdr->blind.dbname,
|
||||
bufHdr->blind.relname, bufdb, bufrel,
|
||||
bufHdr->tag.blockNum,
|
||||
(char *) MAKE_PTR(bufHdr->data),
|
||||
false); /* no fsync */
|
||||
#else
|
||||
status = smgrblindwrt(DEFAULT_SMGR, bufHdr->blind.rnode,
|
||||
bufHdr->tag.blockNum,
|
||||
(char *) MAKE_PTR(bufHdr->data),
|
||||
false); /* no fsync */
|
||||
#endif
|
||||
}
|
||||
|
||||
LockBuffer(BufferDescriptorGetBuffer(bufHdr), BUFFER_LOCK_UNLOCK);
|
||||
@@ -1784,8 +1816,8 @@ blockNum=%d, flags=0x%x, refcount=%d %ld)",
|
||||
for (i = 0; i < NBuffers; ++i, ++buf)
|
||||
{
|
||||
printf("[%-2d] (%s, %d) flags=0x%x, refcnt=%d %ld)\n",
|
||||
i, buf->blind.relname, buf->tag.blockNum,
|
||||
buf->flags, buf->refcount, PrivateRefCount[i]);
|
||||
i, buf->blind.relname, buf->tag.blockNum,
|
||||
buf->flags, buf->refcount, PrivateRefCount[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.74 2000/07/17 03:05:11 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.75 2000/10/16 14:52:12 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -75,8 +75,14 @@ static void mdclose_fd(int fd);
|
||||
static int _mdfd_getrelnfd(Relation reln);
|
||||
static MdfdVec *_mdfd_openseg(Relation reln, int segno, int oflags);
|
||||
static MdfdVec *_mdfd_getseg(Relation reln, int blkno);
|
||||
|
||||
#ifdef OLD_FILE_NAMING
|
||||
static int _mdfd_blind_getseg(char *dbname, char *relname,
|
||||
Oid dbid, Oid relid, int blkno);
|
||||
#else
|
||||
static int _mdfd_blind_getseg(RelFileNode rnode, int blkno);
|
||||
#endif
|
||||
|
||||
static int _fdvec_alloc(void);
|
||||
static void _fdvec_free(int);
|
||||
static BlockNumber _mdnblocks(File file, Size blcksz);
|
||||
@@ -128,7 +134,11 @@ mdcreate(Relation reln)
|
||||
|
||||
Assert(reln->rd_unlinked && reln->rd_fd < 0);
|
||||
|
||||
#ifdef OLD_FILE_NAMING
|
||||
path = relpath(RelationGetPhysicalRelationName(reln));
|
||||
#else
|
||||
path = relpath(reln->rd_node);
|
||||
#endif
|
||||
fd = FileNameOpenFile(path, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, 0600);
|
||||
|
||||
/*
|
||||
@@ -326,7 +336,11 @@ mdopen(Relation reln)
|
||||
int vfd;
|
||||
|
||||
Assert(reln->rd_fd < 0);
|
||||
#ifdef OLD_FILE_NAMING
|
||||
path = relpath(RelationGetPhysicalRelationName(reln));
|
||||
#else
|
||||
path = relpath(reln->rd_node);
|
||||
#endif
|
||||
|
||||
fd = FileNameOpenFile(path, O_RDWR | PG_BINARY, 0600);
|
||||
if (fd < 0)
|
||||
@@ -565,6 +579,7 @@ mdflush(Relation reln, BlockNumber blocknum, char *buffer)
|
||||
* the file, making it more like mdflush().
|
||||
*/
|
||||
int
|
||||
#ifdef OLD_FILE_NAMING
|
||||
mdblindwrt(char *dbname,
|
||||
char *relname,
|
||||
Oid dbid,
|
||||
@@ -572,12 +587,22 @@ mdblindwrt(char *dbname,
|
||||
BlockNumber blkno,
|
||||
char *buffer,
|
||||
bool dofsync)
|
||||
#else
|
||||
mdblindwrt(RelFileNode rnode,
|
||||
BlockNumber blkno,
|
||||
char *buffer,
|
||||
bool dofsync)
|
||||
#endif
|
||||
{
|
||||
int status;
|
||||
long seekpos;
|
||||
int fd;
|
||||
|
||||
#ifdef OLD_FILE_NAMING
|
||||
fd = _mdfd_blind_getseg(dbname, relname, dbid, relid, blkno);
|
||||
#else
|
||||
fd = _mdfd_blind_getseg(rnode, blkno);
|
||||
#endif
|
||||
|
||||
if (fd < 0)
|
||||
return SM_FAIL;
|
||||
@@ -651,16 +676,25 @@ mdmarkdirty(Relation reln, BlockNumber blkno)
|
||||
* rather than building md/fd datastructures to postpone it till later.
|
||||
*/
|
||||
int
|
||||
#ifdef OLD_FILE_NAMING
|
||||
mdblindmarkdirty(char *dbname,
|
||||
char *relname,
|
||||
Oid dbid,
|
||||
Oid relid,
|
||||
BlockNumber blkno)
|
||||
#else
|
||||
mdblindmarkdirty(RelFileNode rnode,
|
||||
BlockNumber blkno)
|
||||
#endif
|
||||
{
|
||||
int status;
|
||||
int fd;
|
||||
|
||||
#ifdef OLD_FILE_NAMING
|
||||
fd = _mdfd_blind_getseg(dbname, relname, dbid, relid, blkno);
|
||||
#else
|
||||
fd = _mdfd_blind_getseg(rnode, blkno);
|
||||
#endif
|
||||
|
||||
if (fd < 0)
|
||||
return SM_FAIL;
|
||||
@@ -969,7 +1003,11 @@ _mdfd_openseg(Relation reln, int segno, int oflags)
|
||||
*fullpath;
|
||||
|
||||
/* be sure we have enough space for the '.segno', if any */
|
||||
#ifdef OLD_FILE_NAMING
|
||||
path = relpath(RelationGetPhysicalRelationName(reln));
|
||||
#else
|
||||
path = relpath(reln->rd_node);
|
||||
#endif
|
||||
|
||||
if (segno > 0)
|
||||
{
|
||||
@@ -1084,8 +1122,12 @@ _mdfd_getseg(Relation reln, int blkno)
|
||||
*/
|
||||
|
||||
static int
|
||||
#ifdef OLD_FILE_NAMING
|
||||
_mdfd_blind_getseg(char *dbname, char *relname, Oid dbid, Oid relid,
|
||||
int blkno)
|
||||
#else
|
||||
_mdfd_blind_getseg(RelFileNode rnode, int blkno)
|
||||
#endif
|
||||
{
|
||||
char *path;
|
||||
int fd;
|
||||
@@ -1095,8 +1137,12 @@ _mdfd_blind_getseg(char *dbname, char *relname, Oid dbid, Oid relid,
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef OLD_FILE_NAMING
|
||||
/* construct the path to the relation */
|
||||
path = relpath_blind(dbname, relname, dbid, relid);
|
||||
#else
|
||||
path = relpath(rnode);
|
||||
#endif
|
||||
|
||||
#ifndef LET_OS_MANAGE_FILESIZE
|
||||
/* append the '.segno', if needed */
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.39 2000/10/02 21:45:33 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.40 2000/10/16 14:52:12 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -36,14 +36,23 @@ typedef struct f_smgr
|
||||
char *buffer);
|
||||
int (*smgr_flush) (Relation reln, BlockNumber blocknum,
|
||||
char *buffer);
|
||||
#ifdef OLD_FILE_NAMING
|
||||
int (*smgr_blindwrt) (char *dbname, char *relname,
|
||||
Oid dbid, Oid relid,
|
||||
BlockNumber blkno, char *buffer,
|
||||
bool dofsync);
|
||||
#else
|
||||
int (*smgr_blindwrt) (RelFileNode rnode, BlockNumber blkno,
|
||||
char *buffer, bool dofsync);
|
||||
#endif
|
||||
int (*smgr_markdirty) (Relation reln, BlockNumber blkno);
|
||||
#ifdef OLD_FILE_NAMING
|
||||
int (*smgr_blindmarkdirty) (char *dbname, char *relname,
|
||||
Oid dbid, Oid relid,
|
||||
BlockNumber blkno);
|
||||
#else
|
||||
int (*smgr_blindmarkdirty) (RelFileNode, BlockNumber blkno);
|
||||
#endif
|
||||
int (*smgr_nblocks) (Relation reln);
|
||||
int (*smgr_truncate) (Relation reln, int nblocks);
|
||||
int (*smgr_commit) (void); /* may be NULL */
|
||||
@@ -301,6 +310,7 @@ smgrflush(int16 which, Relation reln, BlockNumber blocknum, char *buffer)
|
||||
* this page down to stable storage in this circumstance. The
|
||||
* write should be synchronous if dofsync is true.
|
||||
*/
|
||||
#ifdef OLD_FILE_NAMING
|
||||
int
|
||||
smgrblindwrt(int16 which,
|
||||
char *dbname,
|
||||
@@ -332,6 +342,27 @@ smgrblindwrt(int16 which,
|
||||
return status;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
smgrblindwrt(int16 which,
|
||||
RelFileNode rnode,
|
||||
BlockNumber blkno,
|
||||
char *buffer,
|
||||
bool dofsync)
|
||||
{
|
||||
int status;
|
||||
|
||||
status = (*(smgrsw[which].smgr_blindwrt)) (rnode, blkno, buffer, dofsync);
|
||||
|
||||
if (status == SM_FAIL)
|
||||
elog(ERROR, "cannot write block %d of %u/%u blind: %m",
|
||||
blkno, rnode.tblNode, rnode.relNode);
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* smgrmarkdirty() -- Mark a page dirty (needs fsync).
|
||||
*
|
||||
@@ -363,6 +394,7 @@ smgrmarkdirty(int16 which,
|
||||
*
|
||||
* Just like smgrmarkdirty, except we don't have a reldesc.
|
||||
*/
|
||||
#ifdef OLD_FILE_NAMING
|
||||
int
|
||||
smgrblindmarkdirty(int16 which,
|
||||
char *dbname,
|
||||
@@ -393,6 +425,25 @@ smgrblindmarkdirty(int16 which,
|
||||
return status;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
smgrblindmarkdirty(int16 which,
|
||||
RelFileNode rnode,
|
||||
BlockNumber blkno)
|
||||
{
|
||||
int status;
|
||||
|
||||
status = (*(smgrsw[which].smgr_blindmarkdirty)) (rnode, blkno);
|
||||
|
||||
if (status == SM_FAIL)
|
||||
elog(ERROR, "cannot mark block %d of %u/%u blind: %m",
|
||||
blkno, rnode.tblNode, rnode.relNode);
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* smgrnblocks() -- Calculate the number of POSTGRES blocks in the
|
||||
* supplied relation.
|
||||
|
||||
Reference in New Issue
Block a user