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/relfilelocator.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_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_CHECK_SIZE (1 << 4) |
#define | EXTENSION_DONT_OPEN (1 << 5) |
Typedefs | |
typedef struct _MdfdVec | MdfdVec |
Variables | |
static MemoryContext | MdCxt |
#define INIT_MD_FILETAG | ( | a, | |
xx_rlocator, | |||
xx_forknum, | |||
xx_segno | |||
) |
|
static |
Definition at line 1284 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(), and mdtruncate().
|
static |
Definition at line 1390 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_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(), and PG_IO_ALIGN_SIZE.
Referenced by mdextend(), mdprefetch(), mdread(), mdwrite(), mdwriteback(), and mdzeroextend().
|
inlinestatic |
Definition at line 146 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 1345 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 pfree().
Referenced by _mdfd_getseg(), mdimmedsync(), and mdnblocks().
|
static |
Definition at line 1322 of file md.c.
References pfree(), psprintf(), relpath, and SMgrRelationData::smgr_rlocator.
Referenced by _mdfd_getseg(), _mdfd_openseg(), and mdsyncfiletag().
|
static |
Definition at line 1521 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 325 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 1252 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 1234 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 192 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(), pfree(), register_dirty_segment(), relpath, SMgrRelationData::smgr_rlocator, SmgrIsTemp, RelFileLocator::spcOid, and TablespaceCreateDbspace().
bool mdexists | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 173 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 462 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().
void mdimmedsync | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 1097 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 160 of file md.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, MdCxt, and TopMemoryContext.
BlockNumber mdnblocks | ( | SMgrRelation | reln, |
ForkNumber | forknum | ||
) |
Definition at line 938 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(), mdwrite(), 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 639 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(), pfree(), relpath, and SMgrRelationData::smgr_rlocator.
Referenced by _mdfd_getseg(), mdexists(), and mdnblocks().
bool mdprefetch | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum | ||
) |
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, and _MdfdVec::mdfd_vfd.
void mdread | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
void * | buffer | ||
) |
Definition at line 743 of file md.c.
References _mdfd_getseg(), Assert(), RelFileLocatorBackend::backend, RelFileLocator::dbOid, ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg(), ERROR, EXTENSION_CREATE_RECOVERY, EXTENSION_FAIL, FilePathName(), FileRead(), InRecovery, RelFileLocatorBackend::locator, _MdfdVec::mdfd_vfd, MemSet, PG_IO_ALIGN_SIZE, PG_O_DIRECT, RelFileLocator::relNumber, SMgrRelationData::smgr_rlocator, RelFileLocator::spcOid, TYPEALIGN, and zero_damaged_pages.
int mdsyncfiletag | ( | const FileTag * | ftag, |
char * | path | ||
) |
Definition at line 1542 of file md.c.
References _mdfd_open_flags(), _mdfd_segpath(), FileClose(), FilePathName(), FileSync(), FileTag::forknum, InvalidBackendId, IOCONTEXT_NORMAL, IOOBJECT_RELATION, IOOP_FSYNC, MAXPGPATH, SMgrRelationData::md_num_open_segs, SMgrRelationData::md_seg_fds, _MdfdVec::mdfd_vfd, PathNameOpenFile(), pfree(), pgstat_count_io_op_time(), pgstat_prepare_io_time(), FileTag::rlocator, FileTag::segno, smgropen(), and strlcpy().
void mdtruncate | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | nblocks | ||
) |
Definition at line 995 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_rlocator, and SmgrIsTemp.
void mdunlink | ( | RelFileLocatorBackend | rlocator, |
ForkNumber | forknum, | ||
bool | isRedo | ||
) |
Definition at line 309 of file md.c.
References InvalidForkNumber, MAX_FORKNUM, and mdunlinkfork().
int mdunlinkfiletag | ( | const FileTag * | ftag, |
char * | path | ||
) |
Definition at line 1595 of file md.c.
References MAIN_FORKNUM, MAXPGPATH, pfree(), relpathperm, FileTag::rlocator, and strlcpy().
|
static |
Definition at line 346 of file md.c.
References do_truncate(), ereport, errcode_for_file_access(), errmsg(), IsBinaryUpgrade, MAIN_FORKNUM, palloc(), pfree(), register_forget_request(), register_unlink_segment(), RelFileLocatorBackendIsTemp, relpath, sprintf, and WARNING.
Referenced by mdunlink().
void mdwrite | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
const void * | buffer, | ||
bool | skipFsync | ||
) |
Definition at line 812 of file md.c.
References _mdfd_getseg(), Assert(), RelFileLocatorBackend::backend, RelFileLocator::dbOid, ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), ERROR, EXTENSION_CREATE_RECOVERY, EXTENSION_FAIL, FilePathName(), FileWrite(), RelFileLocatorBackend::locator, _MdfdVec::mdfd_vfd, mdnblocks(), PG_IO_ALIGN_SIZE, PG_O_DIRECT, register_dirty_segment(), RelFileLocator::relNumber, SMgrRelationData::smgr_rlocator, SmgrIsTemp, RelFileLocator::spcOid, and TYPEALIGN.
void mdwriteback | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
BlockNumber | nblocks | ||
) |
Definition at line 879 of file md.c.
References _mdfd_getseg(), Assert(), EXTENSION_DONT_OPEN, FileWriteback(), IO_DIRECT_DATA, io_direct_flags, and _MdfdVec::mdfd_vfd.
void mdzeroextend | ( | SMgrRelation | reln, |
ForkNumber | forknum, | ||
BlockNumber | blocknum, | ||
int | nblocks, | ||
bool | skipFsync | ||
) |
Definition at line 527 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 1159 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, and SYNC_REQUEST.
Referenced by mdcreate(), mdextend(), mdtruncate(), mdwrite(), and mdzeroextend().
|
static |
Definition at line 1220 of file md.c.
References INIT_MD_FILETAG, RelFileLocatorBackend::locator, RegisterSyncRequest(), and SYNC_FORGET_REQUEST.
Referenced by mdunlinkfork().
|
static |
Definition at line 1203 of file md.c.
References Assert(), INIT_MD_FILETAG, RelFileLocatorBackend::locator, RegisterSyncRequest(), RelFileLocatorBackendIsTemp, and SYNC_UNLINK_REQUEST.
Referenced by mdunlinkfork().
|
static |
Definition at line 88 of file md.c.
Referenced by _fdvec_resize(), and mdinit().