LevelDB 01: 数据安全 2019-09-09

目录:

  • 1. 原子性 Atomicity
  • 2. Consistency
  • 2.1 有没有事务, log没有保存旧值, 如何撤销?
  • 2.2 (TODO)基于leveldb, filestore 是否实现了 事务/commit等?
  • 3. log
  • 3.1 写log在哪里
  • 4. RecoverLogFile
  • 5. VersionSet::Recover

  • 1. 原子性 Atomicity

    ReadPhysicalRecord():

    1. header eof, 但读到的<kHeaderSize, 则知道header不完整.
    2. header完整, 但对应的payload数据不够.
    3. 检查 checksum

    推荐C++编辑器 Clion 2018-11-27

    备注: 然而, 2019年, 本人还是使用通过slickedit阅读代码, 主要是看中其快捷键自定义功能. 2021年: 现在使用 vscode+ccls

    1. 优点

    • c++中支持以 namespace::method 的方式来搜索symbol. (vscode中仅在当前文件时, 才可alt+n navigate) (slickedit通过context tagging可以搜索到)
    • 支持重构, 比如重命名之类的, 不必到处替换.
    • 支持 your_filename.c:846:14 直接跳转到指定的行和列. 在编译出错后, 复制出错信息, 然后 ctrl+shift+n, 然后粘贴类似 your_path/your_filename.c:846:14 来打开文件. (vscode中是 ctrl+p goto to file)
    • 好用的 "Find Usages", 就是查看谁使用了这个函数, 并不是基于字符串搜索. 比如, 对leveldb/db/version_set.cc的Version::Get使用Find Usages, 会跳转到 Status DBImpl::Get()中的 s = current->Get(options, lkey, value, &stats);
    • 杂项:
      • shift 两次 (search everything), 搜索 wrap, 移动到第1项是 use soft wrap, 回车, 即可应用该选项.

    JBD初步 2018-10-25

    1. 概念

    单个handle是原子操作. 多个handle打包为一个transaction.

    disk is used to indicate the actual block device, whereas the term journal is used for the log area.

    Log record: Describes a single update of a disk block of the journaling filesystem.(来自[Understanding the Linux Kernel, 3rd Edition])

    commit record: a special block, called the commit record, is written to the journal. The commit record is used to indicate that all the blocks belonging to a single atomic operation are written to the journal. fong:这样, 如果crash, 就可以知道那些log是完成的. The commit record indicates that this is a completed operation and could be written to the disk.

    checkpointing: 将 finished transactions 写入磁盘(非log区域), 用于回收相应log空间的过程.

    2. 状态

    T_RUNNING
    the transaction can accept new handles.