预写式日志 WAL(Write-ahead logging)

In computer science, write-ahead logging (WAL) is a family of techniques for providing atomicity and durability (two of the ACID properties) in database systems.
In a system using WAL, all modifications are written to a log before they are applied. Usually both redo and undo information is stored in the log.
The purpose of this can be illustrated by an example. Imagine a program that is in the middle of performing some operation when the machine it is running on loses power. Upon restart, that program might well need to know whether the operation it was performing succeeded, half-succeeded, or failed. If a write-ahead log is used, the program can check this log and compare what it was supposed to be doing when it unexpectedly lost power to what was actually done. On the basis of this comparison, the program could decide to undo what it had started, complete what it had started, or keep things as they are.
WAL allows updates of a database to be done in-place. Another way to implement atomic updates is with shadow paging, which is not in-place. The main advantage of doing updates in-place is that it reduces the need to modify indexes and block lists.
ARIES is a popular algorithm in the WAL family.
File systems typically use a variant of WAL for at least file system metadata called journaling.

好多数据库都用到了此模式 mysql habase zookeeper 非数据库也用到了此模式

WAL和Snapshot和大多数分布式系统一样,ZooKeeper也有WAL(Write-Ahead-Log),对于每一个更新操作,ZooKeeper都会先写WAL, 然后再对内存中的数据做更新,然后向Client通知更新结果。另外,ZooKeeper还会定期将内存中的目录树进行Snapshot,落地到磁盘上,这个跟HDFS中的FSImage是比较类似的。这么做的主要目的,一当然是数据的持久化,二是加快重启之后的恢复速度,如果全部通过Replay WAL的形式恢复的话,会比较慢。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,150评论 0 23
  • 和姜小姐在同一个公司,却没怎么打过交道,可能因为不在一个办公室的原因吧。但是和她一起吃过两次饭,不是单独,是和其他...
    吐金鱼的小泡泡阅读 315评论 0 0
  • 兜兜转转兜兜,我又回到了热电。大学学热能,当时迷茫的很,没有好好学功课,研究生转专业到光电,觉得自己大概不用再搞热...
    于渌阅读 404评论 0 0
  • 今天我早早起床,看到孩子还在甜水,没有去打扰她,因为我知道,一个礼拜下来,也就周末才能睡个自然醒,孩子的生物钟可是...
    琪子妈阅读 204评论 0 5