Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid updating DBOptions if there's no value updated #8518

Closed
wants to merge 3 commits into from

Conversation

jay-zhuang
Copy link
Contributor

@jay-zhuang jay-zhuang commented Jul 13, 2021

Summary: Try to avoid expensive updating DBOptions if
SetDBOptions() does not change any option value.

Test Plan: added unittest

@jay-zhuang jay-zhuang marked this pull request as ready for review July 13, 2021 03:02
@facebook-github-bot
Copy link
Contributor

@jay-zhuang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@mrambacher mrambacher left a comment

Choose a reason for hiding this comment

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

Perhaps it belongs in another PR, but should a similar effort be done for DB::SetOptions? If so (and it is a separate PR), please at least update the title of this PR to indicate it applies to DBOptions and not CFOptions.

Comment on lines 872 to 878
// check if new_options is changed by comparing to base_options
if (is_changed) {
std::string mismatch;
*is_changed = !OptionTypeInfo::StructsAreEqual(
config_options, "MutableDBOptions", &db_mutable_options_type_info,
"MutableDBOptions", &base_options, new_options, &mismatch);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be better as a new API (AreMutableDBOptionsEqual ?). This way, the DB code could do whatever sanitization is necessary before the comparison takes place. Effectively the same code, just in a new routine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

make sense.

Comment on lines +134 to +141
// update again
ASSERT_OK(dbfull()->SetDBOptions({{"bytes_per_sync", "123"}}));
ASSERT_FALSE(is_changed());

Copy link
Contributor

Choose a reason for hiding this comment

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

What about some tests that set bytes_per_sync=0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. With the checking after sanitization, it can avoid updating the value for setting it to 0. But the default value is not sanitized, but SetDBOptions() does. Not sure why, seems it's an inconsistency between DB open and SetDBOptions().

Comment on lines 1124 to 1125
&new_options, &is_changed);
if (!is_changed) {
Copy link
Contributor

Choose a reason for hiding this comment

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

See the note below about making this a new routine. Would allow for the sanitization in the following lines to take place before the comparison.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.

Summary: Try avoid expensive updating options operation if
`SetDBOptions()` does not change any option value.
Skip updating is not guaranteed, for example, changing `bytes_per_sync`
to `0` may still trigger updating, as the value could be sanitized.

Test Plan: added unittest
@facebook-github-bot
Copy link
Contributor

@jay-zhuang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@jay-zhuang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@jay-zhuang jay-zhuang changed the title Avoid updating option if there's no value updated Avoid updating DBOptions if there's no value updated Jul 21, 2021
@facebook-github-bot
Copy link
Contributor

@jay-zhuang merged this pull request in 42eaa45.

jay-zhuang added a commit to jay-zhuang/rocksdb that referenced this pull request Jul 28, 2021
PR facebook#8518 merge the change to wrong section.
facebook-github-bot pushed a commit that referenced this pull request Jul 28, 2021
Summary:
PR #8518 merge the change to wrong section.

Pull Request resolved: #8594

Reviewed By: riversand963

Differential Revision: D29974565

Pulled By: jay-zhuang

fbshipit-source-id: 51c930d93fbdb406fe31ff73c96548a6f88b9965
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants