PostgreSQL Source Code git master
|
#include "postgres.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/file.h>
#include "access/xlogutils.h"
#include "commands/tablespace.h"
#include "common/file_utils.h"
#include "miscadmin.h"
#include "pg_trace.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/fd.h"
#include "storage/md.h"
#include "storage/relfilelocator.h"
#include "storage/smgr.h"
#include "storage/sync.h"
#include "utils/memutils.h"
Go to the source code of this file.
Data Structures | |
struct | _MdfdVec |
struct | MdPathStr |
Macros | |
#define | INIT_MD_FILETAG(a, xx_rlocator, 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_OPEN (1 << 5) |
#define | SEGMENT_CHARS OIDCHARS |
#define | MD_PATH_STR_MAXLEN |
Typedefs | |
typedef struct _MdfdVec | MdfdVec |
typedef struct MdPathStr | MdPathStr |
Functions | |
static void | mdunlinkfork (RelFileLocatorBackend rlocator, ForkNumber forknum, bool isRedo) |
static MdfdVec * | mdopenfork (SMgrRelation reln, ForkNumber forknum, int behavior) |
static void | register_dirty_segment (SMgrRelation reln, ForkNumber forknum, MdfdVec *seg) |
static void | register_unlink_segment (RelFileLocatorBackend rlocator, ForkNumber forknum, BlockNumber segno) |
static void | register_forget_request (RelFileLocatorBackend rlocator, ForkNumber forknum, BlockNumber segno) |
static void | _fdvec_resize (SMgrRelation reln, ForkNumber forknum, int nseg) |
static MdPathStr | _mdfd_segpath (SMgrRelation reln, ForkNumber forknum, BlockNumber segno) |
static MdfdVec * | _mdfd_openseg (SMgrRelation reln, ForkNumber forknum, BlockNumber segno, int oflags) |
static MdfdVec * | _mdfd_getseg (SMgrRelation reln, ForkNumber forknum, BlockNumber blkno, bool skipFsync, int behavior) |
static BlockNumber | _mdnblocks (SMgrRelation reln, ForkNumber forknum, MdfdVec *seg) |
static int | _mdfd_open_flags (void) |
void | mdinit (void) |
bool | mdexists (SMgrRelation reln, ForkNumber forknum) |
void | mdcreate (SMgrRelation reln, ForkNumber forknum, bool isRedo) |
void | mdunlink (RelFileLocatorBackend rlocator, ForkNumber forknum, bool isRedo) |
static int | do_truncate (const char *path) |
void | mdextend (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync) |
void | mdzeroextend (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync) |
void | mdopen (SMgrRelation reln) |
void | mdclose (SMgrRelation reln, ForkNumber forknum) |
bool | mdprefetch (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks) |
static int | buffers_to_iovec (struct iovec *iov, void **buffers, int nblocks) |
uint32 | mdmaxcombine (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum) |
void | mdreadv (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks) |
void | mdwritev (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffers, BlockNumber nblocks, bool skipFsync) |
void | mdwriteback (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks) |
BlockNumber | mdnblocks (SMgrRelation reln, ForkNumber forknum) |
void | mdtruncate (SMgrRelation reln, ForkNumber forknum, BlockNumber curnblk, BlockNumber nblocks) |
void | mdregistersync (SMgrRelation reln, ForkNumber forknum) |
void | mdimmedsync (SMgrRelation reln, ForkNumber forknum) |
void | ForgetDatabaseSyncRequests (Oid dbid) |
void | DropRelationFiles (RelFileLocator *delrels, int ndelrels, bool isRedo) |
int | mdsyncfiletag (const FileTag *ftag, char *path) |
int | mdunlinkfiletag (const FileTag *ftag, char *path) |
bool | mdfiletagmatches (const FileTag *ftag, const FileTag *candidate) |
Variables | |
static MemoryContext | MdCxt |
#define INIT_MD_FILETAG | ( | a, | |
xx_rlocator, | |||
xx_forknum, | |||
xx_segno | |||
) |
#define MD_PATH_STR_MAXLEN |
|
static |
Definition at line 1503 of file md.c.
References SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, MdCxt, MemoryContextAlloc(), pfree(), and repalloc().
Referenced by _mdfd_openseg(), mdclose(), mdcreate(), mdimmedsync(), mdopenfork(), mdregistersync(), and mdtruncate().
|
static |
Definition at line 1614 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_OPEN, EXTENSION_FAIL, EXTENSION_RETURN_NULL, FATAL, FILE_POSSIBLY_DELETED, InRecovery, MCXT_ALLOC_ZERO, SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, mdextend(), _MdfdVec::mdfd_segno, mdopenfork(), palloc_aligned(), pfree(), PG_IO_ALIGN_SIZE, and str.
Referenced by mdextend(), mdprefetch(), mdreadv(), mdwriteback(), mdwritev(), and mdzeroextend().
|
inlinestatic |
Definition at line 156 of file md.c.
References IO_DIRECT_DATA, io_direct_flags, PG_BINARY, and PG_O_DIRECT.
Referenced by _mdfd_openseg(), mdcreate(), mdopenfork(), and mdsyncfiletag().
|
static |
Definition at line 1571 of file md.c.
References _fdvec_resize(), _mdfd_open_flags(), _mdfd_segpath(), _mdnblocks(), Assert(), fd(), SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_segno, _MdfdVec::mdfd_vfd, PathNameOpenFile(), and MdPathStr::str.
Referenced by _mdfd_getseg(), mdimmedsync(), mdnblocks(), and mdregistersync().
|
static |
Definition at line 1551 of file md.c.
References relpath, SMgrRelationData::smgr_rlocator, sprintf, MdPathStr::str, and RelPathStr::str.
Referenced by _mdfd_getseg(), _mdfd_openseg(), and mdsyncfiletag().
|
static |
Definition at line 1743 of file md.c.
References ereport, errcode_for_file_access(), errmsg(), ERROR, FilePathName(), FileSize(), len, and _MdfdVec::mdfd_vfd.
Referenced by _mdfd_getseg(), _mdfd_openseg(), mdextend(), mdnblocks(), mdopenfork(), and mdzeroextend().
|
static |
Definition at line 764 of file md.c.
References Assert(), i, PG_IO_ALIGN_SIZE, PG_O_DIRECT, and TYPEALIGN.
Referenced by mdreadv(), and mdwritev().
|
static |
Definition at line 333 of file md.c.
References ereport, errcode_for_file_access(), errmsg(), pg_truncate(), and WARNING.
Referenced by mdunlinkfork().
void DropRelationFiles | ( | RelFileLocator * | delrels, |
int | ndelrels, | ||
bool | isRedo | ||
) |
Definition at line 1471 of file md.c.
References i, INVALID_PROC_NUMBER, 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 1453 of file md.c.
References RelFileLocator::dbOid, INIT_MD_FILETAG, InvalidBlockNumber, InvalidForkNumber, RegisterSyncRequest(), RelFileLocator::relNumber, RelFileLocator::spcOid, and SYNC_FILTER_REQUEST.
Referenced by createdb_failure_callback(), dbase_redo(), and dropdb().
void mdclose | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 693 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 202 of file md.c.
References _fdvec_resize(), _mdfd_open_flags(), Assert(), RelFileLocator::dbOid, ereport, errcode_for_file_access(), errmsg(), ERROR, fd(), RelFileLocatorBackend::locator, SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_segno, _MdfdVec::mdfd_vfd, PathNameOpenFile(), register_dirty_segment(), relpath, SMgrRelationData::smgr_rlocator, SmgrIsTemp, RelFileLocator::spcOid, RelPathStr::str, and TablespaceCreateDbspace().
bool mdexists | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 183 of file md.c.
References EXTENSION_RETURN_NULL, InRecovery, mdclose(), and mdopenfork().
void mdextend | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
const void * | buffer, | ||
bool | skipFsync | ||
) |
Definition at line 467 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(), PG_IO_ALIGN_SIZE, PG_O_DIRECT, register_dirty_segment(), relpath, SMgrRelationData::smgr_rlocator, SmgrIsTemp, and TYPEALIGN.
Referenced by _mdfd_getseg().
Definition at line 1834 of file md.c.
References RelFileLocator::dbOid, and FileTag::rlocator.
void mdimmedsync | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 1316 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, and mdnblocks().
void mdinit | ( | void | ) |
Definition at line 170 of file md.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, MdCxt, and TopMemoryContext.
uint32 mdmaxcombine | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum | ||
) |
Definition at line 813 of file md.c.
BlockNumber mdnblocks | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 1112 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(), mdregistersync(), mdwritev(), and mdzeroextend().
void mdopen | ( | SMgrRelation | reln | ) |
Definition at line 682 of file md.c.
References MAX_FORKNUM, and SMgrRelationData::md_num_open_segs.
|
static |
Definition at line 644 of file md.c.
References _fdvec_resize(), _mdfd_open_flags(), _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(), relpath, SMgrRelationData::smgr_rlocator, and RelPathStr::str.
Referenced by _mdfd_getseg(), mdexists(), and mdnblocks().
bool mdprefetch | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
int | nblocks | ||
) |
Definition at line 716 of file md.c.
References _mdfd_getseg(), Assert(), EXTENSION_FAIL, EXTENSION_RETURN_NULL, FilePrefetch(), InRecovery, IO_DIRECT_DATA, io_direct_flags, MaxBlockNumber, _MdfdVec::mdfd_vfd, and Min.
void mdreadv | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
void ** | buffers, | ||
BlockNumber | nblocks | ||
) |
Definition at line 827 of file md.c.
References _mdfd_getseg(), Assert(), RelFileLocatorBackend::backend, buffers_to_iovec(), compute_remaining_iovec(), RelFileLocator::dbOid, elog, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg(), ERROR, EXTENSION_CREATE_RECOVERY, EXTENSION_FAIL, FilePathName(), FileReadV(), i, InRecovery, lengthof, RelFileLocatorBackend::locator, _MdfdVec::mdfd_vfd, Min, PG_IOV_MAX, RelFileLocator::relNumber, SMgrRelationData::smgr_rlocator, RelFileLocator::spcOid, and zero_damaged_pages.
void mdregistersync | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 1265 of file md.c.
References _fdvec_resize(), _mdfd_openseg(), FileClose(), SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_vfd, mdnblocks(), and register_dirty_segment().
int mdsyncfiletag | ( | const FileTag * | ftag, |
char * | path | ||
) |
Definition at line 1764 of file md.c.
References _mdfd_open_flags(), _mdfd_segpath(), FileClose(), FilePathName(), FileSync(), FileTag::forknum, INVALID_PROC_NUMBER, IOCONTEXT_NORMAL, IOOBJECT_RELATION, IOOP_FSYNC, MAXPGPATH, SMgrRelationData::md_num_open_segs, MD_PATH_STR_MAXLEN, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_vfd, PathNameOpenFile(), pgstat_count_io_op_time(), pgstat_prepare_io_time(), FileTag::rlocator, FileTag::segno, smgropen(), MdPathStr::str, strlcpy(), and track_io_timing.
void mdtruncate | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | curnblk, | ||
BlockNumber | nblocks | ||
) |
Definition at line 1176 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, register_dirty_segment(), relpath, SMgrRelationData::smgr_rlocator, and SmgrIsTemp.
void mdunlink | ( | RelFileLocatorBackend | rlocator, |
ForkNumber | forknum, | ||
bool | isRedo | ||
) |
Definition at line 317 of file md.c.
References InvalidForkNumber, MAX_FORKNUM, and mdunlinkfork().
int mdunlinkfiletag | ( | const FileTag * | ftag, |
char * | path | ||
) |
Definition at line 1816 of file md.c.
References MAIN_FORKNUM, MAXPGPATH, relpathperm, FileTag::rlocator, RelPathStr::str, and strlcpy().
|
static |
Definition at line 354 of file md.c.
References do_truncate(), ereport, errcode_for_file_access(), errmsg(), IsBinaryUpgrade, MAIN_FORKNUM, register_forget_request(), register_unlink_segment(), RelFileLocatorBackendIsTemp, relpath, sprintf, MdPathStr::str, RelPathStr::str, and WARNING.
Referenced by mdunlink().
void mdwriteback | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
BlockNumber | nblocks | ||
) |
Definition at line 1053 of file md.c.
References _mdfd_getseg(), Assert(), EXTENSION_DONT_OPEN, FileWriteback(), IO_DIRECT_DATA, io_direct_flags, and _MdfdVec::mdfd_vfd.
void mdwritev | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
const void ** | buffers, | ||
BlockNumber | nblocks, | ||
bool | skipFsync | ||
) |
Definition at line 948 of file md.c.
References _mdfd_getseg(), Assert(), RelFileLocatorBackend::backend, buffers_to_iovec(), compute_remaining_iovec(), RelFileLocator::dbOid, elog, ereport, errcode_for_file_access(), errhint(), errmsg(), ERROR, EXTENSION_CREATE_RECOVERY, EXTENSION_FAIL, FilePathName(), FileWriteV(), lengthof, RelFileLocatorBackend::locator, _MdfdVec::mdfd_vfd, mdnblocks(), Min, PG_IOV_MAX, register_dirty_segment(), RelFileLocator::relNumber, SMgrRelationData::smgr_rlocator, SmgrIsTemp, and RelFileLocator::spcOid.
void mdzeroextend | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
int | nblocks, | ||
bool | skipFsync | ||
) |
Definition at line 532 of file md.c.
References _mdfd_getseg(), _mdnblocks(), Assert(), ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), ERROR, EXTENSION_CREATE, FileFallocate(), FilePathName(), FileZero(), InvalidBlockNumber, _MdfdVec::mdfd_vfd, mdnblocks(), register_dirty_segment(), relpath, SMgrRelationData::smgr_rlocator, and SmgrIsTemp.
|
static |
Definition at line 1378 of file md.c.
References Assert(), data_sync_elevel(), DEBUG1, ereport, errcode_for_file_access(), errmsg(), errmsg_internal(), ERROR, FilePathName(), FileSync(), INIT_MD_FILETAG, IOCONTEXT_NORMAL, IOOBJECT_RELATION, IOOP_FSYNC, RelFileLocatorBackend::locator, _MdfdVec::mdfd_segno, _MdfdVec::mdfd_vfd, pgstat_count_io_op_time(), pgstat_prepare_io_time(), RegisterSyncRequest(), SMgrRelationData::smgr_rlocator, SmgrIsTemp, SYNC_REQUEST, and track_io_timing.
Referenced by mdcreate(), mdextend(), mdregistersync(), mdtruncate(), mdwritev(), and mdzeroextend().
|
static |
Definition at line 1439 of file md.c.
References INIT_MD_FILETAG, RelFileLocatorBackend::locator, RegisterSyncRequest(), and SYNC_FORGET_REQUEST.
Referenced by mdunlinkfork().
|
static |
Definition at line 1422 of file md.c.
References Assert(), INIT_MD_FILETAG, RelFileLocatorBackend::locator, RegisterSyncRequest(), RelFileLocatorBackendIsTemp, and SYNC_UNLINK_REQUEST.
Referenced by mdunlinkfork().
|
static |
Definition at line 86 of file md.c.
Referenced by _fdvec_resize(), and mdinit().