File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -879,6 +879,23 @@ where
879
879
880
880
self . buffer . put ( & original[ ..] ) ;
881
881
882
+ // Clone after freeze does not allocate
883
+ let first_message_code = ( * self . buffer . get ( 0 ) . unwrap_or ( & 0 ) ) as char ;
884
+
885
+ // Almost certainly true
886
+ if first_message_code == 'P' {
887
+ // Message layout
888
+ // P followed by 32 int followed by null-terminated statement name
889
+ // So message code should be in offset 0 of the buffer, first character
890
+ // in prepared statement name would be index 5
891
+ let first_char_in_name = * self . buffer . get ( 5 ) . unwrap_or ( & 0 ) ;
892
+ if first_char_in_name != 0 {
893
+ // This is a named prepared statement
894
+ // Server connection state will need to be cleared at checkin
895
+ server. mark_dirty ( ) ;
896
+ }
897
+ }
898
+
882
899
self . send_and_receive_loop (
883
900
code,
884
901
self . buffer . clone ( ) ,
Original file line number Diff line number Diff line change @@ -638,6 +638,11 @@ impl Server {
638
638
pub fn last_activity ( & self ) -> SystemTime {
639
639
self . last_activity
640
640
}
641
+
642
+ // Marks a connection as needing DISCARD ALL at checkin
643
+ pub fn mark_dirty ( & mut self ) {
644
+ self . needs_cleanup = true ;
645
+ }
641
646
}
642
647
643
648
impl Drop for Server {
Original file line number Diff line number Diff line change 159
159
conn . async_exec ( "PREPARE prepared_q (int) AS SELECT $1" )
160
160
conn . close
161
161
end
162
+
163
+ 15 . times do
164
+ conn = PG ::connect ( processes . pgcat . connection_string ( "sharded_db" , "sharding_user" ) )
165
+ conn . prepare ( "prepared_q" , "SELECT $1" )
166
+ conn . close
167
+ end
162
168
end
163
169
164
170
it "Does not send DISCARD ALL unless necessary" do
165
171
10 . times do
166
172
conn = PG ::connect ( processes . pgcat . connection_string ( "sharded_db" , "sharding_user" ) )
167
173
conn . async_exec ( "SET SERVER ROLE to 'primary'" )
168
174
conn . async_exec ( "SELECT 1" )
175
+ conn . exec_params ( "SELECT $1" , [ 1 ] )
169
176
conn . close
170
177
end
171
178
You can’t perform that action at this time.
0 commit comments