Repository navigation
Cancel SHUTDOWN if initial AOF is being written - #1829
Conversation
|
👍 Matt, thanks. If the program works the same with |
|
I did look for an initial value, but it looks to be undefined until set in The only other place If I missed something, let me know. :) |
|
Oh, I see now. Obviously |
|
@mattsta exactly, your code looks perfect just the idea is to use the same init value as before. Thinking a bit about additional failure modes we could fix and replying... |
|
So.. the only code path I can imagine where the value is set to zero but it was not set via CONFIG SET is when we start the server without an AOF file. One could argue that it should be possible to shutdown the server under this special condition if a rewrite is in progress (manually triggered.... for the file to be zero length and a rewrite to be in progress). But, if the server is empty, is not a big deal to wait for the children to exit before the shutdown, since the rewrite in the worst condition can write the data written in the current event loop before flushAppendOnlyFile() is called (otherwise the TL;DR: if we use a value of zero, start a server, trigger a manual rewrite with BGREWRITEAOF, and send SHUTDOWN, all at the same time, the server will not shutdown if the rewrite is still in progress. |
|
That sounds like a good thing. If the user requests data saving, the server shouldn't stop it unless requested. Though, there's not a current way to cancel an AOF rewrite (e.g. DEBUG CANCEL BGREWRITEAOF), and the NOSAVE flag isn't respected in the AOF shutdown flow (because previously, the rewrite was just killed). |
|
AOF rewrite does not need to be preserved actually because the server is writing to the old AOF at the same time, so it is technically strange you can't cancel the first BGREWRITE that starts after a server is started up with an empty file. That was the point of my probably bad exposed comment above :-) About the fact AOF rewrites can't be aborted, that's true but never found an use for it... maybe there is, like, you start a rewrite but the disk is too busy and is putting too much pressure? About NOSAVE, this is specifically intended for the rdb storage because AOFs will always flush pending buffers to the currently active AOF. However the old one is killed because there is no point in waiting for the rerwite since all the data is already in the old AOF anyway. |
Correct! That's also where an initial value of -1 helps because it makes it clear "file has never existed" (meaning: we must wait for it to complete before exiting) versus "file exists but is empty" (meaning: the user has no data, so we can still exit). |
|
Exactly, -1 is semantically more correct. My only concern is if this negative value is used (causing issues) in the AOF code while a rewrite is already in progress. |
|
p.s. grepping to check this. |
|
The var is used while possibly at -1:
Should be never touched in the context of Ok, then we have the key :-) Instead of initializing the value to -1, we should just check for the value of server.aof_state. If it is REDIS_AOF_WAIT_REWRITE, we know the AOF was just turned on. Makes sense? |
Fixes redis#1826 (and many other reports of the same problem)
|
Even better! Didn't notice that flag the first time around. |
Cancel SHUTDOWN if initial AOF is being written
|
Merged, thanks! |
If we're writing the initial AOF, we shouldn't exit because Redis will load the empty (or partial) AOF on restart.