Repository navigation
sql: implement Query.cancel() for postgres #33370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
acec2d8
sql: implement Query.cancel() for postgres
robobun d920eab
sql: only send a postgres CancelRequest for the query the backend is …
robobun 771c008
sql: release the postgres query's connection edge on the failure paths
robobun 6109374
sql: reject a cancelled query when it first runs, not inside cancel()
robobun df87e6e
sql: trim the comments on the postgres cancel path
robobun 43d3780
sql: bound the postgres cancel connection's connect attempt too
robobun afef5ca
sql: one-line the two comments on the postgres cancel socket
robobun f119b73
sql: move the cancel-before-run tests into their own file
robobun 7a18dc7
ci: retrigger
robobun d54d683
Merge branch 'main' into farm/4be26dfa/postgres-query-cancel
robobun 4f1d494
sql: release the pending-request count when a queued query is cancelled
robobun b377317
Merge branch 'main' into farm/4be26dfa/postgres-query-cancel
robobun 907bd97
sql: reject a cancelled pipelined query through the in-flight rejection
robobun 60a71df
sql: let the query handler reject a query cancelled before it runs
robobun e72981d
sql: shorten the discard_response doc comment
robobun ae6e96a
sql: say in the error when a cancelled query still runs on the server
robobun 74fb430
sql: pass the port of the cancel connection as a number
robobun f3d7df8
sql(postgres): move the allocate-and-dial block of createConnection i…
robobun 39297bb
Merge branch 'robobun/4be26dfa/postgres-connection-open' into farm/4b…
robobun 78dcace
sql(postgres): open the cancel connection from the session, in native…
robobun 81b6310
sql: test that a cancel connection never goes out in the clear for a …
robobun ec1eec7
sql: shorten the send_cancel_request doc comment
robobun ac3e96d
Merge branch 'robobun/4be26dfa/postgres-connection-open' into farm/4b…
robobun c0e36e3
sql(postgres): return the connect error from open and throw it in cre…
robobun 3ccf2df
sql: log a cancel connection that cannot be dialed
robobun c2b627f
sql(postgres): build the strings of a connection in one constructor
robobun 59d46e3
Merge branch 'robobun/4be26dfa/postgres-connection-open' into farm/4b…
robobun 998a6fa
sql(postgres): name the functions that build and store the connection…
robobun 819cd9c
sql(postgres): write the terminators of the connection strings
robobun 6eb94ff
Merge branch 'robobun/4be26dfa/postgres-connection-open' into farm/4b…
robobun df941a0
sql(postgres): let the process exit after a dial that never opens, an…
robobun 3b664c6
docs(sql): say that a late cancel request can stop the next query
robobun e8b81f9
test(sql): check that the cancel connection verifies the host name of…
robobun 358721d
Merge branch 'main' into farm/4be26dfa/postgres-query-cancel
robobun 76a436e
sql(postgres): send no CancelRequest for a query that ended during th…
robobun c55aa7a
test(sql): give the pg_sleep poll of the real-server cancel test a de…
robobun 950a49c
sql(postgres): cancel a query whose session closed, and decide at the…
robobun 2bd4fe5
Merge branch 'main' into farm/4be26dfa/postgres-query-cancel
robobun a46f129
sql(postgres): keep a query off the wire when the code of its paramet…
robobun 3570e33
test(sql): cancel() while only the Parse of a query is on the wire
robobun e1c5315
sql(postgres): shorten two comments
robobun 52e8500
test(sql): close the pool of each round of the GC test with its scope
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,36 @@ | ||
| use super::new_reader::NewReader; | ||
| use crate::postgres::AnyPostgresError; | ||
|
|
||
| pub struct BackendKeyData {} | ||
| /// CancelRequest's stand-in for the protocol version: `(1234 << 16) | 5678`. | ||
| const CANCEL_REQUEST_CODE: u32 = 80877102; | ||
|
|
||
| pub struct BackendKeyData { | ||
| pub process_id: u32, | ||
| pub secret_key: u32, | ||
| } | ||
|
|
||
| impl BackendKeyData { | ||
| /// `Int32(16) Int32(80877102) Int32(pid) Int32(secret)`: no type byte, it | ||
| /// is the only message on a connection opened just to carry it. | ||
|
robobun marked this conversation as resolved.
Resolved
|
||
| pub fn cancel_request(&self) -> [u8; 16] { | ||
| let mut packet = [0u8; 16]; | ||
| packet[0..4].copy_from_slice(&16u32.to_be_bytes()); | ||
| packet[4..8].copy_from_slice(&CANCEL_REQUEST_CODE.to_be_bytes()); | ||
| packet[8..12].copy_from_slice(&self.process_id.to_be_bytes()); | ||
| packet[12..16].copy_from_slice(&self.secret_key.to_be_bytes()); | ||
| packet | ||
| } | ||
|
|
||
| pub fn decode_internal<Container: super::new_reader::ReaderContext>( | ||
| mut reader: NewReader<Container>, | ||
| ) -> Result<Self, AnyPostgresError> { | ||
| if !reader.expect_int::<u32>(12)? { | ||
| return Err(AnyPostgresError::InvalidBackendKeyData); | ||
| } | ||
|
|
||
| // process_id, secret_key | ||
| reader.int4()?; | ||
| reader.int4()?; | ||
| Ok(Self {}) | ||
| Ok(Self { | ||
| process_id: reader.int4()?, | ||
| secret_key: reader.int4()?, | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.