函数fsp_alloc_free_page
从fsp中分配32个碎片页
/**********************************************************************//** Allocates a single free page from a space. The page is marked as used. @retval NULL if no page could be allocated @retval block, rw_lock_x_lock_count(&block->lock) == 1 if allocation succeeded (init_mtr == mtr, or the page was not previously freed in mtr) @retval block (not allocated or initialized) otherwise */ static __attribute__((nonnull, warn_unused_result)) buf_block_t* fsp_alloc_free_page( /*================*/ ulint space, /*!< in: space id */ ulint zip_size,/*!< in: compressed page size in bytes or 0 for uncompressed pages */ ulint hint, /*!< in: hint of which page would be desirable */ mtr_t* mtr, /*!< in/out: mini-transaction */ mtr_t* init_mtr)/*!< in/out: mini-transaction in which the page should be initialized (may be the same as mtr) */ { fsp_header_t* header; fil_addr_t first; xdes_t* descr; ulint free; ulint page_no; ulint space_size; ut_ad(mtr); ut_ad(init_mtr); header = fsp_get_space_header(space, zip_size, mtr); //详见 /* Get the hinted descriptor */ /** *descr 是XDES 页中第N个XDES Entry 的内存地址 * */ descr = xdes_get_descriptor_with_space_hdr(header, space, hint, mtr); //详见 /** *这个desc的类型属于XDES_FREE_FRAG 可拿来使用 *为一个段指定空间时, 先从 FSP中的碎片区中取,若拿不至,再分配extent * */ if (descr && (xdes_get_state(descr, mtr) == XDES_FREE_FRAG)) { //详见 /* Ok, we can take this extent */ //descr 所在的 xdes entry 的状态属于 free_freg 碎片 } else { //获得fsp header +40 的 free_frag 空闲碎片 //fsp中的free_frag类型是 flst_base_node_t,真正类型为byte
first = flst_get_first(header + FSP_FREE_FRAG, mtr); //详见 if (fil_addr_is_null(first)) { /* There are no partially full fragments: allocate a free extent and add it to the FREE_FRAG list. NOTE that the allocation may have as a side-effect that an extent containing a descriptor page is added to the FREE_FRAG list. But we will allocate our page from the the free extent anyway. */ descr = fsp_alloc_free_extent(space, zip_size,hint, mtr); if (descr == NULL) { /* No free space left */ return(NULL); } xdes_set_state(descr, XDES_FREE_FRAG, mtr); flst_add_last(header + FSP_FREE_FRAG, descr + XDES_FLST_NODE, mtr); } else { descr = xdes_lst_get_descriptor(space, zip_size, first, mtr); } /* Reset the hint */ hint = ; } /* Now we have in descr an extent with at least one free page. Look for a free page in the extent. */ free = xdes_find_bit(descr, XDES_FREE_BIT, TRUE,hint % FSP_EXTENT_SIZE, mtr); //详见 if (free == ULINT_UNDEFINED) { ut_print_buf(stderr, ((, ); putc('\n', stderr); ut_error; } page_no = xdes_get_offset(descr) + free; //计算出某一bit的page_no 详见 space_size = mtr_read_ulint(header + FSP_SIZE, MLOG_4BYTES, mtr); if (space_size <= page_no) { /* It must be that we are extending a single-table tablespace whose size is still < 64 pages */ ut_a(space != ); if (page_no >= FSP_EXTENT_SIZE) { fprintf(stderr, "InnoDB: Error: trying to extend a" " single-table tablespace %lu\n" "InnoDB: by single page(s) though the" " space size %lu. Page no %lu.\n", (ulong) space, (ulong) space_size, (ulong) page_no); return(NULL); } if (!fsp_try_extend_data_file_with_pages(space, page_no, header, mtr)) { /* No disk space left */ return(NULL); } } fsp_alloc_from_free_frag(header, descr, free, mtr);//详见 return(fsp_page_create(space, zip_size, page_no, mtr, init_mtr)); }
函数fsp_alloc_free_page的更多相关文章
- MySQL ·InnoDB 文件系统之文件物理结构
从上层的角度来看,InnoDB层的文件,除了redo日志外,基本上具有相当统一的结构,都是固定block大小,普遍使用的btree结构来管理数据.只是针对不同的block的应用场景会分配不同的页类型. ...
- Python 小而美的函数
python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况 any any(iterable) ...
- 探究javascript对象和数组的异同,及函数变量缓存技巧
javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...
- JavaScript权威指南 - 函数
函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...
- C++对C的函数拓展
一,内联函数 1.内联函数的概念 C++中的const常量可以用来代替宏常数的定义,例如:用const int a = 10来替换# define a 10.那么C++中是否有什么解决方案来替代宏代码 ...
- 菜鸟Python学习笔记第一天:关于一些函数库的使用
2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...
- javascript中的this与函数讲解
前言 javascript中没有块级作用域(es6以前),javascript中作用域分为函数作用域和全局作用域.并且,大家可以认为全局作用域其实就是Window函数的函数作用域,我们编写的js代码, ...
- 复杂的 Hash 函数组合有意义吗?
很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...
- JS核心系列:浅谈函数的作用域
一.作用域(scope) 所谓作用域就是:变量在声明它们的函数体以及这个函数体嵌套的任意函数体内都是有定义的. function scope(){ var foo = "global&quo ...
随机推荐
- 转:jQuery对象与dom对象的转换
jQuery对象与dom对象的转换 发布时间:September 20, 2007 分类:JavaScript <新站上线的手记> <Discuz!多附件上传选择框之jQuery版& ...
- [leetcode] 405. Convert a Number to Hexadecimal
https://leetcode.com/contest/6/problems/convert-a-number-to-hexadecimal/ 分析:10进制转换成16进制,不能用库函数,刚开始,我 ...
- msyql判断记录是否存在的三种方法
1. select count(*) from .... 这种方法最常见但是效率比较低,因为它需要扫描所有满足条件的记录 2. select 1 from xxxtable where .... 这种 ...
- 关于js与php互相传值的介绍【转载+自身总结】
JS是前台的语言,PHP是后台的语言,初学时会经常出现前后台分不清的情况(我当初就是这样的,现在有时也在犯),我当初的想法是就把前后台当成两个岛,他们是无法跨越的,HTML就像一座桥,当你想要把一座岛 ...
- MySQL二进制文件规范安装
演示环境介绍 操作系统:CentOS 6.7 (64位) 二进制包:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz MySQL 下载地址:http://dev.m ...
- MVC文件上传 - 使用jquery异步上传并客户端验证类型和大小
本篇体验MVC上传文件,从表单上传过渡到jquery异步上传. MVC最基本的上传文件是通过form表单提交方式 □ 前台视图部分 <% using(Html.BeginForm("F ...
- 多站点FTP同步
需求描述: 由于工作的原因,发布程序时,经常需要将一站点的脚本.程序同步到其它的终端站点中,以保证所有站点的程序是同步的,用过FlashFtp,CuteFtp,LeapFtp等客户端工具,均于自己的需 ...
- PS初始化配置
前端工程师在使用photoshop之前需要进行一些初始化设置,主要包括以下3个 [1]首选项设置 <ctrl+k> 编辑 > 首选项 > 单位与标尺 > 把标尺和文字的单 ...
- mysql索引使用笔记
1.使用explain语句查看性能mysql> explain select product_id from orders where order_id in (123, 312, 223, 1 ...
- (转载)Delphi开发经验谈
Delphi开发经验谈 开发环境-------- Delphi 7是一个很经典的版本,在Win2000/XP下推荐安装Delphi 7来开发软件,在Vista下推荐使用Delphi 2007开发软件. ...