[INNODB] ibd文件之结构组成与空间分配

ibd是一个完整的表空间文件,其中最基本的单位为页(Page),一个Page通常为16k。page有不同的种类,用于不同类型的用途。

在介绍页文件的分类前,我们先介绍对页进行分类管理的2个页组。

extend

extend,也叫作区,用于分配页。一个extend有64个连续的页,也就是1MB。当表空间页不足了要分配新页的时候,不会一页一页的分配,而是直接分配一个extend。

segment

segment,也叫作段,用于管理extend,一个表至少会占有2个segment,一个segment用来管理nonleaf page所在的extend,另一个用于管理leaf page所在的extend。每多一个索引,segment会多2个。

下面来介绍常见的page的类型以及其用途。

Page

Page是ibd文件最基本的单位,无论page类型,每种page的基础结构为:

type Page struct {
    // Start with file header
    fheader FileHeader
    // page body
    // checksum && lsn
    trailer [8]byte
}

每个page都有一个头部,还有一个尾部。头部标识了类型、checksum等信息,尾部标识了checksum等信息用于确认该页是否写入完整。根据头部的page类型标识,我们可以将page body解析成对应的类型,主要有以下几种类型:

file space header / xdes

这两个page类型其实使用了一种page结构。该类型的page主要用于管理extend的分配和所属的segment。在这两个page的extend管理部分,主要标识了多少个extend已经被分配,每个extend内page的使用情况等等。

首先介绍下几个通用引用结构,一个是ListBaseNode,它的含义是指向了首尾元素,并标识了长度;还有一个是ListNode,用于双向链表,也就是指向它的前一个或者后一个元素。

该页的结构大致为:

type FSPHeader struct {
    // The space ID of the current space.
    spaceID uint32
    unused  uint32
    // The “size” is the highest valid page number, and is incremented
    // when the file is grown. However, not all of these pages are initialized
    // (some may be zero-filled), as extending a space is a multi-step process.
    highestPageNumberInFile uint32
    // The “free limit” is the highest page number for which the FIL header has
    // been initialized, storing the page number in the page itself, amongst other things.
    // The free limit will always be less than or equal to the size.
    highestPageNumberInitialized uint32
    // Storage of flags related to the space.
    Flags uint32
    //
    pagesUsedInFreeFrag uint32
    // Extents that are completely unused and available to be allocated in
    // whole to some purpose. A FREE extent could be allocated to a file
    // segment (and placed on the appropriate INODE list), or moved
    // to the FREE_FRAG list for individual page use.
    freeList ListBaseNode
    // Extents with free pages remaining that are allocated to be used in “fragments”,
    // having individual pages allocated to different purposes rather than allocating
    // the entire 
  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值