暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss DMS源代码阅读记录

原创 kidd-cn 2023-06-06
438

节点请求页面流程概括:

详细流程:

总体来说分为两种情况:

请求页面的master是requester

在本地查找page owner(这里的owner是向master注册并拥有该页面的最新版本),找到该页面owner,master将请求转发给owner节点

请求页面的master不是requester

1、根据pageID获取master节点的相关信息,并向master节点发送请求,

2、master收到requester请求后通过DRC获取page的owner,并将请求转发给owner节点

细节:

drc:是如何保存页面的信息的?

关键数据结构

1、drc_buf_res_t(描述了一个资源,是page或者是lock)

/*
 * page buffer resource DRC management structure.
 */
typedef struct st_drc_buf_res {
    bilist_node_t   node;               /* used for link drc_buf_res_t in free list or bucket list, must be first */
    uint64          copy_insts;          /* bitmap for owners, for S mode, more than one owner may exist */
    spinlock_t      lock;
    atomic32_t      count;              /* for lock */
    uint8           claimed_owner;      /* owner */
    uint8           lock_mode;          /* current DRC lock mode */
    uint8           last_edp;           /* the newest edp instance id */
    uint8           type;               /* page or lock */
    bool8           in_recovery;        /* in recovery or not */
    bool8           copy_promote;       /* copy promote to owner, can not release, may need flush */
    uint16          part_id;            /* which partition id that current page belongs to */
    bilist_node_t   part_node;          /* used for link drc_buf_res_t that belongs to the same partition id */
    uint64          edp_map;            /* indicate which instance has current page's EDP(Earlier Dirty Page) */
    uint64          lsn;                /* the newest edp LSN of current page in the cluster */
    uint32          ver;
    uint16          len;                /* the length of data below */
    uint8           recovery_skip;      /* DRC is accessed in recovery and skip because drc has owner */
    uint8           unused;
    drc_cvt_item_t  converting;         /* the next requester to grant current page to */
    bilist_t        convert_q;          /* current page's requester queue */
    char            data[DMS_RESID_SIZE];            /* user defined resource(page) identifier */
} drc_buf_res_t;

drc关键数据结构图

drc由两个不同类型的全局resource map构成,一个是page类型,一个是lock类型,上图表示了page类型全局resource map以及DRC中关键数据结构的关系,它们一起构成了节点缓存page在DRC中个管理。

接下来有如下问题需要弄清楚:

为什么需要一个在resource map的基础上,还需要做分区管理?DMS中是如何使用它们的?

在DMS源代码中查找相关使用,都在reform场景中做resource buffer的清理中使用,我想partition主要是用来按partition加速资源的的清理

static int dms_reform_drc_clean_full(void)
{
    drc_res_ctx_t *ctx = DRC_RES_CTX;
    bilist_t *part_list = NULL;

    for (uint16 part_id = 0; part_id < DRC_MAX_PART_NUM; part_id++) {
        part_list = &ctx->global_lock_res.res_parts[part_id];
        drc_release_buf_res_by_part(part_list, DRC_RES_LOCK_TYPE);
        part_list = &ctx->global_buf_res.res_parts[part_id];
        drc_release_buf_res_by_part(part_list, DRC_RES_PAGE_TYPE);
    }

    return DMS_SUCCESS;
}

流程详解

drc_create_buf_res:

  1. 从res_pool中分配一个空闲的内存(drc_buf_res),这里使用了内存预先分配与重用机制
  2. 初始化drc_buf_res
  3. 将drc_buf_res插入到drc_res_map中
  4. 将drc_buf_res插入到drc_global_res_map中对应的partition链表中

问题:

一个page是如果根据pageID映射到哪个节点?

page如何映射到DRC中的哪个分区(partition)

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论