1. /********************************************************************//**
  2. Initializes a page to the buffer buf_pool. The page is usually not read
  3. from a file even if it cannot be found in the buffer buf_pool. This is one
  4. of the functions which perform to a block a state transition NOT_USED =>
  5. FILE_PAGE (the other is buf_page_get_gen).
  6. @return pointer to the block, page bufferfixed */
  7. UNIV_INTERN
  8. buf_block_t*
  9. buf_page_create(
  10. /*============*/
  11. ulint space, /*!< in: space id */
  12. ulint offset, /*!< in: offset of the page within space in units of
  13. a page */
  14. ulint zip_size,/*!< in: compressed page size, or 0 */
  15. mtr_t* mtr) /*!< in: mini-transaction handle */
  16. {
  17. buf_frame_t* frame;
  18. buf_block_t* block;
  19. ulint fold;
  20. buf_block_t* free_block = NULL;
  21. buf_pool_t* buf_pool = buf_pool_get(space, offset);//获取具体buff pool实例 详见
  22.  
  23. ut_ad(mtr);
  24. ut_ad(mtr->state == MTR_ACTIVE);
  25. ut_ad(space || !zip_size);
  26.  
  27. free_block = buf_LRU_get_free_block(buf_pool); //取得一块空闲block 这里
  28.  
  29. fold = buf_page_address_fold(space, offset); //计算hash值 详见
  30.  
  31. buf_pool_mutex_enter(buf_pool);
  32. //可忽略这个
  33. block = (buf_block_t*) buf_page_hash_get_low(buf_pool, space, offset, fold);
  34.  
  35. if (block
  36. && buf_page_in_file(&block->page)
  37. && !buf_pool_watch_is_sentinel(buf_pool, &block->page)) {
  38.  
  39. /* Page can be found in buf_pool */
  40. buf_pool_mutex_exit(buf_pool);
  41.  
  42. buf_block_free(free_block);
  43.  
  44. return(buf_page_get_with_no_latch(space, zip_size,offset, mtr));
  45. }
  46.  
  47. /* If we get here, the page was not in buf_pool: init it there */ block = free_block;
  48.  
  49. mutex_enter(&block->mutex);
  50. /** *初始化block,详见 *计算block中的lock_hash_val *将block->page放入buf_pool->page_hash中 */
  51. buf_page_init(buf_pool, space, offset, fold, zip_size, block);/* The block must be put to the LRU list */
  52. buf_LRU_add_block(&block->page, FALSE); //放入lru中,且status为old 详见
  53.  
  54. buf_block_buf_fix_inc(block, __FILE__, __LINE__);
  55. buf_pool->stat.n_pages_created++;
  56.  
  57. if (zip_size) {
  58. void* data;
  59. ibool lru;
  60.  
  61. /* Prevent race conditions during buf_buddy_alloc(),
  62. which may release and reacquire buf_pool->mutex,
  63. by IO-fixing and X-latching the block. */
  64.  
  65. buf_page_set_io_fix(&block->page, BUF_IO_READ);
  66. rw_lock_x_lock(&block->lock);
  67. mutex_exit(&block->mutex);
  68. /* buf_pool->mutex may be released and reacquired by
  69. buf_buddy_alloc(). Thus, we must release block->mutex
  70. in order not to break the latching order in
  71. the reacquisition of buf_pool->mutex. We also must
  72. defer this operation until after the block descriptor
  73. has been added to buf_pool->LRU and buf_pool->page_hash. */
  74. data = buf_buddy_alloc(buf_pool, zip_size, &lru);
  75. mutex_enter(&block->mutex);
  76. block->page.zip.data = data;
  77.  
  78. /* To maintain the invariant
  79. block->in_unzip_LRU_list
  80. == buf_page_belongs_to_unzip_LRU(&block->page)
  81. we have to add this block to unzip_LRU after
  82. block->page.zip.data is set. */
  83. ut_ad(buf_page_belongs_to_unzip_LRU(&block->page));
  84. buf_unzip_LRU_add_block(block, FALSE);
  85.  
  86. buf_page_set_io_fix(&block->page, BUF_IO_NONE);
  87. rw_lock_x_unlock(&block->lock);
  88. }
  89.  
  90. buf_pool_mutex_exit(buf_pool);
  91.  
  92. mtr_memo_push(mtr, block, MTR_MEMO_BUF_FIX);
  93.  
  94. buf_page_set_accessed(&block->page);
  95.  
  96. mutex_exit(&block->mutex);
  97.  
  98. /* Delete possible entries for the page from the insert buffer:
  99. such can exist if the page belonged to an index which was dropped */
  100.  
  101. ibuf_merge_or_delete_for_page(NULL, space, offset, zip_size, TRUE);
  102.  
  103. /* Flush pages from the end of the LRU list if necessary */
  104. buf_flush_free_margin(buf_pool);
  105. /** *取出block中的frame *block结构体 详见 */
  106. frame = block->frame;
  107. */
  108. memset(frame + FIL_PAGE_PREV, );
  109. memset(frame + FIL_PAGE_NEXT, );
  110. mach_write_to_2(frame + FIL_PAGE_TYPE, FIL_PAGE_TYPE_ALLOCATED);
  111.  
  112. /* Reset to zero the file flush lsn field in the page; if the first
  113. page of an ibdata file is 'created' in this function into the buffer
  114. pool then we lose the original contents of the file flush lsn stamp.
  115. Then InnoDB could in a crash recovery print a big, false, corruption
  116. warning if the stamp contains an lsn bigger than the ib_logfile lsn. */
  117.  
  118. memset(frame + FIL_PAGE_FILE_FLUSH_LSN, , );
  119.  
  120. return(block);
  121. }

