• innodb_flush_method


    1)打开一个文件时如果加入了O_DIRECT标志位,意味着对该文件的读写操作将会绕过page cache,直接与存储设备打交道,但是这里不保证每次write返回后,该write要写入的数据已经写完。

    2)如果是带O_SYNC标志位,则不绕过pape cache, 每次write的数据不仅会在page cache里写入,还会写入存储设备,并且,O_SYNC保证每次write返回后,数据都已经写入page cache和存储设备。

    Direct I/O and Data I/O Integrity Completion

    Although direct I/O writes are done synchronously, they do not provide synchronized I/O data integrity completion, as defined by POSIX. Applications that need this feature should use O_DSYNC in addition to O_DIRECT. O_DSYNC guarantees that all of the data and enough of the metadata (for example, indirect blocks) have written to the stable store to be able to retrieve the data after a system crash. O_DIRECT only writes the data; it does not write the metadata.

    在通常的write中,实际是写的页缓存,页缓存通过周期性的flush(pdflush)或强制回写到磁盘,页缓存回写时,是通过sync_single_inode按inode来回写的,回写过程中会先调用do_writepages回写数据,然后再调用write_inode回写元数据,所以是有先后顺序的,通常也能保证一致性。

    innodb_flush_method这个参数控制着innodb数据文件及redo log的打开、刷写模式,对于这个参数,文档上是这样描述的:
    有三个值:fdatasync(默认),O_DSYNC,O_DIRECT
    默认是fdatasync,调用fsync()去刷数据文件与redo log的buffer
    为O_DSYNC时,innodb会使用O_SYNC方式打开和刷写redo log,使用fsync()刷写数据文件
    为O_DIRECT时,innodb使用O_DIRECT打开数据文件,使用fsync()刷写数据文件跟redo log

    Command-Line Format --innodb_flush_method=name
    System Variable Name innodb_flush_method
    Variable Scope Global
    Dynamic Variable No
      Permitted Values
    Type (Windows) string
    Default async_unbuffered
      Permitted Values (<= 5.1.23)
    Type (Unix) string
    Default fdatasync
    Valid Values fdatasync
    O_DSYNC
    O_DIRECT
      Permitted Values (>= 5.1.24)
    Type (Unix) string
    Default fsync
    Valid Values fsync
    O_DSYNC
    O_DIRECT
  • 相关阅读:
    Python学习笔记六:集合
    Python学习笔记五:字符串常用操作,字典,三级菜单实例
    Python学习笔记四:列表,购物车程序实例
    Python学习笔记三:数据类型
    python学习笔记二:if语句及循环语句,断点,模块,pyc
    Python学习笔记一:第一个Python程序,变量,字符编码与二进制,用户交互程序
    JS教程:从0开始
    基于Token认证的多点登录和WebApi保护
    数据库高级对象(存储过程,事务,锁,游标,触发器)
    Sql基础(零基础学数据库_SqlServer版)
  • 原文地址:https://www.cnblogs.com/javaleon/p/4029034.html
Copyright © 2020-2023  润新知