@@ -142,7 +142,7 @@ impl Config {
142142 ) ) ;
143143 }
144144 for ( key, shard) in self . stores . iter_mut ( ) {
145- shard. validate ( key) ?;
145+ shard. validate ( key, & self . node ) ?;
146146 }
147147 self . deployment . validate ( ) ?;
148148
@@ -267,10 +267,10 @@ pub struct Shard {
267267}
268268
269269impl Shard {
270- fn validate ( & mut self , name : & str ) -> Result < ( ) > {
270+ fn validate ( & mut self , name : & str , node : & NodeId ) -> Result < ( ) > {
271271 ShardName :: new ( name. to_string ( ) ) . map_err ( |e| anyhow ! ( e) ) ?;
272272
273- self . expand_connection ( ) ?;
273+ self . expand_connection ( node ) ?;
274274
275275 if matches ! ( self . pool_size, PoolSize :: None ) {
276276 return Err ( anyhow ! ( "missing pool size definition for shard `{}`" , name) ) ;
@@ -320,22 +320,25 @@ impl Shard {
320320 } )
321321 }
322322
323- fn expand_connection ( & mut self ) -> Result < ( ) > {
323+ // Put the PGAPPNAME into the URL since tokio-postgres ignores this
324+ // environment variable. If PGAPPNAME is not set, use `node`.
325+ fn expand_connection ( & mut self , node : & NodeId ) -> Result < ( ) > {
326+ let app_name = std:: env:: var ( "PGAPPNAME" ) . unwrap_or ( node. to_string ( ) ) ;
327+
324328 let mut url = Url :: parse ( shellexpand:: env ( & self . connection ) ?. as_ref ( ) ) ?;
325- // Put the PGAPPNAME into the URL since tokio-postgres ignores this
326- // environment variable
327- if let Ok ( app_name) = std:: env:: var ( "PGAPPNAME" ) {
328- let query = match url. query ( ) {
329- Some ( query) => {
330- format ! ( "{query}&application_name={app_name}" )
331- }
332- None => {
333- format ! ( "application_name={app_name}" )
334- }
335- } ;
336- url. set_query ( Some ( & query) ) ;
337- }
329+
330+ let query = match url. query ( ) {
331+ Some ( query) => {
332+ format ! ( "{query}&application_name={app_name}" )
333+ }
334+ None => {
335+ format ! ( "application_name={app_name}" )
336+ }
337+ } ;
338+ url. set_query ( Some ( & query) ) ;
339+
338340 self . connection = url. to_string ( ) ;
341+
339342 Ok ( ( ) )
340343 }
341344}
@@ -1939,7 +1942,9 @@ fdw_pool_size = [
19391942 )
19401943 . unwrap ( ) ;
19411944
1942- shard. validate ( "index_node_1" ) . unwrap ( ) ;
1945+ shard
1946+ . validate ( "shard_1" , & NodeId :: new ( "index_node_1" ) . unwrap ( ) )
1947+ . unwrap ( ) ;
19431948 shard
19441949 } ;
19451950 if let Some ( appname) = appname {
0 commit comments