Skip to content

fix return value of loadAppendOnlyFiles#10295

Merged
oranagra merged 9 commits intoredis:unstablefrom
YaacovHazan:fix-loadAppendOnlyFiles-return-value
Feb 22, 2022
Merged

fix return value of loadAppendOnlyFiles#10295
oranagra merged 9 commits intoredis:unstablefrom
YaacovHazan:fix-loadAppendOnlyFiles-return-value

Conversation

@YaacovHazan
Copy link
Collaborator

@YaacovHazan YaacovHazan commented Feb 13, 2022

Make sure the status return from loading multiple AOF files reflects the overall
result, not just the one of the last file.

When one of the AOF files succeeded to load, but the last AOF file
was empty, the loadAppendOnlyFiles will return AOF_EMPTY.
This commit changes this behavior, and return AOF_OK in that case.

This can happen for example, when loading old AOF file, and no more commands processed,
the manifest file will include base AOF file with data, and empty incr AOF file.

When one of the AOF files succeeded to load, but the last AOF file
was empty, the loadAppendOnlyFiles will return AOF_EMPTY.
This commit changes this behavior, and return AOF_OK in that case.

This can happen for example, when loading old AOF file, and no more commands processed,
the manifest file will include base AOF file with data, and empty incr AOF file.
Copy link
Contributor

@chenyang8094 chenyang8094 left a comment

Choose a reason for hiding this comment

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

Thanks, I found out that the return value of AOF was introduced in #9012 (which you submitted). In this PR, AOF_EMPTY is considered a correct return value (such as in debug loadaof).

But in multi part aof, both base and incr AOF may be empty. The current implementation is to directly ignore the empty return value during the AOF loading process, and finally return it to the upper-level caller for processing.

But I found that at the end of the loadAppendOnlyFiles function, there is a problem when we use stopLoading(ret == AOF_OK) At this time, if ret is AOF_EMPTY, we will send a wrong load event to the module, which is not as expected. So I think this modification of yours makes sense. Or change to stopLoading(ret == AOF_OK || ret == AOF_EMPTY) to use less code to get the same effect.

In addition, according to your modification, the upper-level caller will no longer perceive AOF_EMPTY, so can we remove judgment on AOF_EMPTY in debug.c?

@oranagra
Copy link
Member

I think it's a good idea to keep supporting the EMPTY return value, some callers may want to treat that as a failure (e.g debug.c, or if we some day have an explicit AOFLOAD command).
but we should return empty only if the entire AOF loading was empty (i.e. we didn't load anything).
if the base wasn't empty, and just the INCR was empty, we wanna return OK.

as for stopLoading. ideally, we could have left that for the caller to decide what's a failure, or maybe pass in some flag telling loadAppendOnlyFiles which values are a failure, but that's too complicated.
i suppose we can be liberal here and only treat fatal errors as stopLoading failures (i.e. AOF_FAILED and maybe AOF_OPEN_ERR).
IIRC the main user of this indication is modules listening to the event so that they can maybe revert / release something that was allocated during loading, but that's mainly important in replica rdb loading since the replica can keep running, and doesn't seem important in AOF loading (in which redis will exit on failure).

src/aof.c Outdated
if (aof_loaded && ret == AOF_EMPTY) ret = AOF_OK;

cleanup:
stopLoading(ret == AOF_OK);
Copy link
Member

Choose a reason for hiding this comment

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

i think we need to treat TRUNCATED and maybe EMPTY as success..

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree.

  1. if no base and no incr AOF,we just return AOF_NOT_EXIST
  2. or if total_size == 0 , we just return AOF_EMPTY
  3. if any of the middle AOF is empty ,we convert the ret to AOF_OK
  4. if the AOF was truncated (only the last file) , we also treat it as AOF_OK

@oranagra right ?

Copy link
Member

Choose a reason for hiding this comment

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

yes, that's the logic i aim for.
please check the code to make sure we didn't miss anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

@YaacovHazan Maybe you need to update your PR to satisfy the above logic. thanks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@chenyang8094 already added a new commit... pls review

@YaacovHazan
Copy link
Collaborator Author

@chenyang8094 thanks for the review.
We still can get AOF_EMPTY in debug.c (probably not common use case), if aof-use-rdb-preamble is disabled and no data was saved to AOF, So I think we should leave it as is.

YaacovHazan added 2 commits February 14, 2022 09:29
treat TRUNCATED and EMPTY as success
no need for extra aof_loaded vairable
@YaacovHazan
Copy link
Collaborator Author

@chenyang8094 I pushed a new commit, please review.
note that we cannot do the check of the total_size before we actually try to load the AOF files, because missing files counted as a zero size.

@chenyang8094
Copy link
Contributor

@chenyang8094 I pushed a new commit, please review. note that we cannot do the check of the total_size before we actually try to load the AOF files, because missing files counted as a zero size.

You are right. Maybe I should have made getBaseAndIncrAppendOnlyFilesSize return -1 when there is an error (such as some AOF files do not exist), so that I can return AOF_FAILED directly in loadAppendOnlyFiles. Because if I can judge in advance that all AOFs is empty, I can avoid executing a meaningless startloading and stoploading.

make getBaseAndIncrAppendOnlyFilesSize return extra information
if we succeeded or not to get the AOF files size
@YaacovHazan
Copy link
Collaborator Author

@chenyang8094 makes sense... I changed the getBaseAndIncrAppendOnlyFilesSize & getAppendOnlyFileSize to return status.

YaacovHazan added 2 commits February 15, 2022 10:11
@chenyang8094
Copy link
Contributor

@chenyang8094 makes sense... I changed the getBaseAndIncrAppendOnlyFilesSize & getAppendOnlyFileSize to return status.

@YaacovHazan Please solve the test error, thanks.

Copy link
Contributor

@chenyang8094 chenyang8094 left a comment

Choose a reason for hiding this comment

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

LGTM

@oranagra oranagra merged commit 65e4bce into redis:unstable Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants