@@ -153,7 +153,7 @@ impl Config {
153153 ) ) ;
154154 }
155155 for ( key, shard) in self . stores . iter_mut ( ) {
156- shard. validate ( key) ?;
156+ shard. validate ( key, & self . node ) ?;
157157 }
158158 self . deployment . validate ( ) ?;
159159
@@ -281,10 +281,10 @@ pub struct Shard {
281281}
282282
283283impl Shard {
284- fn validate ( & mut self , name : & str ) -> Result < ( ) > {
284+ fn validate ( & mut self , name : & str , node : & NodeId ) -> Result < ( ) > {
285285 ShardName :: new ( name. to_string ( ) ) . map_err ( |e| anyhow ! ( e) ) ?;
286286
287- self . expand_connection ( ) ?;
287+ self . expand_connection ( node ) ?;
288288
289289 if matches ! ( self . pool_size, PoolSize :: None ) {
290290 return Err ( anyhow ! ( "missing pool size definition for shard `{}`" , name) ) ;
@@ -334,22 +334,25 @@ impl Shard {
334334 } )
335335 }
336336
337- fn expand_connection ( & mut self ) -> Result < ( ) > {
337+ // Put the PGAPPNAME into the URL since tokio-postgres ignores this
338+ // environment variable. If PGAPPNAME is not set, use `node`.
339+ fn expand_connection ( & mut self , node : & NodeId ) -> Result < ( ) > {
340+ let app_name = std:: env:: var ( "PGAPPNAME" ) . unwrap_or ( node. to_string ( ) ) ;
341+
338342 let mut url = Url :: parse ( shellexpand:: env ( & self . connection ) ?. as_ref ( ) ) ?;
339- // Put the PGAPPNAME into the URL since tokio-postgres ignores this
340- // environment variable
341- if let Ok ( app_name) = std:: env:: var ( "PGAPPNAME" ) {
342- let query = match url. query ( ) {
343- Some ( query) => {
344- format ! ( "{query}&application_name={app_name}" )
345- }
346- None => {
347- format ! ( "application_name={app_name}" )
348- }
349- } ;
350- url. set_query ( Some ( & query) ) ;
351- }
343+
344+ let query = match url. query ( ) {
345+ Some ( query) => {
346+ format ! ( "{query}&application_name={app_name}" )
347+ }
348+ None => {
349+ format ! ( "application_name={app_name}" )
350+ }
351+ } ;
352+ url. set_query ( Some ( & query) ) ;
353+
352354 self . connection = url. to_string ( ) ;
355+
353356 Ok ( ( ) )
354357 }
355358}
@@ -1947,7 +1950,9 @@ fdw_pool_size = [
19471950 )
19481951 . unwrap ( ) ;
19491952
1950- shard. validate ( "index_node_1" ) . unwrap ( ) ;
1953+ shard
1954+ . validate ( "shard_1" , & NodeId :: new ( "index_node_1" ) . unwrap ( ) )
1955+ . unwrap ( ) ;
19511956 shard
19521957 } ;
19531958 if let Some ( appname) = appname {
0 commit comments