欢迎光临
我们一直在努力

【参天引擎】一条 ALTER TABLE 把集群搞挂了,让我把 Cantian 数据字典的三层架构全搞明白了

讲真,第一次看 Cantian 数据字典源码的时候,我也是一脸懵——Catalog 系统表、DC 内存缓存、DDL 集群同步,这三层到底是怎么协同的?直到有一次线上执行 ALTER TABLE,结果把集群搞挂了,我才真正去翻源码,搞明白这套机制是怎么做到"元数据一致、DDL 不丢"的。

这篇文章就是帮你建立 Cantian 数据字典的"全局地图"。你会看到:

  • Catalog 系统表:SYS_TABLE

    /

    S

    Y

    S

    C

    O

    L

    U

    M

    N

    /SYS_COLUMN

    /SYSCOLUMN/SYS_INDEX$ 等核心表

  • DC 内存缓存:Entry 轻量常驻 + Entity 完整按需加载 + LRU 淘汰
  • DDL 集群同步:MES 逻辑日志广播与 meta_version 版本号
  • 元数据查找:从 SQL 查询到 DC 查找的完整路径
  • 动态视图:DV_DC_OBJECTS 等运行时可观测性

核心要解决的问题就三个:

  • 元数据怎么存:Catalog 系统表是怎么组织的?
  • 缓存怎么管:DC 两级缓存是怎么做到又快又省的?
  • DDL 怎么同步:集群多节点是怎么做到元数据一致的?

  • 先搞清楚 Cantian 数据字典是个啥

    Cantian 的数据字典,说白了就是管理数据库所有对象的元信息。

    你想啊,一个数据库有多少对象:表、列、索引、用户、权限、视图……这些对象的定义信息存在哪儿?怎么快速查找?集群环境下怎么保证多节点一致?这就是数据字典要解决的问题。

    它的核心设计原则就这几个:

    原则说明
    双层架构 系统表持久化 + DC 内存缓存
    逻辑日志 DDL 通过 MES 广播实现集群同步
    版本号管理 meta_version 保证元数据一致性
    LRU 淘汰 DC 缓存按需加载、自动淘汰

    数据字典功能域总览:三层架构是怎么协同的?

    数据字典(Data Dictionary)是 Cantian 数据库的元数据中心,负责管理表、列、索引、用户、权限等对象的定义信息。采用 系统表持久化 + DC 内存缓存 双层架构,通过 DDL 逻辑日志广播 实现集群内多节点元数据一致性。

    源码路径: pkg/src/kernel/catalog/

    #mermaid-svg-dL0OVSwF6OuU1SYi{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-dL0OVSwF6OuU1SYi .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-dL0OVSwF6OuU1SYi .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-dL0OVSwF6OuU1SYi .error-icon{fill:#552222;}#mermaid-svg-dL0OVSwF6OuU1SYi .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-dL0OVSwF6OuU1SYi .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-dL0OVSwF6OuU1SYi .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-dL0OVSwF6OuU1SYi .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-dL0OVSwF6OuU1SYi .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-dL0OVSwF6OuU1SYi .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-dL0OVSwF6OuU1SYi .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-dL0OVSwF6OuU1SYi .marker{fill:#333333;stroke:#333333;}#mermaid-svg-dL0OVSwF6OuU1SYi .marker.cross{stroke:#333333;}#mermaid-svg-dL0OVSwF6OuU1SYi svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-dL0OVSwF6OuU1SYi p{margin:0;}#mermaid-svg-dL0OVSwF6OuU1SYi .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-dL0OVSwF6OuU1SYi .cluster-label text{fill:#333;}#mermaid-svg-dL0OVSwF6OuU1SYi .cluster-label span{color:#333;}#mermaid-svg-dL0OVSwF6OuU1SYi .cluster-label span p{background-color:transparent;}#mermaid-svg-dL0OVSwF6OuU1SYi .label text,#mermaid-svg-dL0OVSwF6OuU1SYi span{fill:#333;color:#333;}#mermaid-svg-dL0OVSwF6OuU1SYi .node rect,#mermaid-svg-dL0OVSwF6OuU1SYi .node circle,#mermaid-svg-dL0OVSwF6OuU1SYi .node ellipse,#mermaid-svg-dL0OVSwF6OuU1SYi .node polygon,#mermaid-svg-dL0OVSwF6OuU1SYi .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-dL0OVSwF6OuU1SYi .rough-node .label text,#mermaid-svg-dL0OVSwF6OuU1SYi .node .label text,#mermaid-svg-dL0OVSwF6OuU1SYi .image-shape .label,#mermaid-svg-dL0OVSwF6OuU1SYi .icon-shape .label{text-anchor:middle;}#mermaid-svg-dL0OVSwF6OuU1SYi .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-dL0OVSwF6OuU1SYi .rough-node .label,#mermaid-svg-dL0OVSwF6OuU1SYi .node .label,#mermaid-svg-dL0OVSwF6OuU1SYi .image-shape .label,#mermaid-svg-dL0OVSwF6OuU1SYi .icon-shape .label{text-align:center;}#mermaid-svg-dL0OVSwF6OuU1SYi .node.clickable{cursor:pointer;}#mermaid-svg-dL0OVSwF6OuU1SYi .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-dL0OVSwF6OuU1SYi .arrowheadPath{fill:#333333;}#mermaid-svg-dL0OVSwF6OuU1SYi .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-dL0OVSwF6OuU1SYi .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-dL0OVSwF6OuU1SYi .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-dL0OVSwF6OuU1SYi .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-dL0OVSwF6OuU1SYi .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-dL0OVSwF6OuU1SYi .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-dL0OVSwF6OuU1SYi .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-dL0OVSwF6OuU1SYi .cluster text{fill:#333;}#mermaid-svg-dL0OVSwF6OuU1SYi .cluster span{color:#333;}#mermaid-svg-dL0OVSwF6OuU1SYi div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-dL0OVSwF6OuU1SYi .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-dL0OVSwF6OuU1SYi rect.text{fill:none;stroke-width:0;}#mermaid-svg-dL0OVSwF6OuU1SYi .icon-shape,#mermaid-svg-dL0OVSwF6OuU1SYi .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-dL0OVSwF6OuU1SYi .icon-shape p,#mermaid-svg-dL0OVSwF6OuU1SYi .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-dL0OVSwF6OuU1SYi .icon-shape .label rect,#mermaid-svg-dL0OVSwF6OuU1SYi .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-dL0OVSwF6OuU1SYi .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-dL0OVSwF6OuU1SYi .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-dL0OVSwF6OuU1SYi :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

    数据字典架构层次

    dc_open

    按需加载

    失效通知

    RD_CREATE/RD_ALTER/RD_DROP

    查询

    Catalog 系统表SYS_TABLE$, SYS_COLUMN$SYS_INDEX$, SYS_USER$ 等

    DC 内存缓存dc_context_t → dc_user_tEntry (轻量) → Entity (完整)

    DDL 集群同步逻辑日志广播 → 重放meta_version 版本号

    数据字典视图DV_* 动态视图 / 静态视图

    SQL 查询层

    架构要点:系统表持久化元数据 → DC 内存缓存加速访问 → DDL 逻辑日志确保集群一致 → 数据字典视图暴露运行时状态。

    核心职责

    职责说明
    元数据缓存 在内存中缓存表/视图/索引/序列等对象的元数据定义
    系统表管理 定义和维护 SYS_TABLE

    S

    Y

    S

    C

    O

    L

    U

    M

    N

    、SYS_COLUMN

    SYSCOLUMN 等核心系统表

    DDL 集群同步 通过逻辑日志广播 + Redo 重放保证多节点字典一致
    权限管理 缓存用户/角色/权限信息,支持权限检查
    Schema 锁 协调 DDL 与 DML 的并发访问

    Catalog 目录管理

    系统表

    Catalog 系统表是元数据的持久化存储形式,在编译时通过全局数组 g_sys_tables[] 预定义。

    核心系统表关系图:

    #mermaid-svg-U9gcaVugMJAAftsA{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-U9gcaVugMJAAftsA .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-U9gcaVugMJAAftsA .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-U9gcaVugMJAAftsA .error-icon{fill:#552222;}#mermaid-svg-U9gcaVugMJAAftsA .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-U9gcaVugMJAAftsA .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-U9gcaVugMJAAftsA .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-U9gcaVugMJAAftsA .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-U9gcaVugMJAAftsA .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-U9gcaVugMJAAftsA .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-U9gcaVugMJAAftsA .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-U9gcaVugMJAAftsA .marker{fill:#333333;stroke:#333333;}#mermaid-svg-U9gcaVugMJAAftsA .marker.cross{stroke:#333333;}#mermaid-svg-U9gcaVugMJAAftsA svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-U9gcaVugMJAAftsA p{margin:0;}#mermaid-svg-U9gcaVugMJAAftsA .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-U9gcaVugMJAAftsA .cluster-label text{fill:#333;}#mermaid-svg-U9gcaVugMJAAftsA .cluster-label span{color:#333;}#mermaid-svg-U9gcaVugMJAAftsA .cluster-label span p{background-color:transparent;}#mermaid-svg-U9gcaVugMJAAftsA .label text,#mermaid-svg-U9gcaVugMJAAftsA span{fill:#333;color:#333;}#mermaid-svg-U9gcaVugMJAAftsA .node rect,#mermaid-svg-U9gcaVugMJAAftsA .node circle,#mermaid-svg-U9gcaVugMJAAftsA .node ellipse,#mermaid-svg-U9gcaVugMJAAftsA .node polygon,#mermaid-svg-U9gcaVugMJAAftsA .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-U9gcaVugMJAAftsA .rough-node .label text,#mermaid-svg-U9gcaVugMJAAftsA .node .label text,#mermaid-svg-U9gcaVugMJAAftsA .image-shape .label,#mermaid-svg-U9gcaVugMJAAftsA .icon-shape .label{text-anchor:middle;}#mermaid-svg-U9gcaVugMJAAftsA .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-U9gcaVugMJAAftsA .rough-node .label,#mermaid-svg-U9gcaVugMJAAftsA .node .label,#mermaid-svg-U9gcaVugMJAAftsA .image-shape .label,#mermaid-svg-U9gcaVugMJAAftsA .icon-shape .label{text-align:center;}#mermaid-svg-U9gcaVugMJAAftsA .node.clickable{cursor:pointer;}#mermaid-svg-U9gcaVugMJAAftsA .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-U9gcaVugMJAAftsA .arrowheadPath{fill:#333333;}#mermaid-svg-U9gcaVugMJAAftsA .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-U9gcaVugMJAAftsA .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-U9gcaVugMJAAftsA .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-U9gcaVugMJAAftsA .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-U9gcaVugMJAAftsA .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-U9gcaVugMJAAftsA .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-U9gcaVugMJAAftsA .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-U9gcaVugMJAAftsA .cluster text{fill:#333;}#mermaid-svg-U9gcaVugMJAAftsA .cluster span{color:#333;}#mermaid-svg-U9gcaVugMJAAftsA div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-U9gcaVugMJAAftsA .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-U9gcaVugMJAAftsA rect.text{fill:none;stroke-width:0;}#mermaid-svg-U9gcaVugMJAAftsA .icon-shape,#mermaid-svg-U9gcaVugMJAAftsA .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-U9gcaVugMJAAftsA .icon-shape p,#mermaid-svg-U9gcaVugMJAAftsA .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-U9gcaVugMJAAftsA .icon-shape .label rect,#mermaid-svg-U9gcaVugMJAAftsA .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-U9gcaVugMJAAftsA .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-U9gcaVugMJAAftsA .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-U9gcaVugMJAAftsA :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

    USER#

    TABLE#

    TABLE#

    TABLE#

    TABLE#

    SYS_USER$用户定义ID, NAME, PASSWORD

    SYS_TABLE$表/视图定义USER#, ID, NAME, TYPE, COLS

    SYS_COLUMN$列定义USER#, TABLE#, ID, NAME, DATATYPE

    SYS_INDEX$索引定义USER#, TABLE#, ID, NAME, TYPE

    SYS_VIEW$视图定义USER#, ID, NAME, TEXT

    SYS_LOB$LOB 定义USER#, TABLE#, COLUMN#, ENTRY

    SYS_PART$分区定义USER#, TABLE#, PART#, NAME

    SYS_PRIVS$权限定义GRANTEE#, PRIVID, GRANTOR

    SYS_SEQUENCES$序列定义ID, UID, NAME, MINVAL, MAXVAL

    SYS_ROLES$角色定义ID, NAME, PASSWORD

    Catalog 存储位置

    系统表数据存储在内核的系统表空间中,通过 SYSTEM 表空间管理。核心系统表(SYS_TABLE

    S

    Y

    S

    C

    O

    L

    U

    M

    N

    、SYS_COLUMN

    SYSCOLUMN 等)由编译期全局数组 g_sys_tables[] 定义其描述信息,数据库启动 MOUNT 阶段从持久化存储加载。

    // 核心系统表引用: knl_ctlg.c
    table_t *db_sys_table(uint32 id) { return &g_sys_tables[id]; }
    index_t *db_sys_index(uint32 id) { return &g_sys_indexes[id]; }

    Catalog 初始化(MOUNT 阶段)

    源码位置: knl_dc.c

    #mermaid-svg-r9jS7aR7jwygkHcn{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-r9jS7aR7jwygkHcn .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-r9jS7aR7jwygkHcn .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-r9jS7aR7jwygkHcn .error-icon{fill:#552222;}#mermaid-svg-r9jS7aR7jwygkHcn .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-r9jS7aR7jwygkHcn .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-r9jS7aR7jwygkHcn .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-r9jS7aR7jwygkHcn .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-r9jS7aR7jwygkHcn .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-r9jS7aR7jwygkHcn .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-r9jS7aR7jwygkHcn .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-r9jS7aR7jwygkHcn .marker{fill:#333333;stroke:#333333;}#mermaid-svg-r9jS7aR7jwygkHcn .marker.cross{stroke:#333333;}#mermaid-svg-r9jS7aR7jwygkHcn svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-r9jS7aR7jwygkHcn p{margin:0;}#mermaid-svg-r9jS7aR7jwygkHcn .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-r9jS7aR7jwygkHcn .cluster-label text{fill:#333;}#mermaid-svg-r9jS7aR7jwygkHcn .cluster-label span{color:#333;}#mermaid-svg-r9jS7aR7jwygkHcn .cluster-label span p{background-color:transparent;}#mermaid-svg-r9jS7aR7jwygkHcn .label text,#mermaid-svg-r9jS7aR7jwygkHcn span{fill:#333;color:#333;}#mermaid-svg-r9jS7aR7jwygkHcn .node rect,#mermaid-svg-r9jS7aR7jwygkHcn .node circle,#mermaid-svg-r9jS7aR7jwygkHcn .node ellipse,#mermaid-svg-r9jS7aR7jwygkHcn .node polygon,#mermaid-svg-r9jS7aR7jwygkHcn .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-r9jS7aR7jwygkHcn .rough-node .label text,#mermaid-svg-r9jS7aR7jwygkHcn .node .label text,#mermaid-svg-r9jS7aR7jwygkHcn .image-shape .label,#mermaid-svg-r9jS7aR7jwygkHcn .icon-shape .label{text-anchor:middle;}#mermaid-svg-r9jS7aR7jwygkHcn .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-r9jS7aR7jwygkHcn .rough-node .label,#mermaid-svg-r9jS7aR7jwygkHcn .node .label,#mermaid-svg-r9jS7aR7jwygkHcn .image-shape .label,#mermaid-svg-r9jS7aR7jwygkHcn .icon-shape .label{text-align:center;}#mermaid-svg-r9jS7aR7jwygkHcn .node.clickable{cursor:pointer;}#mermaid-svg-r9jS7aR7jwygkHcn .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-r9jS7aR7jwygkHcn .arrowheadPath{fill:#333333;}#mermaid-svg-r9jS7aR7jwygkHcn .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-r9jS7aR7jwygkHcn .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-r9jS7aR7jwygkHcn .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-r9jS7aR7jwygkHcn .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-r9jS7aR7jwygkHcn .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-r9jS7aR7jwygkHcn .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-r9jS7aR7jwygkHcn .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-r9jS7aR7jwygkHcn .cluster text{fill:#333;}#mermaid-svg-r9jS7aR7jwygkHcn .cluster span{color:#333;}#mermaid-svg-r9jS7aR7jwygkHcn div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-r9jS7aR7jwygkHcn .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-r9jS7aR7jwygkHcn rect.text{fill:none;stroke-width:0;}#mermaid-svg-r9jS7aR7jwygkHcn .icon-shape,#mermaid-svg-r9jS7aR7jwygkHcn .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-r9jS7aR7jwygkHcn .icon-shape p,#mermaid-svg-r9jS7aR7jwygkHcn .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-r9jS7aR7jwygkHcn .icon-shape .label rect,#mermaid-svg-r9jS7aR7jwygkHcn .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-r9jS7aR7jwygkHcn .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-r9jS7aR7jwygkHcn .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-r9jS7aR7jwygkHcn :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

    首次启动

    恢复启动

    数据库 MOUNT 阶段

    dc_init 入口

    ctx->memory == NULL?

    dc_context_init创建内存池/哈希桶/LRU

    复用已存在上下文

    dc_init_users从 SYS_USER$ 加载所有用户

    dc_open_core_systbl打开核心系统表

    dc_init_table_entries初始化 SYS 用户表 Entry

    dc_init_extral_entries初始化视图/同义词/角色/权限

    ctx->ready = TRUE字典就绪

    Catalog DDL 操作

    DDL 操作通过专门的写入函数修改系统表:

    操作函数说明
    写入表定义 db_write_systable() 将表描述写入 SYS_TABLE$
    写入列定义 db_write_syscolumn() 将列属性写入 SYS_COLUMN$
    写入索引定义 db_write_sysindex() 将索引属性写入 SYS_INDEX$
    写入 LOB 定义 db_write_syslob() 将 LOB 属性写入 SYS_LOB$
    写入视图定义 db_write_sysview() 将视图 SQL 写入 SYS_VIEW$
    插入用户 db_insert_sys_user() 将用户信息写入 SYS_USER$

    系统表数据通过 Redo 日志保护,崩溃恢复时从 Redo 日志恢复。


    DC 元数据缓存

    DC(Dictionary Cache)结构

    DC 缓存采用 Entry(轻量元数据,常驻内存)+ Entity(完整元数据,按需加载,可 LRU 淘汰) 两级结构:

    dc_context_t (字典上下文)
    ├── user_buckets[] —— 用户哈希桶
    ├── users[] —— 用户数组 (dc_user_t)
    │ └── dc_user_t
    │ ├── groups[] —— Entry 分组数组
    │ │ └── dc_group_t → entries[]
    │ │ └── dc_entry_t (轻量元数据,常驻)
    │ │ └── entity → dc_entity_t (完整元数据,按需加载)
    │ ├── buckets[] —— 对象哈希桶
    │ ├── sequence_set —— 序列集合
    │ └── sys_privs/all_sys_privs —— 权限信息
    ├── lru_queue —— LRU 淘汰队列 (dc_lru_queue_t)
    ├── roles[] —— 角色数组 (dc_role_t)
    └── spm —— SQL Plan Management

    DC Entry(字典入口)

    dc_entry_t 是对象的轻量级元数据,始终驻留内存,包含:

    • 对象 ID、名称、用户、类型(表/视图/同义词)
    • 创建 SCN / 变更 SCN(org_scn, chg_scn)
    • Schema 锁(sch_lock)协调 DDL/DML 并发
    • 引用计数(ref_count)防止使用中被淘汰
    • 指向 dc_entity_t 的指针(可能为 NULL)

    源码定义: knl_dc.h

    DC 查找机制(Hash)

    DC 使用哈希桶(dc_bucket_t)实现 O(1) 查找:

    typedef struct st_dc_bucket {
    spinlock_t lock;
    uint32 first; // 哈希链表首节点索引
    } dc_bucket_t;

    查找流程:dc_open() → dc_find() → 哈希计算 → 遍历哈希桶链表 → 匹配对象名 → 获取 Entry。

    DC 淘汰策略(LRU)

    Entity 通过 LRU 双向链表管理。访问时移到链表头(最近使用),内存不足时从链表尾(最久未用)淘汰并释放内存:

    typedef struct st_dc_lru_queue {
    spinlock_t lock;
    uint32 count;
    dc_entity_t *head; // 最近使用
    dc_entity_t *tail; // 最久未用
    } dc_lru_queue_t;

    DC 统计计数器

    • entry_hwm / entry_lwm:Entry 高水位 / 低水位
    • entity->ref_count:Entity 引用计数(原子操作)
    • lru_queue->count:LRU 队列中 Entity 数量
    • ctx->version:字典版本号(DDL 变更时递增)

    DDL 元数据同步

    DDL 跨节点广播

    集群模式下 DDL 操作通过 MES 层广播逻辑日志 到所有存活节点:

    节点B (接收)

    MES 通信层

    节点A (DDL执行)

    节点B (接收)

    MES 通信层

    节点A (DDL执行)

    #mermaid-svg-VWshK7cvslgwVrfM{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-VWshK7cvslgwVrfM .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-VWshK7cvslgwVrfM .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-VWshK7cvslgwVrfM .error-icon{fill:#552222;}#mermaid-svg-VWshK7cvslgwVrfM .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-VWshK7cvslgwVrfM .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-VWshK7cvslgwVrfM .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-VWshK7cvslgwVrfM .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-VWshK7cvslgwVrfM .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-VWshK7cvslgwVrfM .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-VWshK7cvslgwVrfM .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-VWshK7cvslgwVrfM .marker{fill:#333333;stroke:#333333;}#mermaid-svg-VWshK7cvslgwVrfM .marker.cross{stroke:#333333;}#mermaid-svg-VWshK7cvslgwVrfM svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-VWshK7cvslgwVrfM p{margin:0;}#mermaid-svg-VWshK7cvslgwVrfM .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-VWshK7cvslgwVrfM text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-VWshK7cvslgwVrfM .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-VWshK7cvslgwVrfM .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-VWshK7cvslgwVrfM .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-VWshK7cvslgwVrfM .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-VWshK7cvslgwVrfM #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-VWshK7cvslgwVrfM .sequenceNumber{fill:white;}#mermaid-svg-VWshK7cvslgwVrfM #sequencenumber{fill:#333;}#mermaid-svg-VWshK7cvslgwVrfM #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-VWshK7cvslgwVrfM .messageText{fill:#333;stroke:none;}#mermaid-svg-VWshK7cvslgwVrfM .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-VWshK7cvslgwVrfM .labelText,#mermaid-svg-VWshK7cvslgwVrfM .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-VWshK7cvslgwVrfM .loopText,#mermaid-svg-VWshK7cvslgwVrfM .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-VWshK7cvslgwVrfM .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-VWshK7cvslgwVrfM .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-VWshK7cvslgwVrfM .noteText,#mermaid-svg-VWshK7cvslgwVrfM .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-VWshK7cvslgwVrfM .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-VWshK7cvslgwVrfM .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-VWshK7cvslgwVrfM .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-VWshK7cvslgwVrfM .actorPopupMenu{position:absolute;}#mermaid-svg-VWshK7cvslgwVrfM .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-VWshK7cvslgwVrfM .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-VWshK7cvslgwVrfM .actor-man circle,#mermaid-svg-VWshK7cvslgwVrfM line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-VWshK7cvslgwVrfM :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

    执行 DDL (CREATE TABLE)

    修改系统表

    生成逻辑日志 (rd_create_table_t)

    dtc_sync_ddl_internal()

    MES_CMD_DDL_BROADCAST

    dcs_process_ddl_broadcast()

    dtc_refresh_ddl(session, log)

    rd_create_table() 重放

    MES_CMD_DDL_BROADCAST_ACK

    ACK 回收

    DDL Redo

    DDL 操作自动生成逻辑日志(logic_op_t),包含操作类型和元数据快照。重放函数通过 g_logic_lmgrs[] 表注册:

    操作类型重放函数说明
    RD_CREATE_TABLE rd_create_table() 创建 Entry,标记就绪
    RD_DROP_TABLE rd_drop_table() 失效 Entity,移除 Entry
    RD_ALTER_TABLE rd_alter_table() 失效旧 Entity,重新加载
    RD_RENAME_TABLE rd_rename_table() 更新 Entry 名称
    RD_CREATE_USER rd_create_user() 创建用户缓存
    RD_CREATE_INDEX rd_alter_table() 索引变更复用 alter 路径

    源码位置: dc_log.c

    元数据版本号(meta_version)

    dc_context_t.version 是字典全局版本号,每次 DDL 变更时递增,用于快速判断缓存是否需要刷新。

    DC 失效通知

    DDL 重放时对受影响的对象执行失效操作:

  • ALTER TABLE → rd_invalid_entity() 标记 Entity 无效
  • 重新加载系统表 → dc_load_entity() 重建 Entity
  • 释放旧 Entity → dc_close_entity() 归还到 LRU
  • 通过 Schema 锁(sch_lock_mutex)保证失效期间无并发 DML 访问。


    元数据查找机制

    从 SQL 到 DC 查找的路径

    #mermaid-svg-XHMce7TfTQStMVKB{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-XHMce7TfTQStMVKB .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-XHMce7TfTQStMVKB .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-XHMce7TfTQStMVKB .error-icon{fill:#552222;}#mermaid-svg-XHMce7TfTQStMVKB .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-XHMce7TfTQStMVKB .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-XHMce7TfTQStMVKB .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-XHMce7TfTQStMVKB .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-XHMce7TfTQStMVKB .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-XHMce7TfTQStMVKB .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-XHMce7TfTQStMVKB .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-XHMce7TfTQStMVKB .marker{fill:#333333;stroke:#333333;}#mermaid-svg-XHMce7TfTQStMVKB .marker.cross{stroke:#333333;}#mermaid-svg-XHMce7TfTQStMVKB svg{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-XHMce7TfTQStMVKB p{margin:0;}#mermaid-svg-XHMce7TfTQStMVKB .label{font-family:\”trebuchet ms\”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-XHMce7TfTQStMVKB .cluster-label text{fill:#333;}#mermaid-svg-XHMce7TfTQStMVKB .cluster-label span{color:#333;}#mermaid-svg-XHMce7TfTQStMVKB .cluster-label span p{background-color:transparent;}#mermaid-svg-XHMce7TfTQStMVKB .label text,#mermaid-svg-XHMce7TfTQStMVKB span{fill:#333;color:#333;}#mermaid-svg-XHMce7TfTQStMVKB .node rect,#mermaid-svg-XHMce7TfTQStMVKB .node circle,#mermaid-svg-XHMce7TfTQStMVKB .node ellipse,#mermaid-svg-XHMce7TfTQStMVKB .node polygon,#mermaid-svg-XHMce7TfTQStMVKB .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-XHMce7TfTQStMVKB .rough-node .label text,#mermaid-svg-XHMce7TfTQStMVKB .node .label text,#mermaid-svg-XHMce7TfTQStMVKB .image-shape .label,#mermaid-svg-XHMce7TfTQStMVKB .icon-shape .label{text-anchor:middle;}#mermaid-svg-XHMce7TfTQStMVKB .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-XHMce7TfTQStMVKB .rough-node .label,#mermaid-svg-XHMce7TfTQStMVKB .node .label,#mermaid-svg-XHMce7TfTQStMVKB .image-shape .label,#mermaid-svg-XHMce7TfTQStMVKB .icon-shape .label{text-align:center;}#mermaid-svg-XHMce7TfTQStMVKB .node.clickable{cursor:pointer;}#mermaid-svg-XHMce7TfTQStMVKB .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-XHMce7TfTQStMVKB .arrowheadPath{fill:#333333;}#mermaid-svg-XHMce7TfTQStMVKB .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-XHMce7TfTQStMVKB .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-XHMce7TfTQStMVKB .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-XHMce7TfTQStMVKB .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-XHMce7TfTQStMVKB .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-XHMce7TfTQStMVKB .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-XHMce7TfTQStMVKB .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-XHMce7TfTQStMVKB .cluster text{fill:#333;}#mermaid-svg-XHMce7TfTQStMVKB .cluster span{color:#333;}#mermaid-svg-XHMce7TfTQStMVKB div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\”trebuchet ms\”,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-XHMce7TfTQStMVKB .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-XHMce7TfTQStMVKB rect.text{fill:none;stroke-width:0;}#mermaid-svg-XHMce7TfTQStMVKB .icon-shape,#mermaid-svg-XHMce7TfTQStMVKB .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-XHMce7TfTQStMVKB .icon-shape p,#mermaid-svg-XHMce7TfTQStMVKB .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-XHMce7TfTQStMVKB .icon-shape .label rect,#mermaid-svg-XHMce7TfTQStMVKB .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-XHMce7TfTQStMVKB .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-XHMce7TfTQStMVKB .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-XHMce7TfTQStMVKB :root{–mermaid-font-family:\”trebuchet ms\”,verdana,arial,sans-serif;}

    未找到

    找到

    SQL 查询

    解析器获取表名

    dc_open 打开字典句柄

    字典就绪?

    ERR_DATABASE_NOT_AVAILABLE

    dc_open_user 打开用户

    double_hash_find哈希查找对象

    ERR_TABLE_OR_VIEW_NOT_EXIST

    entry->entity 是否为 NULL?

    dc_load_entity 从系统表加载

    增加引用计数, 返回 knl_dictionary_t

    表名/列名解析

    • 表名解析: dc_find() → 哈希桶查找 → dc_entry_t 匹配 name
    • 列名解析: dc_entity_t.column_groups → 列名哈希索引 → knl_column_t

    权限检查

    dc_open 过程中隐含用户级权限验证:

    • dc_open_user_by_id() 检查用户存在性和状态
    • 对象级权限(SELECT/INSERT/UPDATE/DELETE)在 SQL 执行路径中通过 dc_user_t.sys_privs 和 dc_obj_priv_t 检查

    数据字典视图

    动态视图(DV_*)

    Cantian 提供一系列动态视图(以 DV_ 前缀命名),实时反映内存中 DC 缓存状态:

    视图说明
    DV_DC_OBJECTS 字典缓存中的对象列表(表/视图/索引)
    DV_DC_USERS 字典缓存中的用户信息
    DV_DC_ROLES 字典缓存中的角色信息
    DV_SYS_TABLES 系统表列表
    DV_SYS_COLUMNS 系统列定义列表
    DV_SYS_INDEXES 系统索引定义列表

    静态视图

    静态视图(SYS_VIEW$ 中的用户视图)通过 DC 中存储的 SQL 文本定义,查询时动态解析执行。

    视图定义与实现

    动态视图通过 dynview_desc_t 描述,注册到 g_dynview_desc[] 全局表。查询动态视图时直接调用对应的回调函数从内存中收集数据。

    源码位置: knl_dynview.h


    元数据持久化

    Catalog 表数据的持久化

    系统表数据通过以下路径持久化:

  • DDL 操作 → db_write_sysxxx() → 写入系统表页面(Buffer Pool)
  • Buffer Pool 脏页 → Checkpoint → 写入磁盘数据文件
  • DDL 逻辑日志 → Redo Log → 磁盘持久化
  • Checkpoint 时元数据一致性

    Checkpoint 线程(CKPT)刷脏时,系统表页面与其他数据页面一同被刷入磁盘,保证数据文件中的 Catalog 与 Redo Log 一致。

    恢复时 Catalog 重建

    崩溃恢复时:

  • Redo Apply: 从 Redo Log 重放 DDL 逻辑日志 → 重建 DC 缓存
  • DC Replay: dc_init() → 从系统表重新加载所有元数据 → 重建 Entry/Entity
  • 集群恢复: DAAC_FULL_RECOVER_SESSION 重放历史 DDL 日志 → 恢复 DC 状态

  • 关键数据结构与代码入口

    关键数据结构

    结构定义位置说明
    dc_context_t knl_dc.h 字典上下文,聚合所有缓存
    dc_entry_t knl_dc.h 轻量元数据入口,常驻内存
    dc_entity_t knl_dc.h 完整元数据实体,含列/索引/分区
    dc_user_t knl_dc.h 用户对象,聚合 Entry 和权限
    dc_bucket_t knl_dc.h 哈希桶,O(1) 定位
    dc_lru_queue_t knl_dc.h LRU 淘汰队列
    knl_dictionary_t knl_dc.h 字典句柄,dc_open 返回值
    dc_role_t knl_dc.h 角色缓存
    rd_create_table_t knl_dc.h 创建表逻辑日志
    logic_op_t knl_log_type.h DDL 逻辑日志类型枚举
    schema_lock_t knl_dc.h Schema 锁,保护 DDL/DML 并发

    关键代码入口

    功能文件入口函数
    字典初始化 knl_dc.c dc_init()
    字典打开 knl_dc.c dc_open()
    字典关闭 knl_dc.c dc_close()
    Entity 加载 dc_tbl.c dc_load_entity()
    DDL 重放 dc_log.c rd_create_table(), rd_alter_table(), rd_drop_table()
    DDL 广播 dtc_dc.c dtc_sync_ddl_internal()
    DDL 接收处理 dtc_dcs.c dcs_process_ddl_broadcast()
    系统表定义 knl_ctlg.c db_sys_table(), g_sys_tables[]
    用户管理 knl_user.c dc_init_users()
    权限管理 knl_privilege.c 权限检查和缓存
    序列管理 dc_seq.c 序列缓存和 Nextval 操作

    总结

    数据字典模块通过 Catalog 系统表持久化存储元数据定义,DC 内存缓存提供 O(1) 哈希查找加速访问,两级缓存架构(Entry 常驻 + Entity LRU 按需淘汰)在内存与性能之间取得平衡。DDL 操作通过 MES 层广播逻辑日志到集群所有节点,配合 meta_version 版本号和 Schema 锁保证并发安全。崩溃恢复时通过 Redo Apply 和 DC Replay 重建完整的缓存状态。

    关键源码索引

    文件路径关键函数功能说明
    pkg/src/kernel/catalog/knl_dc.c dc_init(), dc_open(), dc_close() DC 字典缓存初始化/打开/关闭
    pkg/src/kernel/catalog/dc_tbl.c dc_load_entity() 从系统表加载 Entity 到缓存
    pkg/src/kernel/catalog/dc_log.c rd_create_table(), rd_alter_table(), rd_drop_table() DDL 逻辑日志重放
    pkg/src/kernel/catalog/knl_ctlg.c db_sys_table(), g_sys_tables[] 系统表定义与访问
    pkg/src/kernel/catalog/knl_user.c dc_init_users() 用户缓存初始化
    pkg/src/kernel/catalog/knl_privilege.c 权限检查函数 权限缓存与验证
    pkg/src/kernel/catalog/dc_seq.c 序列操作函数 序列缓存与 Nextval
    pkg/src/cluster/dtc_dc.c dtc_sync_ddl_internal() DDL 跨节点广播
    pkg/src/cluster/dtc_dcs.c dcs_process_ddl_broadcast() DDL 广播接收处理
    pkg/src/kernel/catalog/knl_dc.h dc_context_t, dc_entry_t, dc_entity_t DC 核心数据结构
    pkg/src/kernel/catalog/knl_dynview.h dynview_desc_t 动态视图描述符
    pkg/src/kernel/persist/knl_log_type.h logic_op_t DDL 逻辑日志类型枚举
    赞(0)
    未经允许不得转载:171主机测评 » 【参天引擎】一条 ALTER TABLE 把集群搞挂了,让我把 Cantian 数据字典的三层架构全搞明白了
    分享到: 更多 (0)

    评论 抢沙发

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址