diff --git a/options/options_helper.cc b/options/options_helper.cc index d417a201fc..a945a9e195 100644 --- a/options/options_helper.cc +++ b/options/options_helper.cc @@ -995,7 +995,8 @@ Status OptionTypeInfo::ParseStruct( std::unordered_map unused; status = ParseType(config_options, opt_value, *struct_map, opt_addr, &unused); - if (status.ok() && !unused.empty()) { + if (status.ok() && !unused.empty() && + !config_options.ignore_unknown_options) { status = Status::InvalidArgument( "Unrecognized option", struct_name + "." + unused.begin()->first); } @@ -1006,7 +1007,7 @@ Status OptionTypeInfo::ParseStruct( Find(opt_name.substr(struct_name.size() + 1), *struct_map, &elem_name); if (opt_info != nullptr) { status = opt_info->Parse(config_options, elem_name, opt_value, opt_addr); - } else { + } else if (!config_options.ignore_unknown_options) { status = Status::InvalidArgument("Unrecognized option", opt_name); } } else { @@ -1015,7 +1016,7 @@ Status OptionTypeInfo::ParseStruct( const auto opt_info = Find(opt_name, *struct_map, &elem_name); if (opt_info != nullptr) { status = opt_info->Parse(config_options, elem_name, opt_value, opt_addr); - } else { + } else if (!config_options.ignore_unknown_options) { status = Status::InvalidArgument("Unrecognized option", struct_name + "." + opt_name); } diff --git a/options/options_test.cc b/options/options_test.cc index bcb04d741c..03a2a10d4e 100644 --- a/options/options_test.cc +++ b/options/options_test.cc @@ -832,6 +832,21 @@ TEST_F(OptionsTest, CompressionOptionsFromString) { ASSERT_OK(GetColumnFamilyOptionsFromString(ignore, ColumnFamilyOptions(), "compression_opts.unknown=bad", &base_cf_opt)); + + // Test with some additional values added + config_options.ignore_unknown_options = false; + ASSERT_NOK( + GetColumnFamilyOptionsFromString(config_options, ColumnFamilyOptions(), + "new_unknown_field=whatever; " + "bottommost_compression_opts=4:5:6:7", + &base_cf_opt)); + // Test Ignoring Unknown Options + config_options.ignore_unknown_options = true; + ASSERT_OK( + GetColumnFamilyOptionsFromString(config_options, ColumnFamilyOptions(), + "new_unknown_field=whatever; " + "bottommost_compression_opts=4:5:6:7", + &base_cf_opt)); } TEST_F(OptionsTest, OldInterfaceTest) { diff --git a/unreleased_history/bug_fixes/parse_struct_ignore_unknown_options.md b/unreleased_history/bug_fixes/parse_struct_ignore_unknown_options.md new file mode 100644 index 0000000000..cfcb7a449d --- /dev/null +++ b/unreleased_history/bug_fixes/parse_struct_ignore_unknown_options.md @@ -0,0 +1 @@ +Honor ConfigOptions.ignore_unknown_options in ParseStruct()