mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
WAL
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.91 2000/10/23 04:10:06 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.92 2000/10/28 16:20:55 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -42,6 +42,13 @@
|
||||
* freelist.c -- chooses victim for buffer replacement
|
||||
* buf_table.c -- manages the buffer lookup table
|
||||
*/
|
||||
|
||||
#ifdef XLOG
|
||||
|
||||
#include "xlog_bufmgr.c"
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <math.h>
|
||||
@@ -2512,3 +2519,5 @@ MarkBufferForCleanup(Buffer buffer, void (*CleanupFunc)(Buffer))
|
||||
SpinRelease(BufMgrLock);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* ! XLOG */
|
||||
|
||||
@@ -16,10 +16,17 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.32 2000/10/23 04:10:06 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/localbuf.c,v 1.33 2000/10/28 16:20:56 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifdef XLOG
|
||||
|
||||
#include "xlog_localbuf.c"
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <math.h>
|
||||
@@ -247,10 +254,11 @@ InitLocalBuffer(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* LocalBufferSync -
|
||||
* flush all dirty buffers in the local buffer cache. Since the buffer
|
||||
* cache is only used for keeping relations visible during a transaction,
|
||||
* we will not need these buffers again.
|
||||
* LocalBufferSync
|
||||
*
|
||||
* Flush all dirty buffers in the local buffer cache at commit time.
|
||||
* Since the buffer cache is only used for keeping relations visible
|
||||
* during a transaction, we will not need these buffers again.
|
||||
*/
|
||||
void
|
||||
LocalBufferSync(void)
|
||||
@@ -303,3 +311,5 @@ ResetLocalBufferPool(void)
|
||||
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
|
||||
nextFreeLocalBuf = 0;
|
||||
}
|
||||
|
||||
#endif /* XLOG */
|
||||
|
||||
2205
src/backend/storage/buffer/xlog_bufmgr.c
Normal file
2205
src/backend/storage/buffer/xlog_bufmgr.c
Normal file
File diff suppressed because it is too large
Load Diff
274
src/backend/storage/buffer/xlog_localbuf.c
Normal file
274
src/backend/storage/buffer/xlog_localbuf.c
Normal file
@@ -0,0 +1,274 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* localbuf.c
|
||||
* local buffer manager. Fast buffer manager for temporary tables
|
||||
* or special cases when the operation is not visible to other backends.
|
||||
*
|
||||
* When a relation is being created, the descriptor will have rd_islocal
|
||||
* set to indicate that the local buffer manager should be used. During
|
||||
* the same transaction the relation is being created, any inserts or
|
||||
* selects from the newly created relation will use the local buffer
|
||||
* pool. rd_islocal is reset at the end of a transaction (commit/abort).
|
||||
* This is useful for queries like SELECT INTO TABLE and create index.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||
* Portions Copyright (c) 1994-5, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/Attic/xlog_localbuf.c,v 1.1 2000/10/28 16:20:56 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "executor/execdebug.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "utils/relcache.h"
|
||||
|
||||
extern long int LocalBufferFlushCount;
|
||||
|
||||
int NLocBuffer = 64;
|
||||
BufferDesc *LocalBufferDescriptors = NULL;
|
||||
long *LocalRefCount = NULL;
|
||||
|
||||
static int nextFreeLocalBuf = 0;
|
||||
|
||||
/*#define LBDEBUG*/
|
||||
|
||||
/*
|
||||
* LocalBufferAlloc -
|
||||
* allocate a local buffer. We do round robin allocation for now.
|
||||
*/
|
||||
BufferDesc *
|
||||
LocalBufferAlloc(Relation reln, BlockNumber blockNum, bool *foundPtr)
|
||||
{
|
||||
int i;
|
||||
BufferDesc *bufHdr = (BufferDesc *) NULL;
|
||||
|
||||
if (blockNum == P_NEW)
|
||||
{
|
||||
blockNum = reln->rd_nblocks;
|
||||
reln->rd_nblocks++;
|
||||
}
|
||||
|
||||
/* a low tech search for now -- not optimized for scans */
|
||||
for (i = 0; i < NLocBuffer; i++)
|
||||
{
|
||||
if (LocalBufferDescriptors[i].tag.rnode.relNode ==
|
||||
reln->rd_node.relNode &&
|
||||
LocalBufferDescriptors[i].tag.blockNum == blockNum)
|
||||
{
|
||||
|
||||
#ifdef LBDEBUG
|
||||
fprintf(stderr, "LB ALLOC (%u,%d) %d\n",
|
||||
RelationGetRelid(reln), blockNum, -i - 1);
|
||||
#endif
|
||||
LocalRefCount[i]++;
|
||||
*foundPtr = TRUE;
|
||||
return &LocalBufferDescriptors[i];
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LBDEBUG
|
||||
fprintf(stderr, "LB ALLOC (%u,%d) %d\n",
|
||||
RelationGetRelid(reln), blockNum, -nextFreeLocalBuf - 1);
|
||||
#endif
|
||||
|
||||
/* need to get a new buffer (round robin for now) */
|
||||
for (i = 0; i < NLocBuffer; i++)
|
||||
{
|
||||
int b = (nextFreeLocalBuf + i) % NLocBuffer;
|
||||
|
||||
if (LocalRefCount[b] == 0)
|
||||
{
|
||||
bufHdr = &LocalBufferDescriptors[b];
|
||||
LocalRefCount[b]++;
|
||||
nextFreeLocalBuf = (b + 1) % NLocBuffer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bufHdr == NULL)
|
||||
elog(ERROR, "no empty local buffer.");
|
||||
|
||||
/*
|
||||
* this buffer is not referenced but it might still be dirty (the last
|
||||
* transaction to touch it doesn't need its contents but has not
|
||||
* flushed it). if that's the case, write it out before reusing it!
|
||||
*/
|
||||
if (bufHdr->flags & BM_DIRTY || bufHdr->cntxDirty)
|
||||
{
|
||||
Relation bufrel = RelationNodeCacheGetRelation(bufHdr->tag.rnode);
|
||||
|
||||
Assert(bufrel != NULL);
|
||||
|
||||
/* flush this page */
|
||||
smgrwrite(DEFAULT_SMGR, bufrel, bufHdr->tag.blockNum,
|
||||
(char *) MAKE_PTR(bufHdr->data));
|
||||
LocalBufferFlushCount++;
|
||||
|
||||
/*
|
||||
* drop relcache refcount incremented by
|
||||
* RelationIdCacheGetRelation
|
||||
*/
|
||||
RelationDecrementReferenceCount(bufrel);
|
||||
}
|
||||
|
||||
/*
|
||||
* it's all ours now.
|
||||
*
|
||||
* We need not in tblNode currently but will in future I think,
|
||||
* when we'll give up rel->rd_fd to fmgr cache.
|
||||
*/
|
||||
bufHdr->tag.rnode = reln->rd_node;
|
||||
bufHdr->tag.blockNum = blockNum;
|
||||
bufHdr->flags &= ~BM_DIRTY;
|
||||
bufHdr->cntxDirty = false;
|
||||
|
||||
/*
|
||||
* lazy memory allocation. (see MAKE_PTR for why we need to do
|
||||
* MAKE_OFFSET.)
|
||||
*/
|
||||
if (bufHdr->data == (SHMEM_OFFSET) 0)
|
||||
{
|
||||
char *data = (char *) malloc(BLCKSZ);
|
||||
|
||||
bufHdr->data = MAKE_OFFSET(data);
|
||||
}
|
||||
|
||||
*foundPtr = FALSE;
|
||||
return bufHdr;
|
||||
}
|
||||
|
||||
/*
|
||||
* WriteLocalBuffer -
|
||||
* writes out a local buffer
|
||||
*/
|
||||
int
|
||||
WriteLocalBuffer(Buffer buffer, bool release)
|
||||
{
|
||||
int bufid;
|
||||
|
||||
Assert(BufferIsLocal(buffer));
|
||||
|
||||
#ifdef LBDEBUG
|
||||
fprintf(stderr, "LB WRITE %d\n", buffer);
|
||||
#endif
|
||||
|
||||
bufid = -(buffer + 1);
|
||||
LocalBufferDescriptors[bufid].flags |= BM_DIRTY;
|
||||
|
||||
if (release)
|
||||
{
|
||||
Assert(LocalRefCount[bufid] > 0);
|
||||
LocalRefCount[bufid]--;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* InitLocalBuffer -
|
||||
* init the local buffer cache. Since most queries (esp. multi-user ones)
|
||||
* don't involve local buffers, we delay allocating memory for actual the
|
||||
* buffer until we need it.
|
||||
*/
|
||||
void
|
||||
InitLocalBuffer(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* these aren't going away. I'm not gonna use palloc.
|
||||
*/
|
||||
LocalBufferDescriptors =
|
||||
(BufferDesc *) malloc(sizeof(BufferDesc) * NLocBuffer);
|
||||
MemSet(LocalBufferDescriptors, 0, sizeof(BufferDesc) * NLocBuffer);
|
||||
nextFreeLocalBuf = 0;
|
||||
|
||||
for (i = 0; i < NLocBuffer; i++)
|
||||
{
|
||||
BufferDesc *buf = &LocalBufferDescriptors[i];
|
||||
|
||||
/*
|
||||
* negative to indicate local buffer. This is tricky: shared
|
||||
* buffers start with 0. We have to start with -2. (Note that the
|
||||
* routine BufferDescriptorGetBuffer adds 1 to buf_id so our first
|
||||
* buffer id is -1.)
|
||||
*/
|
||||
buf->buf_id = -i - 2;
|
||||
}
|
||||
|
||||
LocalRefCount = (long *) malloc(sizeof(long) * NLocBuffer);
|
||||
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
|
||||
}
|
||||
|
||||
/*
|
||||
* LocalBufferSync
|
||||
*
|
||||
* Flush all dirty buffers in the local buffer cache at commit time.
|
||||
* Since the buffer cache is only used for keeping relations visible
|
||||
* during a transaction, we will not need these buffers again.
|
||||
*
|
||||
* Note that we have to *flush* local buffers because of them are not
|
||||
* visible to checkpoint makers. But we can skip XLOG flush check.
|
||||
*/
|
||||
void
|
||||
LocalBufferSync(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NLocBuffer; i++)
|
||||
{
|
||||
BufferDesc *buf = &LocalBufferDescriptors[i];
|
||||
Relation bufrel;
|
||||
|
||||
if (buf->flags & BM_DIRTY || buf->cntxDirty)
|
||||
{
|
||||
#ifdef LBDEBUG
|
||||
fprintf(stderr, "LB SYNC %d\n", -i - 1);
|
||||
#endif
|
||||
bufrel = RelationNodeCacheGetRelation(buf->tag.rnode);
|
||||
|
||||
Assert(bufrel != NULL);
|
||||
|
||||
smgrwrite(DEFAULT_SMGR, bufrel, buf->tag.blockNum,
|
||||
(char *) MAKE_PTR(buf->data));
|
||||
smgrmarkdirty(DEFAULT_SMGR, bufrel, buf->tag.blockNum);
|
||||
LocalBufferFlushCount++;
|
||||
|
||||
/* drop relcache refcount from RelationIdCacheGetRelation */
|
||||
RelationDecrementReferenceCount(bufrel);
|
||||
|
||||
buf->flags &= ~BM_DIRTY;
|
||||
buf->cntxDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
|
||||
nextFreeLocalBuf = 0;
|
||||
}
|
||||
|
||||
void
|
||||
ResetLocalBufferPool(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NLocBuffer; i++)
|
||||
{
|
||||
BufferDesc *buf = &LocalBufferDescriptors[i];
|
||||
|
||||
buf->tag.rnode.relNode = InvalidOid;
|
||||
buf->flags &= ~BM_DIRTY;
|
||||
buf->cntxDirty = false;
|
||||
buf->buf_id = -i - 2;
|
||||
}
|
||||
|
||||
MemSet(LocalRefCount, 0, sizeof(long) * NLocBuffer);
|
||||
nextFreeLocalBuf = 0;
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.64 2000/10/02 19:42:47 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.65 2000/10/28 16:20:56 vadim Exp $
|
||||
*
|
||||
* NOTES:
|
||||
*
|
||||
@@ -823,8 +823,10 @@ FileWrite(File file, char *buffer, int amount)
|
||||
if (returnCode > 0)
|
||||
{
|
||||
VfdCache[file].seekPos += returnCode;
|
||||
#ifndef XLOG
|
||||
/* mark the file as needing fsync */
|
||||
VfdCache[file].fdstate |= FD_DIRTY;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
VfdCache[file].seekPos = FileUnknownPos;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.76 2000/10/20 11:01:11 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.77 2000/10/28 16:20:57 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -76,12 +76,7 @@ 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);
|
||||
@@ -134,11 +129,7 @@ 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);
|
||||
|
||||
/*
|
||||
@@ -336,11 +327,7 @@ 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)
|
||||
@@ -579,30 +566,16 @@ 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,
|
||||
Oid relid,
|
||||
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;
|
||||
@@ -676,25 +649,13 @@ 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;
|
||||
@@ -915,6 +876,22 @@ mdabort()
|
||||
return SM_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef XLOG
|
||||
/*
|
||||
* mdsync() -- Sync storage.
|
||||
*
|
||||
*/
|
||||
int
|
||||
mdsync()
|
||||
{
|
||||
sync();
|
||||
if (IsUnderPostmaster)
|
||||
sleep(2);
|
||||
sync();
|
||||
return SM_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* _fdvec_alloc () -- grab a free (or new) md file descriptor vector.
|
||||
*
|
||||
@@ -996,11 +973,7 @@ _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)
|
||||
{
|
||||
@@ -1115,12 +1088,7 @@ _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;
|
||||
@@ -1130,12 +1098,7 @@ _mdfd_blind_getseg(RelFileNode rnode, int blkno)
|
||||
|
||||
#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.41 2000/10/21 15:43:31 vadim Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.42 2000/10/28 16:20:57 vadim Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -36,27 +36,17 @@ 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 */
|
||||
int (*smgr_abort) (void); /* may be NULL */
|
||||
#ifdef XLOG
|
||||
int (*smgr_sync) (void);
|
||||
#endif
|
||||
} f_smgr;
|
||||
|
||||
/*
|
||||
@@ -69,7 +59,11 @@ static f_smgr smgrsw[] = {
|
||||
/* magnetic disk */
|
||||
{mdinit, NULL, mdcreate, mdunlink, mdextend, mdopen, mdclose,
|
||||
mdread, mdwrite, mdflush, mdblindwrt, mdmarkdirty, mdblindmarkdirty,
|
||||
#ifdef XLOG
|
||||
mdnblocks, mdtruncate, mdcommit, mdabort, mdsync},
|
||||
#else
|
||||
mdnblocks, mdtruncate, mdcommit, mdabort},
|
||||
#endif
|
||||
|
||||
#ifdef STABLE_MEMORY_STORAGE
|
||||
/* main memory */
|
||||
@@ -310,40 +304,6 @@ 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,
|
||||
char *relname,
|
||||
Oid dbid,
|
||||
Oid relid,
|
||||
BlockNumber blkno,
|
||||
char *buffer,
|
||||
bool dofsync)
|
||||
{
|
||||
char *dbstr;
|
||||
char *relstr;
|
||||
int status;
|
||||
|
||||
/* strdup here is probably redundant */
|
||||
dbstr = pstrdup(dbname);
|
||||
relstr = pstrdup(relname);
|
||||
|
||||
status = (*(smgrsw[which].smgr_blindwrt)) (dbstr, relstr, dbid, relid,
|
||||
blkno, buffer, dofsync);
|
||||
|
||||
if (status == SM_FAIL)
|
||||
elog(ERROR, "cannot write block %d of %s [%s] blind: %m",
|
||||
blkno, relstr, dbstr);
|
||||
|
||||
pfree(dbstr);
|
||||
pfree(relstr);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
smgrblindwrt(int16 which,
|
||||
RelFileNode rnode,
|
||||
@@ -361,7 +321,6 @@ smgrblindwrt(int16 which,
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* smgrmarkdirty() -- Mark a page dirty (needs fsync).
|
||||
@@ -394,39 +353,6 @@ smgrmarkdirty(int16 which,
|
||||
*
|
||||
* Just like smgrmarkdirty, except we don't have a reldesc.
|
||||
*/
|
||||
#ifdef OLD_FILE_NAMING
|
||||
int
|
||||
smgrblindmarkdirty(int16 which,
|
||||
char *dbname,
|
||||
char *relname,
|
||||
Oid dbid,
|
||||
Oid relid,
|
||||
BlockNumber blkno)
|
||||
{
|
||||
char *dbstr;
|
||||
char *relstr;
|
||||
int status;
|
||||
|
||||
/* strdup here is probably redundant */
|
||||
dbstr = pstrdup(dbname);
|
||||
relstr = pstrdup(relname);
|
||||
|
||||
status = (*(smgrsw[which].smgr_blindmarkdirty)) (dbstr, relstr,
|
||||
dbid, relid,
|
||||
blkno);
|
||||
|
||||
if (status == SM_FAIL)
|
||||
elog(ERROR, "cannot mark block %d of %s [%s] blind: %m",
|
||||
blkno, relstr, dbstr);
|
||||
|
||||
pfree(dbstr);
|
||||
pfree(relstr);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
smgrblindmarkdirty(int16 which,
|
||||
RelFileNode rnode,
|
||||
@@ -442,7 +368,6 @@ smgrblindmarkdirty(int16 which,
|
||||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* smgrnblocks() -- Calculate the number of POSTGRES blocks in the
|
||||
@@ -528,6 +453,27 @@ smgrabort()
|
||||
return SM_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef XLOG
|
||||
int
|
||||
smgrsync()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NSmgr; i++)
|
||||
{
|
||||
if (smgrsw[i].smgr_sync)
|
||||
{
|
||||
if ((*(smgrsw[i].smgr_sync)) () == SM_FAIL)
|
||||
elog(STOP, "storage sync failed on %s: %m",
|
||||
DatumGetCString(DirectFunctionCall1(smgrout,
|
||||
Int16GetDatum(i))));
|
||||
}
|
||||
}
|
||||
|
||||
return SM_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NOT_USED
|
||||
bool
|
||||
smgriswo(int16 smgrno)
|
||||
|
||||
Reference in New Issue
Block a user