@@ -43,8 +43,8 @@ fn default_data_dir_path() -> PathBuf {
4343// For a given index `index-id`, it means that we have the metastore file
4444// in `./qwdata/indexes/{index-id}/metastore.json` and splits in
4545// dir `./qwdata/indexes/{index-id}/splits`.
46- fn default_metastore_and_index_root_uri ( ) -> String {
47- Uri :: try_new ( & default_data_dir_path ( ) . join ( "indexes" ) . to_string_lossy ( ) )
46+ fn default_metastore_and_index_root_uri ( data_dir_path : & Path ) -> String {
47+ Uri :: try_new ( & data_dir_path . join ( "indexes" ) . to_string_lossy ( ) )
4848 . expect ( "Default data dir `./qwdata` value is invalid." )
4949 . as_ref ( )
5050 . to_string ( )
@@ -150,7 +150,7 @@ pub struct StorageConfig {
150150 pub s3_config : S3Config ,
151151}
152152
153- #[ derive( Debug , Clone , Serialize , Deserialize , PartialEq ) ]
153+ #[ derive( Clone , Serialize , Deserialize , PartialEq ) ]
154154#[ serde( deny_unknown_fields) ]
155155pub struct QuickwitConfig {
156156 pub version : usize ,
@@ -162,10 +162,8 @@ pub struct QuickwitConfig {
162162 pub rest_listen_port : u16 ,
163163 #[ serde( default ) ]
164164 pub peer_seeds : Vec < String > ,
165- #[ serde( default = "default_metastore_and_index_root_uri" ) ]
166- pub metastore_uri : String ,
167- #[ serde( default = "default_metastore_and_index_root_uri" ) ]
168- pub default_index_root_uri : String ,
165+ metastore_uri : Option < String > ,
166+ default_index_root_uri : Option < String > ,
169167 #[ serde( default = "default_data_dir_path" ) ]
170168 #[ serde( rename = "data_dir" ) ]
171169 pub data_dir_path : PathBuf ,
@@ -292,6 +290,21 @@ impl QuickwitConfig {
292290 }
293291}
294292
293+ impl QuickwitConfig {
294+ pub fn metastore_uri ( & self ) -> String {
295+ self . metastore_uri
296+ . as_ref ( )
297+ . unwrap_or ( & default_metastore_and_index_root_uri ( & self . data_dir_path ) )
298+ . to_string ( )
299+ }
300+ pub fn default_index_root_uri ( & self ) -> String {
301+ self . default_index_root_uri
302+ . as_ref ( )
303+ . unwrap_or ( & default_metastore_and_index_root_uri ( & self . data_dir_path ) )
304+ . to_string ( )
305+ }
306+ }
307+
295308impl Default for QuickwitConfig {
296309 fn default ( ) -> Self {
297310 Self {
@@ -300,8 +313,8 @@ impl Default for QuickwitConfig {
300313 rest_listen_port : default_rest_listen_port ( ) ,
301314 peer_seeds : Vec :: new ( ) ,
302315 node_id : default_node_id ( ) ,
303- metastore_uri : default_metastore_and_index_root_uri ( ) ,
304- default_index_root_uri : default_metastore_and_index_root_uri ( ) ,
316+ metastore_uri : None ,
317+ default_index_root_uri : None ,
305318 data_dir_path : PathBuf :: from ( DEFAULT_DATA_DIR_PATH ) ,
306319 indexer_config : IndexerConfig :: default ( ) ,
307320 searcher_config : SearcherConfig :: default ( ) ,
@@ -310,6 +323,25 @@ impl Default for QuickwitConfig {
310323 }
311324}
312325
326+ impl std:: fmt:: Debug for QuickwitConfig {
327+ fn fmt ( & self , formatter : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
328+ formatter
329+ . debug_struct ( "QuickwitConfig" )
330+ . field ( "version" , & self . version )
331+ . field ( "node_id" , & self . node_id )
332+ . field ( "listen_address" , & self . listen_address )
333+ . field ( "rest_listen_port" , & self . rest_listen_port )
334+ . field ( "peer_seeds" , & self . peer_seeds )
335+ . field ( "data_dir_path" , & self . data_dir_path )
336+ . field ( "metastore_uri" , & self . metastore_uri ( ) )
337+ . field ( "default_index_root_uri" , & self . default_index_root_uri ( ) )
338+ . field ( "indexer_config" , & self . indexer_config )
339+ . field ( "searcher_config" , & self . searcher_config )
340+ . field ( "storage_config" , & self . storage_config )
341+ . finish ( )
342+ }
343+ }
344+
313345#[ cfg( test) ]
314346mod tests {
315347 use std:: env;
@@ -349,7 +381,7 @@ mod tests {
349381 ]
350382 ) ;
351383 assert_eq!(
352- config. metastore_uri,
384+ config. metastore_uri( ) ,
353385 "postgres://username:password@host:port/db"
354386 ) ;
355387
@@ -410,7 +442,7 @@ mod tests {
410442 assert_eq ! ( config. version, 0 ) ;
411443 assert_eq ! ( config. node_id, "1" ) ;
412444 assert_eq ! (
413- config. metastore_uri,
445+ config. metastore_uri( ) ,
414446 "postgres://username:password@host:port/db"
415447 ) ;
416448 assert ! ( config. storage_config. is_none( ) ) ;
@@ -424,7 +456,7 @@ mod tests {
424456 let config = serde_yaml:: from_str :: < QuickwitConfig > ( config_yaml) . unwrap ( ) ;
425457 assert_eq ! ( config. version, 0 ) ;
426458 assert_eq ! (
427- config. metastore_uri,
459+ config. metastore_uri( ) ,
428460 "postgres://username:password@host:port/db"
429461 ) ;
430462 assert_eq ! (
@@ -446,7 +478,7 @@ mod tests {
446478 assert_eq ! ( config. version, 0 ) ;
447479 assert ! ( config. node_id. starts_with( "node-" ) ) ;
448480 assert_eq ! (
449- config. metastore_uri,
481+ config. metastore_uri( ) ,
450482 format!(
451483 "file://{}/qwdata/indexes" ,
452484 env:: current_dir( ) . unwrap( ) . display( )
0 commit comments