Skip to content

cleanup around loadAppendOnlyFile#9012

Merged
oranagra merged 2 commits intoredis:unstablefrom
YaacovHazan:clean_load_append_only
Jun 14, 2021
Merged

cleanup around loadAppendOnlyFile#9012
oranagra merged 2 commits intoredis:unstablefrom
YaacovHazan:clean_load_append_only

Conversation

@YaacovHazan
Copy link
Collaborator

@YaacovHazan YaacovHazan commented May 31, 2021

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

@YaacovHazan YaacovHazan requested a review from oranagra May 31, 2021 12:14
Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@YaacovHazan YaacovHazan force-pushed the clean_load_append_only branch from 5f04aa6 to 0f06cba Compare June 1, 2021 10:42
oranagra
oranagra previously approved these changes Jun 1, 2021
@oranagra oranagra added the state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten label Jun 1, 2021
@oranagra
Copy link
Member

oranagra commented Jun 1, 2021

@yossigo i'd like you to approve this change too.

Copy link
Collaborator

@yossigo yossigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@soloestoy
Copy link
Contributor

should we also change rdb?

@oranagra
Copy link
Member

oranagra commented Jun 8, 2021

should we also change rdb?

@soloestoy what do you mean? change rdb.c not to use exit(1) yes, at some point (we wanna create librdb), but not now.
regarding the order of write and read, there's no issue there, maybe i'm missing your point.

@soloestoy
Copy link
Contributor

@oranagra I didn't make it clear, what I mean is:

  1. if we use aof-use-rdb-preamble, function loadAppendOnlyFile() will call rdbLoadRio() and may use exit(1).
  2. this PR seems aim to let the caller(now is only loadDataFromDisk()) to decide if it should exit(1) or not, so I think load AOF and RDB should have same behavior.
  3. as you said, we wanna create librdb.

- 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
@YaacovHazan
Copy link
Collaborator Author

@soloestoy you are right. This PR is more about the order of opening the files, and the error cleanup is the bonus.
Another deeper PR is needed to sort it out in rdb.c

@oranagra oranagra merged commit 1677efb into redis:unstable Jun 14, 2021
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Sep 8, 2021
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
oranagra pushed a commit that referenced this pull request Sep 26, 2021
this was a regression from #9012 (not released yet)
Comment on lines +554 to +555
if (ret != AOF_OK && ret != AOF_EMPTY)
exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Feb 8, 2023
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.
oranagra pushed a commit that referenced this pull request Feb 9, 2023
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).
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants