@ -640,32 +640,6 @@ Status ConfigureFromMap(
return s ;
return s ;
}
}
Status GetMutableOptionsFromStrings (
const MutableCFOptions & base_options ,
const std : : unordered_map < std : : string , std : : string > & options_map ,
Logger * /*info_log*/ , MutableCFOptions * new_options ) {
assert ( new_options ) ;
* new_options = base_options ;
ConfigOptions config_options ;
const auto config = CFOptionsAsConfigurable ( base_options ) ;
return ConfigureFromMap < MutableCFOptions > ( config_options , options_map ,
MutableCFOptions : : kName ( ) ,
config . get ( ) , new_options ) ;
}
Status GetMutableDBOptionsFromStrings (
const MutableDBOptions & base_options ,
const std : : unordered_map < std : : string , std : : string > & options_map ,
MutableDBOptions * new_options ) {
assert ( new_options ) ;
* new_options = base_options ;
ConfigOptions config_options ;
auto config = DBOptionsAsConfigurable ( base_options ) ;
return ConfigureFromMap < MutableDBOptions > ( config_options , options_map ,
MutableDBOptions : : kName ( ) ,
config . get ( ) , new_options ) ;
}
Status StringToMap ( const std : : string & opts_str ,
Status StringToMap ( const std : : string & opts_str ,
std : : unordered_map < std : : string , std : : string > * opts_map ) {
std : : unordered_map < std : : string , std : : string > * opts_map ) {
@ -707,12 +681,6 @@ Status StringToMap(const std::string& opts_str,
return Status : : OK ( ) ;
return Status : : OK ( ) ;
}
}
Status GetStringFromMutableDBOptions ( const ConfigOptions & config_options ,
const MutableDBOptions & mutable_opts ,
std : : string * opt_string ) {
auto config = DBOptionsAsConfigurable ( mutable_opts ) ;
return config - > GetOptionString ( config_options , opt_string ) ;
}
Status GetStringFromDBOptions ( std : : string * opt_string ,
Status GetStringFromDBOptions ( std : : string * opt_string ,
const DBOptions & db_options ,
const DBOptions & db_options ,
@ -731,14 +699,6 @@ Status GetStringFromDBOptions(const ConfigOptions& config_options,
return config - > GetOptionString ( config_options , opt_string ) ;
return config - > GetOptionString ( config_options , opt_string ) ;
}
}
Status GetStringFromMutableCFOptions ( const ConfigOptions & config_options ,
const MutableCFOptions & mutable_opts ,
std : : string * opt_string ) {
assert ( opt_string ) ;
opt_string - > clear ( ) ;
const auto config = CFOptionsAsConfigurable ( mutable_opts ) ;
return config - > GetOptionString ( config_options , opt_string ) ;
}
Status GetStringFromColumnFamilyOptions ( std : : string * opt_string ,
Status GetStringFromColumnFamilyOptions ( std : : string * opt_string ,
const ColumnFamilyOptions & cf_options ,
const ColumnFamilyOptions & cf_options ,
@ -1052,6 +1012,42 @@ Status OptionTypeInfo::Parse(const ConfigOptions& config_options,
}
}
}
}
Status OptionTypeInfo : : ParseType (
const ConfigOptions & config_options , const std : : string & opts_str ,
const std : : unordered_map < std : : string , OptionTypeInfo > & type_map ,
void * opt_addr , std : : unordered_map < std : : string , std : : string > * unused ) {
std : : unordered_map < std : : string , std : : string > opts_map ;
Status status = StringToMap ( opts_str , & opts_map ) ;
if ( ! status . ok ( ) ) {
return status ;
} else {
return ParseType ( config_options , opts_map , type_map , opt_addr , unused ) ;
}
}
Status OptionTypeInfo : : ParseType (
const ConfigOptions & config_options ,
const std : : unordered_map < std : : string , std : : string > & opts_map ,
const std : : unordered_map < std : : string , OptionTypeInfo > & type_map ,
void * opt_addr , std : : unordered_map < std : : string , std : : string > * unused ) {
for ( const auto & opts_iter : opts_map ) {
std : : string opt_name ;
const auto * opt_info = Find ( opts_iter . first , type_map , & opt_name ) ;
if ( opt_info ! = nullptr ) {
Status status =
opt_info - > Parse ( config_options , opt_name , opts_iter . second , opt_addr ) ;
if ( ! status . ok ( ) ) {
return status ;
}
} else if ( unused ! = nullptr ) {
( * unused ) [ opts_iter . first ] = opts_iter . second ;
} else if ( ! config_options . ignore_unknown_options ) {
return Status : : NotFound ( " Unrecognized option " , opts_iter . first ) ;
}
}
return Status : : OK ( ) ;
}
Status OptionTypeInfo : : ParseStruct (
Status OptionTypeInfo : : ParseStruct (
const ConfigOptions & config_options , const std : : string & struct_name ,
const ConfigOptions & config_options , const std : : string & struct_name ,
const std : : unordered_map < std : : string , OptionTypeInfo > * struct_map ,
const std : : unordered_map < std : : string , OptionTypeInfo > * struct_map ,
@ -1060,20 +1056,12 @@ Status OptionTypeInfo::ParseStruct(
Status status ;
Status status ;
if ( opt_name = = struct_name | | EndsWith ( opt_name , " . " + struct_name ) ) {
if ( opt_name = = struct_name | | EndsWith ( opt_name , " . " + struct_name ) ) {
// This option represents the entire struct
// This option represents the entire struct
std : : unordered_map < std : : string , std : : string > opt_map ;
std : : unordered_map < std : : string , std : : string > unused ;
status = StringToMap ( opt_value , & opt_map ) ;
status =
for ( const auto & map_iter : opt_map ) {
ParseType ( config_options , opt_value , * struct_map , opt_addr , & unused ) ;
if ( ! status . ok ( ) ) {
if ( status . ok ( ) & & ! unused . empty ( ) ) {
break ;
status = Status : : InvalidArgument (
}
" Unrecognized option " , struct_name + " . " + unused . begin ( ) - > first ) ;
const auto iter = struct_map - > find ( map_iter . first ) ;
if ( iter ! = struct_map - > end ( ) ) {
status = iter - > second . Parse ( config_options , map_iter . first ,
map_iter . second , opt_addr ) ;
} else {
status = Status : : InvalidArgument ( " Unrecognized option " ,
struct_name + " . " + map_iter . first ) ;
}
}
}
} else if ( StartsWith ( opt_name , struct_name + " . " ) ) {
} else if ( StartsWith ( opt_name , struct_name + " . " ) ) {
// This option represents a nested field in the struct (e.g, struct.field)
// This option represents a nested field in the struct (e.g, struct.field)
@ -1140,6 +1128,27 @@ Status OptionTypeInfo::Serialize(const ConfigOptions& config_options,
}
}
}
}
Status OptionTypeInfo : : SerializeType (
const ConfigOptions & config_options ,
const std : : unordered_map < std : : string , OptionTypeInfo > & type_map ,
const void * opt_addr , std : : string * result ) {
Status status ;
for ( const auto & iter : type_map ) {
std : : string single ;
const auto & opt_info = iter . second ;
if ( opt_info . ShouldSerialize ( ) ) {
status =
opt_info . Serialize ( config_options , iter . first , opt_addr , & single ) ;
if ( ! status . ok ( ) ) {
return status ;
} else {
result - > append ( iter . first + " = " + single + config_options . delimiter ) ;
}
}
}
return status ;
}
Status OptionTypeInfo : : SerializeStruct (
Status OptionTypeInfo : : SerializeStruct (
const ConfigOptions & config_options , const std : : string & struct_name ,
const ConfigOptions & config_options , const std : : string & struct_name ,
const std : : unordered_map < std : : string , OptionTypeInfo > * struct_map ,
const std : : unordered_map < std : : string , OptionTypeInfo > * struct_map ,
@ -1154,19 +1163,12 @@ Status OptionTypeInfo::SerializeStruct(
// This option represents the entire struct
// This option represents the entire struct
std : : string result ;
std : : string result ;
for ( const auto & iter : * struct_map ) {
status = SerializeType ( embedded , * struct_map , opt_addr , & result ) ;
std : : string single ;
if ( ! status . ok ( ) ) {
const auto & opt_info = iter . second ;
return status ;
if ( opt_info . ShouldSerialize ( ) ) {
} else {
status = opt_info . Serialize ( embedded , iter . first , opt_addr , & single ) ;
* value = " { " + result + " } " ;
if ( ! status . ok ( ) ) {
return status ;
} else {
result . append ( iter . first + " = " + single + embedded . delimiter ) ;
}
}
}
}
* value = " { " + result + " } " ;
} else if ( StartsWith ( opt_name , struct_name + " . " ) ) {
} else if ( StartsWith ( opt_name , struct_name + " . " ) ) {
// This option represents a nested field in the struct (e.g, struct.field)
// This option represents a nested field in the struct (e.g, struct.field)
std : : string elem_name ;
std : : string elem_name ;
@ -1304,6 +1306,20 @@ bool OptionTypeInfo::AreEqual(const ConfigOptions& config_options,
return false ;
return false ;
}
}
bool OptionTypeInfo : : TypesAreEqual (
const ConfigOptions & config_options ,
const std : : unordered_map < std : : string , OptionTypeInfo > & type_map ,
const void * this_addr , const void * that_addr , std : : string * mismatch ) {
for ( const auto & iter : type_map ) {
const auto & opt_info = iter . second ;
if ( ! opt_info . AreEqual ( config_options , iter . first , this_addr , that_addr ,
mismatch ) ) {
return false ;
}
}
return true ;
}
bool OptionTypeInfo : : StructsAreEqual (
bool OptionTypeInfo : : StructsAreEqual (
const ConfigOptions & config_options , const std : : string & struct_name ,
const ConfigOptions & config_options , const std : : string & struct_name ,
const std : : unordered_map < std : : string , OptionTypeInfo > * struct_map ,
const std : : unordered_map < std : : string , OptionTypeInfo > * struct_map ,
@ -1314,15 +1330,11 @@ bool OptionTypeInfo::StructsAreEqual(
std : : string result ;
std : : string result ;
if ( EndsWith ( opt_name , struct_name ) ) {
if ( EndsWith ( opt_name , struct_name ) ) {
// This option represents the entire struct
// This option represents the entire struct
for ( const auto & iter : * struct_map ) {
matches = TypesAreEqual ( config_options , * struct_map , this_addr , that_addr ,
const auto & opt_info = iter . second ;
& result ) ;
if ( ! matches ) {
matches = opt_info . AreEqual ( config_options , iter . first , this_addr ,
* mismatch = struct_name + " . " + result ;
that_addr , & result ) ;
return false ;
if ( ! matches ) {
* mismatch = struct_name + " . " + result ;
return false ;
}
}
}
} else if ( StartsWith ( opt_name , struct_name + " . " ) ) {
} else if ( StartsWith ( opt_name , struct_name + " . " ) ) {
// This option represents a nested field in the struct (e.g, struct.field)
// This option represents a nested field in the struct (e.g, struct.field)