函数buf_page_create的更多相关文章

  1. Python 小而美的函数

    python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况   any any(iterable) ...

  2. 探究javascript对象和数组的异同,及函数变量缓存技巧

    javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...

  3. JavaScript权威指南 - 函数

    函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...

  4. C++对C的函数拓展

    一,内联函数 1.内联函数的概念 C++中的const常量可以用来代替宏常数的定义,例如:用const int a = 10来替换# define a 10.那么C++中是否有什么解决方案来替代宏代码 ...

  5. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  6. javascript中的this与函数讲解

    前言 javascript中没有块级作用域(es6以前),javascript中作用域分为函数作用域和全局作用域.并且,大家可以认为全局作用域其实就是Window函数的函数作用域,我们编写的js代码, ...

  7. 复杂的 Hash 函数组合有意义吗?

    很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...

  8. JS核心系列:浅谈函数的作用域

    一.作用域(scope) 所谓作用域就是:变量在声明它们的函数体以及这个函数体嵌套的任意函数体内都是有定义的. function scope(){ var foo = "global&quo ...

  9. C++中的时间函数

    C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...

随机推荐

  1. C#中读取二维数组每位的长度

    C#中的二维数组,如int[,] A=new int[a,b];则 a=A.GetLength(0);即可获得二维数组中第一维的长度. b=A.GetLength(1);即可获得二维数组中第二维的长度 ...

  2. Python的map、filter、reduce函数 [转]

    1. map函数func作用于给定序列的每个元素,并用一个列表来提供返回值. map函数python实现代码: def map(func,seq): mapped_seq = []        fo ...

  3. unable to start within 45 seconds. If the server requires more time, try increasing the timeout in the server editor

    eclipse启动项目时,提示超时: 解决方案: 修改 workspace\.metadata\.plugins\org.eclipse.wst.server.core\servers.xml文件.  ...

  4. 解决Tomcat 7遇到StackOverflowError的异常

    参考网址:http://qingyuexiao.iteye.com/blog/1886059 前言:在写此博客前,首先感谢姚双琪.林瑞丰.网友qingyuexiao的倾囊相助!此博文不过是笔者对于他们 ...

  5. 【锋利的JQuery-学习笔记】Tab选项卡的实现

    效果图: 关键点: 1.标签和标签内容都是用<ul><li>实现的,主要是通过Css样式设计成选项卡的模样. 2.用js代码实现点击标签时,标签内容的切换(做法是<div ...

  6. 1051 Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. AutoEventWireup解释

    这一事件聚合了当前页是否自动关联某些特殊事件. 首先,从浏览器页面出发的事件不能立刻在本地得到处理,而是POST至服务器上,因此,asp.net建立了委托(代理)机制.在建立一个事件的同事,建立相应的 ...

  8. iOS Objective-C对象模型及应用

    前言 原创文章,转载请注明出自唐巧的技术博客. 本文主要介绍Objective-C对象模型的实现细节,以及Objective-C语言对象模型中对isa swizzling和method swizzli ...

  9. java使用正则表达式验证IP V4、 IP V6

    package cn.outofmemory.snippets.core; import java.util.regex.Pattern; /** * A collection of utilitie ...

  10. Nginx+Tomcat+Memcached负载均衡集群服务搭建

    操作系统:CentOS6.5  本文档主要讲解,如何在CentOS6.5下搭建Nginx+Tomcat+Memcached负载均衡集群服务器,Nginx负责负载均衡,Tomcat负责实际服务,Memc ...