Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
smgr.h114 linesDownload Raw Back to storage
1/*-------------------------------------------------------------------------2 *3 * smgr.h4 *	  storage manager switch public interface declarations.5 *6 *7 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group8 * Portions Copyright (c) 1994, Regents of the University of California9 *10 * src/include/storage/smgr.h11 *12 *-------------------------------------------------------------------------13 */14#ifndef SMGR_H15#define SMGR_H16 17#include "lib/ilist.h"18#include "storage/block.h"19#include "storage/relfilelocator.h"20 21/*22 * smgr.c maintains a table of SMgrRelation objects, which are essentially23 * cached file handles.  An SMgrRelation is created (if not already present)24 * by smgropen(), and destroyed by smgrclose().  Note that neither of these25 * operations imply I/O, they just create or destroy a hashtable entry.26 * (But smgrclose() may release associated resources, such as OS-level file27 * descriptors.)28 *29 * An SMgrRelation may have an "owner", which is just a pointer to it from30 * somewhere else; smgr.c will clear this pointer if the SMgrRelation is31 * closed.  We use this to avoid dangling pointers from relcache to smgr32 * without having to make the smgr explicitly aware of relcache.  There33 * can't be more than one "owner" pointer per SMgrRelation, but that's34 * all we need.35 *36 * SMgrRelations that do not have an "owner" are considered to be transient,37 * and are deleted at end of transaction.38 */39typedef struct SMgrRelationData40{41	/* rlocator is the hashtable lookup key, so it must be first! */42	RelFileLocatorBackend smgr_rlocator;	/* relation physical identifier */43 44	/* pointer to owning pointer, or NULL if none */45	struct SMgrRelationData **smgr_owner;46 47	/*48	 * The following fields are reset to InvalidBlockNumber upon a cache flush49	 * event, and hold the last known size for each fork.  This information is50	 * currently only reliable during recovery, since there is no cache51	 * invalidation for fork extension.52	 */53	BlockNumber smgr_targblock; /* current insertion target block */54	BlockNumber smgr_cached_nblocks[MAX_FORKNUM + 1];	/* last known size */55 56	/* additional public fields may someday exist here */57 58	/*59	 * Fields below here are intended to be private to smgr.c and its60	 * submodules.  Do not touch them from elsewhere.61	 */62	int			smgr_which;		/* storage manager selector */63 64	/*65	 * for md.c; per-fork arrays of the number of open segments66	 * (md_num_open_segs) and the segments themselves (md_seg_fds).67	 */68	int			md_num_open_segs[MAX_FORKNUM + 1];69	struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1];70 71	/* if unowned, list link in list of all unowned SMgrRelations */72	dlist_node	node;73} SMgrRelationData;74 75typedef SMgrRelationData *SMgrRelation;76 77#define SmgrIsTemp(smgr) \78	RelFileLocatorBackendIsTemp((smgr)->smgr_rlocator)79 80extern void smgrinit(void);81extern SMgrRelation smgropen(RelFileLocator rlocator, BackendId backend);82extern bool smgrexists(SMgrRelation reln, ForkNumber forknum);83extern void smgrsetowner(SMgrRelation *owner, SMgrRelation reln);84extern void smgrclearowner(SMgrRelation *owner, SMgrRelation reln);85extern void smgrclose(SMgrRelation reln);86extern void smgrcloseall(void);87extern void smgrcloserellocator(RelFileLocatorBackend rlocator);88extern void smgrrelease(SMgrRelation reln);89extern void smgrreleaseall(void);90extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);91extern void smgrdosyncall(SMgrRelation *rels, int nrels);92extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);93extern void smgrextend(SMgrRelation reln, ForkNumber forknum,94					   BlockNumber blocknum, const void *buffer, bool skipFsync);95extern void smgrzeroextend(SMgrRelation reln, ForkNumber forknum,96						   BlockNumber blocknum, int nblocks, bool skipFsync);97extern bool smgrprefetch(SMgrRelation reln, ForkNumber forknum,98						 BlockNumber blocknum);99extern void smgrread(SMgrRelation reln, ForkNumber forknum,100					 BlockNumber blocknum, void *buffer);101extern void smgrwrite(SMgrRelation reln, ForkNumber forknum,102					  BlockNumber blocknum, const void *buffer, bool skipFsync);103extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,104						  BlockNumber blocknum, BlockNumber nblocks);105extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);106extern BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum);107extern void smgrtruncate(SMgrRelation reln, ForkNumber *forknum,108						 int nforks, BlockNumber *nblocks);109extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);110extern void AtEOXact_SMgr(void);111extern bool ProcessBarrierSmgrRelease(void);112 113#endif							/* SMGR_H */114 
codekingpro/portable-devtools · Team Ai