1. /********************************************************************//**
  2. Reads or writes data. This operation is asynchronous (aio).
  3. @return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do
  4. i/o on a tablespace which does not exist */
  5. UNIV_INTERN
  6. ulint
  7. fil_io(
  8. /*===*/
  9. ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE,
  10. ORed to OS_FILE_LOG, if a log i/o
  11. and ORed to OS_AIO_SIMULATED_WAKE_LATER
  12. if simulated aio and we want to post a
  13. batch of i/os; NOTE that a simulated batch
  14. may introduce hidden chances of deadlocks,
  15. because i/os are not actually handled until
  16. all have been posted: use with great
  17. caution! */
  18. ibool sync, /*!< in: TRUE if synchronous aio is desired */
  19. ulint space_id, /*!< in: space id */
  20. ulint zip_size, /*!< in: compressed page size in bytes;
  21. 0 for uncompressed pages */
  22. ulint block_offset, /*!< in: offset in number of blocks */
  23. ulint byte_offset, /*!< in: remainder of offset in bytes; in
  24. aio this must be divisible by the OS block
  25. size */
  26. ulint len, /*!< in: how many bytes to read or write; this
  27. must not cross a file boundary; in aio this
  28. must be a block size multiple */
  29. void* buf, /*!< in/out: buffer where to store read data
  30. or from where to write; in aio this must be
  31. appropriately aligned */
  32. void* message) /*!< in: message for aio handler if non-sync
  33. aio used, else ignored */
  34. {
  35. ulint mode;
  36. fil_space_t* space;
  37. fil_node_t* node;
  38. ulint offset_high;
  39. ulint offset_low;
  40. ibool ret;
  41. ulint is_log;
  42. ulint wake_later;
  43.  
  44. is_log = type & OS_FILE_LOG;
  45. type = type & ~OS_FILE_LOG;
  46.  
  47. wake_later = type & OS_AIO_SIMULATED_WAKE_LATER;
  48. type = type & ~OS_AIO_SIMULATED_WAKE_LATER;
  49.  
  50. ut_ad(byte_offset < UNIV_PAGE_SIZE);
  51. ut_ad(!zip_size || !byte_offset);
  52. ut_ad(ut_is_2pow(zip_size));
  53. ut_ad(buf);
  54. ut_ad(len > );
  55. #if (1 << UNIV_PAGE_SIZE_SHIFT) != UNIV_PAGE_SIZE
  56. # error "(1 << UNIV_PAGE_SIZE_SHIFT) != UNIV_PAGE_SIZE"
  57. #endif
  58. ut_ad(fil_validate_skip());
  59. #ifndef UNIV_HOTBACKUP
  60. # ifndef UNIV_LOG_DEBUG
  61. /* ibuf bitmap pages must be read in the sync aio mode: */
  62. ut_ad(recv_no_ibuf_operations || (type == OS_FILE_WRITE)
  63. || !ibuf_bitmap_page(zip_size, block_offset)
  64. || sync || is_log);
  65. # endif /* UNIV_LOG_DEBUG */
  66. if (sync) {
  67. mode = OS_AIO_SYNC;
  68. } else if (is_log) {
  69. mode = OS_AIO_LOG;
  70. } else if (type == OS_FILE_READ
  71. && !recv_no_ibuf_operations
  72. && ibuf_page(space_id, zip_size, block_offset, NULL)) {
  73. mode = OS_AIO_IBUF;
  74. } else {
  75. mode = OS_AIO_NORMAL;
  76. }
  77. #else /* !UNIV_HOTBACKUP */
  78. ut_a(sync);
  79. mode = OS_AIO_SYNC;
  80. #endif /* !UNIV_HOTBACKUP */
  81.  
  82. if (type == OS_FILE_READ) {
  83. srv_data_read+= len;
  84. } else if (type == OS_FILE_WRITE) {
  85. srv_data_written+= len;
  86. }
  87.  
  88. /* Reserve the fil_system mutex and make sure that we can open at
  89. least one file while holding it, if the file is not already open */
  90.  
  91. fil_mutex_enter_and_prepare_for_io(space_id);
  92.  
  93. space = fil_space_get_by_id(space_id);
  94.  
  95. /* If we are deleting a tablespace we don't allow any read
  96. operations on that. However, we do allow write operations. */
  97. if (!space || (type == OS_FILE_READ && space->stop_new_ops)) {
  98. mutex_exit(&fil_system->mutex);
  99.  
  100. ut_print_timestamp(stderr);
  101. fprintf(stderr,
  102. " InnoDB: Error: trying to do i/o"
  103. " to a tablespace which does not exist.\n"
  104. "InnoDB: i/o type %lu, space id %lu,"
  105. " page no. %lu, i/o length %lu bytes\n",
  106. (ulong) type, (ulong) space_id, (ulong) block_offset,
  107. (ulong) len);
  108.  
  109. return(DB_TABLESPACE_DELETED);
  110. }
  111.  
  112. ut_ad((mode != OS_AIO_IBUF) || (space->purpose == FIL_TABLESPACE));
  113.  
  114. node = UT_LIST_GET_FIRST(space->chain);
  115.  
  116. for (;;) {
  117. if (UNIV_UNLIKELY(node == NULL)) {
  118. fil_report_invalid_page_access(
  119. block_offset, space_id, space->name,
  120. byte_offset, len, type);
  121.  
  122. ut_error;
  123. }
  124.  
  125. && node->size == ) {
  126. /* We do not know the size of a single-table tablespace
  127. before we open the file */
  128.  
  129. break;
  130. }
  131.  
  132. if (node->size > block_offset) {
  133. /* Found! */
  134. break;
  135. } else {
  136. block_offset -= node->size;
  137. node = UT_LIST_GET_NEXT(chain, node);
  138. }
  139. }
  140.  
  141. /* Open file if closed */
  142. fil_node_prepare_for_io(node, fil_system, space);
  143.  
  144. /* Check that at least the start offset is within the bounds of a
  145. single-table tablespace */
  146. if (UNIV_UNLIKELY(node->size <= block_offset)
  147. && space->id != && space->purpose == FIL_TABLESPACE) {
  148.  
  149. fil_report_invalid_page_access(
  150. block_offset, space_id, space->name, byte_offset,
  151. len, type);
  152.  
  153. ut_error;
  154. }
  155.  
  156. /* Now we have made the changes in the data structures of fil_system */
  157. mutex_exit(&fil_system->mutex);
  158.  
  159. /* Calculate the low 32 bits and the high 32 bits of the file offset */
  160.  
  161. if (!zip_size) {
  162. offset_high = (block_offset >> ( - UNIV_PAGE_SIZE_SHIFT));
  163. offset_low = ((block_offset << UNIV_PAGE_SIZE_SHIFT)
  164. & 0xFFFFFFFFUL) + byte_offset;
  165.  
  166. ut_a(node->size - block_offset
  167. >= ((byte_offset + len + (UNIV_PAGE_SIZE - ))
  168. / UNIV_PAGE_SIZE));
  169. } else {
  170. ulint zip_size_shift;
  171. switch (zip_size) {
  172. : zip_size_shift = ; break;
  173. : zip_size_shift = ; break;
  174. : zip_size_shift = ; break;
  175. : zip_size_shift = ; break;
  176. : zip_size_shift = ; break;
  177. default: ut_error;
  178. }
  179. offset_high = block_offset >> ( - zip_size_shift);
  180. offset_low = (block_offset << zip_size_shift & 0xFFFFFFFFUL)
  181. + byte_offset;
  182. ut_a(node->size - block_offset
  183. >= (len + (zip_size - )) / zip_size);
  184. }
  185.  
  186. /* Do aio */
  187.  
  188. ut_a(byte_offset % OS_FILE_LOG_BLOCK_SIZE == );
  189. ut_a((len % OS_FILE_LOG_BLOCK_SIZE) == );
  190.  
  191. #ifdef UNIV_HOTBACKUP
  192. /* In ibbackup do normal i/o, not aio */
  193. if (type == OS_FILE_READ) {
  194. ret = os_file_read(node->handle, buf, offset_low, offset_high,len); //详见
  195. } else {
  196. ret = os_file_write(node->name, node->handle, buf,
  197. offset_low, offset_high, len);
  198. }
  199. #else
  200. /* Queue the aio request */
  201. ret = os_aio(type, mode | wake_later, node->name, node->handle, buf,
  202. offset_low, offset_high, len, node, message);
  203. #endif
  204. ut_a(ret);
  205.  
  206. if (mode == OS_AIO_SYNC) {
  207. /* The i/o operation is already completed when we return from
  208. os_aio: */
  209.  
  210. mutex_enter(&fil_system->mutex);
  211.  
  212. fil_node_complete_io(node, fil_system, type);
  213.  
  214. mutex_exit(&fil_system->mutex);
  215.  
  216. ut_ad(fil_validate_skip());
  217. }
  218.  
  219. return(DB_SUCCESS);
  220. }

