Let's say I'm halfway through rewriting AOF,A write command modifies the key/value pairs that haven't been rewritten yet,That means the key-value pair has been modified。At the end of the rewrite, the modified key-value will be overwritten into the AOF rewrite file, but This command will also be added to the AOF rewrite buffer,

At the end, the AOF rewrite buffer is written to the AOF rewrite file, right? There's a discrepancy in the data


So WHAT I mean by that is that the write command modifies the data at the beginning of the rewrite, and then the write command is appended to the rewrite buffer. The rewriting process overwrites the changed key. But when it finally ends, the overwrite file is appended to the command in the overwrite buffer! But this command is no longer valid

Comment From: enjoy-binbin

  1. aof rewrite
  2. block a while, fork a process (copy on write)
  3. the child process do the rewrite thing (based on the data at the moment of fork)
  4. the parent write the aof diff to aof rewrite buffer
  5. when 3 is finish, the child need to take care of the rewrite buffer
  6. after 5 is finish, rename the tmp aof file

At the end of the rewrite, the modified key-value will be overwritten into the AOF rewrite file, but This command will also be added to the AOF rewrite buffer

halfway through rewriting AOF, the new write, it will not be overwritten into the AOF rewrite file, it will add to the rewrite buffer, and be part of the step 5

Comment From: sixsixsix516

谢谢大佬 我懂了, 原来重写时的数据是基于fork时那一瞬间的数据, 那就没有问题了! thanks!

Comment From: oranagra

@sixsixsix516 it seems that what you're missing is that the rewrite is done from a fork child process, so it has a frozen copy of the parent process' memory from the time of the forking, and is not affected by changes done in the parent process during the rewrite.

Comment From: sixsixsix516

Thank you for your answer. I have got it.