PostgreSQL Source Code
git master
|
#include "postgres.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/file.h>
#include "access/xlog.h"
#include "access/xlogutils.h"
#include "commands/tablespace.h"
#include "miscadmin.h"
#include "pg_trace.h"
#include "pgstat.h"
#include "postmaster/bgwriter.h"
#include "storage/bufmgr.h"
#include "storage/fd.h"
#include "storage/md.h"
#include "storage/relfilenode.h"
#include "storage/smgr.h"
#include "storage/sync.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
Go to the source code of this file.
Data Structures | |
struct | _MdfdVec |
Macros | |
#define | INIT_MD_FILETAG(a, xx_rnode, xx_forknum, xx_segno) |
#define | EXTENSION_FAIL (1 << 0) |
#define | EXTENSION_RETURN_NULL (1 << 1) |
#define | EXTENSION_CREATE (1 << 2) |
#define | EXTENSION_CREATE_RECOVERY (1 << 3) |
#define | EXTENSION_DONT_CHECK_SIZE (1 << 4) |
Typedefs | |
typedef struct _MdfdVec | MdfdVec |
Variables | |
static MemoryContext | MdCxt |
#define EXTENSION_CREATE (1 << 2) |
Definition at line 108 of file md.c.
Referenced by _mdfd_getseg(), and mdextend().
#define EXTENSION_CREATE_RECOVERY (1 << 3) |
Definition at line 110 of file md.c.
Referenced by _mdfd_getseg(), mdread(), and mdwrite().
#define EXTENSION_DONT_CHECK_SIZE (1 << 4) |
Definition at line 118 of file md.c.
Referenced by _mdfd_getseg().
#define EXTENSION_FAIL (1 << 0) |
Definition at line 104 of file md.c.
Referenced by _mdfd_getseg(), mdnblocks(), mdprefetch(), mdread(), and mdwrite().
#define EXTENSION_RETURN_NULL (1 << 1) |
Definition at line 106 of file md.c.
Referenced by _mdfd_getseg(), mdexists(), mdopenfork(), mdprefetch(), and mdwriteback().
#define INIT_MD_FILETAG | ( | a, | |
xx_rnode, | |||
xx_forknum, | |||
xx_segno | |||
) |
Definition at line 92 of file md.c.
Referenced by ForgetDatabaseSyncRequests(), register_dirty_segment(), register_forget_request(), and register_unlink_segment().
|
static |
Definition at line 1081 of file md.c.
References SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, MemoryContextAlloc(), pfree(), and repalloc().
Referenced by _mdfd_openseg(), mdclose(), mdcreate(), mdimmedsync(), mdopenfork(), and mdtruncate().
|
static |
Definition at line 1187 of file md.c.
References _mdfd_openseg(), _mdfd_segpath(), _mdnblocks(), Assert, elog, ereport, errcode_for_file_access(), errmsg(), ERROR, EXTENSION_CREATE, EXTENSION_CREATE_RECOVERY, EXTENSION_DONT_CHECK_SIZE, EXTENSION_FAIL, EXTENSION_RETURN_NULL, FATAL, FILE_POSSIBLY_DELETED, InRecovery, SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, mdextend(), _MdfdVec::mdfd_segno, mdopenfork(), palloc0(), and pfree().
Referenced by mdextend(), mdprefetch(), mdread(), mdwrite(), and mdwriteback().
|
static |
Definition at line 1142 of file md.c.
References _fdvec_resize(), _mdfd_segpath(), _mdnblocks(), Assert, fd(), SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_segno, _MdfdVec::mdfd_vfd, PathNameOpenFile(), pfree(), and PG_BINARY.
Referenced by _mdfd_getseg(), mdimmedsync(), and mdnblocks().
|
static |
Definition at line 1119 of file md.c.
References pfree(), psprintf(), relpath, and SMgrRelationData::smgr_rnode.
Referenced by _mdfd_getseg(), _mdfd_openseg(), and mdsyncfiletag().
|
static |
Definition at line 1312 of file md.c.
References ereport, errcode_for_file_access(), errmsg(), ERROR, FilePathName(), FileSize(), and _MdfdVec::mdfd_vfd.
Referenced by _mdfd_getseg(), _mdfd_openseg(), mdextend(), mdnblocks(), and mdopenfork().
|
static |
Definition at line 293 of file md.c.
References ereport, errcode_for_file_access(), errmsg(), pg_truncate(), and WARNING.
Referenced by mdunlinkfork().
void DropRelationFiles | ( | RelFileNode * | delrels, |
int | ndelrels, | ||
bool | isRedo | ||
) |
Definition at line 1049 of file md.c.
References i, InvalidBackendId, MAX_FORKNUM, palloc(), pfree(), smgrclose(), smgrdounlinkall(), smgropen(), and XLogDropRelation().
Referenced by FinishPreparedTransaction(), xact_redo_abort(), and xact_redo_commit().
void ForgetDatabaseSyncRequests | ( | Oid | dbid | ) |
Definition at line 1031 of file md.c.
References RelFileNode::dbNode, INIT_MD_FILETAG, InvalidBlockNumber, InvalidForkNumber, RegisterSyncRequest(), RelFileNode::relNode, RelFileNode::spcNode, and SYNC_FILTER_REQUEST.
Referenced by dbase_redo(), and dropdb().
void mdclose | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 532 of file md.c.
References _fdvec_resize(), FileClose(), SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, and _MdfdVec::mdfd_vfd.
Referenced by mdexists().
void mdcreate | ( | SMgrRelation | reln, |
ForkNumber | forkNum, | ||
bool | isRedo | ||
) |
Definition at line 178 of file md.c.
References _fdvec_resize(), Assert, RelFileNode::dbNode, ereport, errcode_for_file_access(), errmsg(), ERROR, fd(), SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_segno, _MdfdVec::mdfd_vfd, RelFileNodeBackend::node, PathNameOpenFile(), pfree(), PG_BINARY, relpath, SMgrRelationData::smgr_rnode, RelFileNode::spcNode, and TablespaceCreateDbspace().
bool mdexists | ( | SMgrRelation | reln, |
ForkNumber | forkNum | ||
) |
Definition at line 161 of file md.c.
References EXTENSION_RETURN_NULL, mdclose(), and mdopenfork().
void mdextend | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
char * | buffer, | ||
bool | skipFsync | ||
) |
Definition at line 414 of file md.c.
References _mdfd_getseg(), _mdnblocks(), Assert, ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), ERROR, EXTENSION_CREATE, FilePathName(), FileWrite(), InvalidBlockNumber, _MdfdVec::mdfd_vfd, mdnblocks(), register_dirty_segment(), relpath, SMgrRelationData::smgr_rnode, SmgrIsTemp, and WAIT_EVENT_DATA_FILE_EXTEND.
Referenced by _mdfd_getseg().
void mdimmedsync | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 921 of file md.c.
References _fdvec_resize(), _mdfd_openseg(), data_sync_elevel(), ereport, errcode_for_file_access(), errmsg(), ERROR, FileClose(), FilePathName(), FileSync(), SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_vfd, mdnblocks(), and WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC.
void mdinit | ( | void | ) |
Definition at line 148 of file md.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, and TopMemoryContext.
BlockNumber mdnblocks | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 762 of file md.c.
References _mdfd_openseg(), _mdnblocks(), Assert, elog, EXTENSION_FAIL, FATAL, SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, and mdopenfork().
Referenced by mdextend(), mdimmedsync(), mdtruncate(), and mdwrite().
void mdopen | ( | SMgrRelation | reln | ) |
Definition at line 521 of file md.c.
References MAX_FORKNUM, and SMgrRelationData::md_num_open_segs.
|
static |
Definition at line 478 of file md.c.
References _fdvec_resize(), _mdnblocks(), Assert, ereport, errcode_for_file_access(), errmsg(), ERROR, EXTENSION_RETURN_NULL, fd(), FILE_POSSIBLY_DELETED, SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_segno, _MdfdVec::mdfd_vfd, PathNameOpenFile(), pfree(), PG_BINARY, relpath, and SMgrRelationData::smgr_rnode.
Referenced by _mdfd_getseg(), mdexists(), and mdnblocks().
bool mdprefetch | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum | ||
) |
Definition at line 555 of file md.c.
References _mdfd_getseg(), Assert, EXTENSION_FAIL, EXTENSION_RETURN_NULL, FilePrefetch(), InRecovery, _MdfdVec::mdfd_vfd, and WAIT_EVENT_DATA_FILE_PREFETCH.
void mdread | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
char * | buffer | ||
) |
Definition at line 632 of file md.c.
References _mdfd_getseg(), Assert, RelFileNodeBackend::backend, RelFileNode::dbNode, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg(), ERROR, EXTENSION_CREATE_RECOVERY, EXTENSION_FAIL, FilePathName(), FileRead(), InRecovery, _MdfdVec::mdfd_vfd, MemSet, RelFileNodeBackend::node, RelFileNode::relNode, SMgrRelationData::smgr_rnode, RelFileNode::spcNode, WAIT_EVENT_DATA_FILE_READ, and zero_damaged_pages.
int mdsyncfiletag | ( | const FileTag * | ftag, |
char * | path | ||
) |
Definition at line 1333 of file md.c.
References _mdfd_segpath(), FileClose(), FilePathName(), FileSync(), FileTag::forknum, InvalidBackendId, MAXPGPATH, SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_vfd, PathNameOpenFile(), pfree(), PG_BINARY, FileTag::rnode, FileTag::segno, smgropen(), strlcpy(), and WAIT_EVENT_DATA_FILE_SYNC.
void mdtruncate | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | nblocks | ||
) |
Definition at line 819 of file md.c.
References _fdvec_resize(), Assert, ereport, errcode_for_file_access(), errmsg(), ERROR, FileClose(), FilePathName(), FileTruncate(), InRecovery, SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_vfd, mdnblocks(), register_dirty_segment(), relpath, SMgrRelationData::smgr_rnode, SmgrIsTemp, and WAIT_EVENT_DATA_FILE_TRUNCATE.
void mdunlink | ( | RelFileNodeBackend | rnode, |
ForkNumber | forkNum, | ||
bool | isRedo | ||
) |
Definition at line 277 of file md.c.
References InvalidForkNumber, MAX_FORKNUM, and mdunlinkfork().
int mdunlinkfiletag | ( | const FileTag * | ftag, |
char * | path | ||
) |
Definition at line 1380 of file md.c.
References MAIN_FORKNUM, MAXPGPATH, pfree(), relpathperm, FileTag::rnode, and strlcpy().
|
static |
Definition at line 314 of file md.c.
References do_truncate(), ereport, errcode_for_file_access(), errmsg(), MAIN_FORKNUM, palloc(), pfree(), register_forget_request(), register_unlink_segment(), RelFileNodeBackendIsTemp, relpath, sprintf, and WARNING.
Referenced by mdunlink().
void mdwrite | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
char * | buffer, | ||
bool | skipFsync | ||
) |
Definition at line 697 of file md.c.
References _mdfd_getseg(), Assert, RelFileNodeBackend::backend, RelFileNode::dbNode, ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), ERROR, EXTENSION_CREATE_RECOVERY, EXTENSION_FAIL, FilePathName(), FileWrite(), _MdfdVec::mdfd_vfd, mdnblocks(), RelFileNodeBackend::node, register_dirty_segment(), RelFileNode::relNode, SMgrRelationData::smgr_rnode, SmgrIsTemp, RelFileNode::spcNode, and WAIT_EVENT_DATA_FILE_WRITE.
void mdwriteback | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
BlockNumber | nblocks | ||
) |
Definition at line 583 of file md.c.
References _mdfd_getseg(), Assert, EXTENSION_RETURN_NULL, FileWriteback(), _MdfdVec::mdfd_vfd, and WAIT_EVENT_DATA_FILE_FLUSH.
|
static |
Definition at line 974 of file md.c.
References Assert, data_sync_elevel(), DEBUG1, ereport, errcode_for_file_access(), errmsg(), ERROR, FilePathName(), FileSync(), INIT_MD_FILETAG, _MdfdVec::mdfd_segno, _MdfdVec::mdfd_vfd, RelFileNodeBackend::node, RegisterSyncRequest(), SMgrRelationData::smgr_rnode, SmgrIsTemp, SYNC_REQUEST, and WAIT_EVENT_DATA_FILE_SYNC.
Referenced by mdextend(), mdtruncate(), and mdwrite().
|
static |
Definition at line 1017 of file md.c.
References INIT_MD_FILETAG, RelFileNodeBackend::node, RegisterSyncRequest(), and SYNC_FORGET_REQUEST.
Referenced by mdunlinkfork().
|
static |
Definition at line 1000 of file md.c.
References Assert, INIT_MD_FILETAG, RelFileNodeBackend::node, RegisterSyncRequest(), RelFileNodeBackendIsTemp, and SYNC_UNLINK_REQUEST.
Referenced by mdunlinkfork().
|
static |