• zhaozhao.zz's avatar
    AOF: recover from last write error after turn on appendonly again (#8030) · 49b36633
    zhaozhao.zz authored
    The key point is how to recover from last AOF write error, for example:
    
    1. start redis with appendonly yes, and append some write commands
    
    2. short write or something else error happen, `server.aof_last_write_status` changed to `C_ERR`, now redis doesn't accept write commands
    
    3. execute `CONFIG SET appendonly no` to avoid the above problem, now redis can accept write commands again
    
    4. disk error resolved, and execute `CONFIG SET appendonly yes` to reopen AOF, but `server.aof_last_write_status` cannot be changed to `C_OK` (if background aof rewrite run less then 1 second, it will free `server.aof_buf` and then serverCron cannot fix `aof_last_write_status`), then redis cannot accept write commands forever.
    
    This PR use a simple way to fix it:
    
    1. just free `server.aof_buf` when stop appendonly to save memory, if error happens in `flushAppendOnlyFile(1)`, the `server.aof_buf` may contains some data which has not be written to aof, I think we can ignore it because we turn off the appendonly.
    
    2. reset fsync status after stop appendonly and call `flushAppendOnlyFile` only when `aof_state` is ON
    
    3. reset `server.last_write_status` when reopen aof to accept write commands
    49b36633
aof.c 76.5 KB