cleanup around loadAppendOnlyFile#9012
Conversation
oranagra
left a comment
There was a problem hiding this comment.
can you please verify that we have some tests to cover these error cases and try to run them with valgrind
Today when we load the AOF on startup, the loadAppendOnlyFile checks if the file is openning for reading. This check is redundent (dead code) as we open the AOF file at initServer, and the file will always be existing for the loadAppendOnlyFile. In this commit: - remove all the exit(1) from loadAppendOnlyFile, as it is the caller responsibility to decide what to do in case of failure. - move the opening of the AOF file for writing, to be after we loading it. - avoid return -ERR in DEBUG LOADAOF, when the AOF is existing but empty
5f04aa6 to
0f06cba
Compare
|
@yossigo i'd like you to approve this change too. |
yossigo
left a comment
There was a problem hiding this comment.
LGTM, but I want to point out this is not just cleanup but will have some functional impact in rare (unexpected?) conditions:
- Before this commit, if the file was replaced in the right moment we could end up creating AOF file A and reading from AOF file B. Later on, we'd keep writing to AOF file A (which could even have been unlinked at this point).
- Before this commit, a non-writable AOF would be caught before reading it. Now we'll hit the error and bail only after reading.
|
should we also change rdb? |
@soloestoy what do you mean? change rdb.c not to use |
|
@oranagra I didn't make it clear, what I mean is:
|
- change the top comment of loadAppendOnlyFile() to reflect the new return values. - handle differently, the case of AOF file does not exist, and AOF exist but doesn't open for reading
|
@soloestoy you are right. This PR is more about the order of opening the files, and the error cleanup is the bonus. |
Today when we load the AOF on startup, the loadAppendOnlyFile checks if the file is openning for reading. This check is redundent (dead code) as we open the AOF file for writing at initServer, and the file will always be existing for the loadAppendOnlyFile. In this commit: - remove all the exit(1) from loadAppendOnlyFile, as it is the caller responsibility to decide what to do in case of failure. - move the opening of the AOF file for writing, to be after we loading it. - avoid return -ERR in DEBUG LOADAOF, when the AOF is existing but empty
this was a regression from #9012 (not released yet)
| if (ret != AOF_OK && ret != AOF_EMPTY) | ||
| exit(1); |
There was a problem hiding this comment.
Why did we choose exit here. A DEBUG command can make the server exit, is a bit odd.
I encountered this issue:
start a server with AOF off
debug loadaof
the server exit
the reason is that, in loadAppendOnlyFiles, the ret is AOF_NOT_EXIST, so it do a exit(1)
i think we should also ignore AOF_NOT_EXIST in this case?
or actually we need to return an error, print the log, instead of exit
There was a problem hiding this comment.
this command is only meant to be used by the test suite, and only by tests that generated an AOF file first.
i don't think it should ignore the AOF_NOT_EXIST, but i'm willing to trade this exit with an error reply (considering that the caller is likely to catch this error and die)
Return an error when loadAppendOnlyFiles fails instead of exiting. DEBUF LOADAOF command is only meant to be used by the test suite, and only by tests that generated an AOF file first. So this change is ok (considering that the caller is likely to catch this error and die). This actually revert part of the code in redis#9012, and now DEBUG LOADAOF behaves the same as DEBUG RELOAD (returns an error when the load fails). Plus remove a `after 2000` in a test, which can save times.
Return an error when loadAppendOnlyFiles fails instead of exiting. DEBUF LOADAOF command is only meant to be used by the test suite, and only by tests that generated an AOF file first. So this change is ok (considering that the caller is likely to catch this error and die). This actually revert part of the code in #9012, and now DEBUG LOADAOF behaves the same as DEBUG RELOAD (returns an error when the load fails). Plus remove a `after 2000` in a test, which can save times (looks like copy paste error).
…1790) Return an error when loadAppendOnlyFiles fails instead of exiting. DEBUF LOADAOF command is only meant to be used by the test suite, and only by tests that generated an AOF file first. So this change is ok (considering that the caller is likely to catch this error and die). This actually revert part of the code in redis#9012, and now DEBUG LOADAOF behaves the same as DEBUG RELOAD (returns an error when the load fails). Plus remove a `after 2000` in a test, which can save times (looks like copy paste error).
Today when we load the AOF on startup, the loadAppendOnlyFile checks if
the file is openning for reading.
This check is redundent (dead code) as we open the AOF file for writing at initServer,
and the file will always be existing for the loadAppendOnlyFile.
In this commit:
responsibility to decide what to do in case of failure.