• Tian's avatar
    Fsync directory while persisting AOF manifest, RDB file, and config file (#10737) · 99a425d0
    Tian authored
    The current process to persist files is `write` the data, `fsync` and `rename` the file,
    but a underlying problem is that the rename may be lost when a sudden crash like
    power outage and the directory hasn't been persisted.
    
    The article [Ensuring data reaches disk](https://lwn.net/Articles/457667/) mentions
    a safe way to update file should be:
    
    1. create a new temp file (on the same file system!)
    2. write data to the temp file
    3. fsync() the temp file
    4. rename the temp file to the appropriate name
    5. fsync() the containing directory
    
    This commit handles CONFIG REWRITE, AOF manifest, and RDB file (both for persistence,
    and the one the replica gets from the master).
    It doesn't handle (yet), ACL SAVE and Cluster configs, since these don't yet follow this pattern.
    99a425d0
rdb.c 135 KB