refactor: use BackendPid instead of BackendKeyData where secret is not required#1025
refactor: use BackendPid instead of BackendKeyData where secret is not required#1025meskill wants to merge 3 commits into
Conversation
a12f655 to
6e8a433
Compare
| copy_out: usize, | ||
| copy_data: usize, | ||
| first_backend_data: Option<BackendKeyData>, | ||
| first_backend_data: Option<BackendPid>, |
There was a problem hiding this comment.
This is extremely unlikely, but the backend PIDs could collide (same PID, different servers). The secret kinda makes sure that cannot practically happen.
There was a problem hiding this comment.
It's not likely, but possible. One simple fix (to quote our favorite bot coworker) could be to generate a unique ID for each server connection (struct Server) and use that for identification instead of whatever info Postgres returns. I used BackendKeyData because it was convenient originally and seemed pretty futureproof, but protocol 3.2 made things a bit harder for sure here.
6e8a433 to
c7711f7
Compare
|
Found 1 test failure on Blacksmith runners: Failure
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Refactor the codebase by using BackendKeyData (contains a connection secret) only where the secret is required, while all other places will use BackendPid (wrapper around u32) to refer the connection or store it. The BackendKeyData becomes complex type without copy and hash and it should be cloned where needed instead and it makes visible the non-free operation of 256 bytes array copying.
The performance benefits are not huge and I had to tweak the pgbench configuration with options
-t 10000 -c 100to see the difference around the commit #2f70a7a70cc8eceefe577f994e89b5e943e0724d that added the support for the extended secret.Benchmark comparisions
The performance difference is there. Integration test for cancellation has been added and some around refactoring have done.