函数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 ...
随机推荐
- javascript异步执行函数导致的变量变化问题解决思路
for(var i=0;i<3;i++) { setTimeout(function(){ console.log(i) },0); }控制台输出:333 这是因为执行方法的时候for循环已经执 ...
- Java多线程同步代码块
/*多线程的安全问题1.为什么会出现安全问题?因为程序在运行时,会出现一个线程在判断条件满足后,具备了执行资格,但没有运行代码后一个线程也判断了条件,也具备了执行资格,后一个线程运行了代码,但这时候, ...
- MyBatis拦截器:给参数对象属性赋值
该拦截器的作用:在进行增加.修改等操作时,给数据模型的一些通用操作属性(如:创建人.创建时间.修改人.修改时间等)自动赋值. 该实现是在DAO层拦截,即存入DB前最后一层.后经分析,不是很合理,改为在 ...
- 英语中的 姓氏/Surname
.Chomsky (Belarusian: Хомскі, Russian: Хомский, Ukrainian: Хомський, Hebrew: חומסקי, "from (V ...
- 将博客搬迁至CSDN
CSDN不给我搬家就算了....我自己搬= = http://blog.csdn.net/ourfutr2330
- C++对象模型与内存位对齐的简单分析(GNU GCC&VS2015编译器)
以Fruit和Apple为例进行分析: Fruit和Apple的定义如下: 通过在两种编译环境下的测试(GNU GCC & VS2015),可以发现这两种编译器的对象模型是一样的,如下图所示: ...
- How to debug Custom Action DLL
在MSI工程中,经常会遇到这样的情况: MSI 工程需要调用DLL(C++)中的一个函数实现某些特殊或者复杂的功能,通常的做法是在Custom Action 中调用该DLL . 那么在安装过程中,该C ...
- 【译】velocity
本文原文地址:http://davidwalsh.name/intro-javascript-animation 就像许多开发者确信的那样,在Web上使用CSS实现动画并不是唯一的方式,我们也可以使用 ...
- C# 读取快捷方式指向的文件
C# 读取快捷方式指向的文件 [Flags()] public enum SLR_FLAGS { SLR_NO_UI = 0x1, SLR_ANY_MATCH = 0x2, SLR_UPDATE = ...
- Entity Framework多对多关联映射的实现
Entity Framework是微软官方提供的一个ORM解决方案,它有纯正的血统,比NHibernate更容易使用并且与现有其它官方框架配合更加密切. 时代不断的在发展变化,记得10年前还是ADO( ...