@@ -49,7 +49,7 @@ impl ComputeNode {
49
49
task. borrow ( ) . clone ( )
50
50
}
51
51
52
- async fn promote_impl ( & self , mut cfg : PromoteConfig ) -> Result < ( ) > {
52
+ async fn promote_impl ( & self , cfg : PromoteConfig ) -> Result < ( ) > {
53
53
{
54
54
let state = self . state . lock ( ) . unwrap ( ) ;
55
55
let mode = & state. pspec . as_ref ( ) . unwrap ( ) . spec . mode ;
@@ -134,25 +134,41 @@ impl ComputeNode {
134
134
{
135
135
let mut state = self . state . lock ( ) . unwrap ( ) ;
136
136
let spec = & mut state. pspec . as_mut ( ) . unwrap ( ) . spec ;
137
- spec. mode = ComputeMode :: Primary ;
138
- let new_conf = cfg. spec . cluster . postgresql_conf . as_mut ( ) . unwrap ( ) ;
139
- let existing_conf = spec. cluster . postgresql_conf . as_ref ( ) . unwrap ( ) ;
140
- Self :: merge_spec ( new_conf, existing_conf) ;
137
+ tracing:: debug!( "old spec: {:#?}, new spec: {:#?}" , spec, cfg. spec) ;
138
+
139
+ // Local setup has different ports for pg process (port=) for primary and secondary.
140
+ // In order for promotion to work, new spec needs to have port= with value for secondary
141
+ if cfg ! ( feature = "testing" ) {
142
+ let Some ( existing_conf) = spec. cluster . postgresql_conf . as_ref ( ) else {
143
+ bail ! ( "spec.cluster.postgresql_conf missing for endpoint" ) ;
144
+ } ;
145
+ let existing_conf = existing_conf. clone ( ) ;
146
+
147
+ * spec = cfg. spec ;
148
+
149
+ let Some ( new_conf) = spec. cluster . postgresql_conf . as_mut ( ) else {
150
+ bail ! ( "local setup was requested, but spec.cluster.postgresql_conf was not passed" ) ;
151
+ } ;
152
+ Self :: update_conf_from_existing ( new_conf, existing_conf) ;
153
+ } else {
154
+ * spec = cfg. spec ;
155
+ }
156
+
157
+ tracing:: debug!( "applied spec: {:#?}" , spec) ;
141
158
}
159
+
142
160
info ! ( "applied new spec, reconfiguring as primary" ) ;
143
161
self . reconfigure ( )
144
162
}
145
163
146
164
/// Merge old and new Postgres conf specs to apply on secondary.
147
- /// Change new spec's port and safekeepers since they are supplied
148
- /// differenly
149
- fn merge_spec ( new_conf : & mut String , existing_conf : & str ) {
165
+ /// Change new spec's port to old spec's ports, as they're different in local setup and
166
+ /// if we don't change it, promoted primary connection won't be established
167
+ fn update_conf_from_existing ( new_conf : & mut String , existing_conf : String ) {
150
168
let mut new_conf_set: HashMap < & str , & str > = new_conf
151
169
. split_terminator ( '\n' )
152
170
. map ( |e| e. split_once ( "=" ) . expect ( "invalid item" ) )
153
171
. collect ( ) ;
154
- new_conf_set. remove ( "neon.safekeepers" ) ;
155
-
156
172
let existing_conf_set: HashMap < & str , & str > = existing_conf
157
173
. split_terminator ( '\n' )
158
174
. map ( |e| e. split_once ( "=" ) . expect ( "invalid item" ) )
0 commit comments