前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Postgresql文件管理器一图流

Postgresql文件管理器一图流

作者头像
mingjie
发布2022-05-12 11:02:06
9240
发布2022-05-12 11:02:06
举报
文章被收录于专栏:Postgresql源码分析

smgr管理器核心数据结构,需要配合md.c来使用。

代码语言:javascript
复制
	/*
	 * for md.c; per-fork arrays of the number of open segments
	 * (md_num_open_segs) and the segments themselves (md_seg_fds).
	 */
	int			md_num_open_segs[MAX_FORKNUM + 1];
	struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1];
  • md_num_open_segs记录当前表打开文件数量
  • md_seg_fds记录当前表打开文件段指针,PG文件超过1G需要切分,例如文件名为23456的表:
    • 切分为一个文件
      • 23456信息记录在md_seg_fds[MAIN_FORKNUM][0]
      • md_num_open_segs[MAIN_FORKNUM]=1
    • 切分为两个文件
      • 23456信息记录在md_seg_fds[MAIN_FORKNUM][0]
      • 23456.0信息记录在md_seg_fds[MAIN_FORKNUM][1]
      • md_num_open_segs[MAIN_FORKNUM]=2
在这里插入图片描述
在这里插入图片描述

注意: md_seg_fds是一个指针数组,每一个指针指向当前表存FD的一块空间,当前表有多个文件的话,这块空间就会有多个_MdfdVec,每个_MdfdVec记录当前文件的vfd和当前文件的segments号(segments表示切割后第几个文件)

  • 每张表对应一个SMgrRelation
  • 每个SMgrRelation维护自己已经打开的vfd
  • vfd在md.c中使用,在fd.c中实现
  • 实现新的文件系统接口需要在smgr.c中添加,并指向自己的实现(比如md.c)
  • 实现新的文件系统大概率无需使用vfd,文件句柄需要自己管理
代码语言:javascript
复制
/*
 * smgr.c maintains a table of SMgrRelation objects, which are essentially
 * cached file handles.  An SMgrRelation is created (if not already present)
 * by smgropen(), and destroyed by smgrclose().  Note that neither of these
 * operations imply I/O, they just create or destroy a hashtable entry.
 * (But smgrclose() may release associated resources, such as OS-level file
 * descriptors.)
 *
 * An SMgrRelation may have an "owner", which is just a pointer to it from
 * somewhere else; smgr.c will clear this pointer if the SMgrRelation is
 * closed.  We use this to avoid dangling pointers from relcache to smgr
 * without having to make the smgr explicitly aware of relcache.  There
 * can't be more than one "owner" pointer per SMgrRelation, but that's
 * all we need.
 *
 * SMgrRelations that do not have an "owner" are considered to be transient,
 * and are deleted at end of transaction.
 */
typedef struct SMgrRelationData
{
	/* rnode is the hashtable lookup key, so it must be first! */
	RelFileNodeBackend smgr_rnode;	/* relation physical identifier */

	/* pointer to owning pointer, or NULL if none */
	struct SMgrRelationData **smgr_owner;

	/*
	 * These next three fields are not actually used or manipulated by smgr,
	 * except that they are reset to InvalidBlockNumber upon a cache flush
	 * event (in particular, upon truncation of the relation).  Higher levels
	 * store cached state here so that it will be reset when truncation
	 * happens.  In all three cases, InvalidBlockNumber means "unknown".
	 */
	BlockNumber smgr_targblock; /* current insertion target block */
	BlockNumber smgr_fsm_nblocks;	/* last known size of fsm fork */
	BlockNumber smgr_vm_nblocks;	/* last known size of vm fork */

	/* additional public fields may someday exist here */

	/*
	 * Fields below here are intended to be private to smgr.c and its
	 * submodules.  Do not touch them from elsewhere.
	 */
	int			smgr_which;		/* storage manager selector */

	/*
	 * for md.c; per-fork arrays of the number of open segments
	 * (md_num_open_segs) and the segments themselves (md_seg_fds).
	 */
	int			md_num_open_segs[MAX_FORKNUM + 1];
	struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1];

	/* if unowned, list link in list of all unowned SMgrRelations */
	dlist_node	node;
} SMgrRelationData;

typedef SMgrRelationData *SMgrRelation
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-07-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档