函数fil_io的更多相关文章

  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. XCODE真机调试设备连接一直忙碌如何处理

    只是还没反应过来 等一会就行了

  2. duilib中各控件响应的消息类型

    消息 说明 Sender click 鼠标点击 CButtonUI dropdown 下拉显示 CComboUI headerclick 点击列标题 CListHeaderItemUI itemact ...

  3. java.util.ConcurrentModificationException 解决办法(转)

    今天在项目的中有一个需求,需要在一个Set类型的集合中删除满足条件的对象,这时想当然地想到直接调用Set的remove(Object o)方法将指定的对象删除即可,测试代码:   public cla ...

  4. JNI中使用cl命令生成DLL文件

    问题描述:     在使用JNI调用DLL时,首先需要生成DLL文件 问题解决:     (1)现在使用VS2008的cl.exe程序,生成DLL文件 (1.1)cl.exe环境搭建 注:   cl. ...

  5. oracle——表修改语句集合

     alter table table_name modify column_name default 0; 

  6. PE文件结构详解(六)重定位

    前面两篇 PE文件结构详解(四)PE导入表 和 PE文件结构详解(五)延迟导入表 介绍了PE文件中比较常用的两种导入方式,不知道大家有没有注意到,在调用导入函数时系统生成的代码是像下面这样的: 在这里 ...

  7. Castle 开发系统文章

    转: http://www.cnblogs.com/Jebel/archive/2008/06/24/1228766.html

  8. Firefox下网页缩放时防止div被挤到下一层

    http://wu110cheng.blog.163.com/blog/static/13334965420121120102439190/ Firefox下网页缩放时防止div被挤到下一层 问题:三 ...

  9. 跨线程调用控件之MethodInvoker

    原文:http://www.cnblogs.com/cm8448940/archive/2008/07/10/1240045.html 使用到两个控件,一个按钮button1,一个标签label1. ...

  10. linux上部署应用

    1.编写traffic.sh 引入相关的jar包及java环境路径 2.crontab -e 加入: */10 * * * * cd /opt/sys/traffic_version/bin & ...