Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
niclaflamme committed Aug 10, 2025
commit 374107fcb5c7519ebe9264f725993963a55702ba
21 changes: 3 additions & 18 deletions pgdog/src/backend/pool/connection/binding.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Binding between frontend client and a connection on the backend.

use crate::{
net::{parameter::Parameters, ProtocolMessage},
net::{parameter::Parameters, ProtocolMessage, Query},
state::State,
};

Expand Down Expand Up @@ -240,23 +240,8 @@ impl Binding {
/// Execute a BEGIN on all servers
/// TODO: Block mutli-shard BEGINs as transaction should not occur on multiple shards
pub async fn begin(&mut self) -> Result<(), Error> {
let begin: &str = "BEGIN;";

match self {
Binding::Server(Some(ref mut server)) => {
server.execute(&begin).await?;
}

Binding::MultiShard(ref mut servers, _) => {
for server in servers {
server.execute(&begin).await?;
}
}

_ => (),
}

Ok(())
let query = Query::new("BEGIN");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment. Client can pass options to BEGIN, changing transaction type.

self.execute(query.query()).await
}

pub async fn link_client(&mut self, params: &Parameters) -> Result<usize, Error> {
Expand Down
2 changes: 0 additions & 2 deletions pgdog/src/frontend/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,12 @@ impl Client {
}
Some(Command::RollbackTransaction) => {
self.end_transaction(true).await?;
self.logical_transaction.rollback()?;

inner.done(self.in_transaction());
return Ok(false);
}
Some(Command::CommitTransaction) => {
self.end_transaction(false).await?;
self.logical_transaction.commit()?;

inner.done(self.in_transaction());
return Ok(false);
Expand Down
7 changes: 7 additions & 0 deletions pgdog/src/frontend/client/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ async fn test_transaction_state() {

read!(conn, ['2', 'D', 'C', 'Z']);

println!("router.route {:?}", inner.router.route());
println!("router.route {:?}", inner.router.route());
println!("router.route {:?}", inner.router.route());
println!("router.route {:?}", inner.router.route());
println!("router.route {:?}", inner.router.route());
println!("router.route {:?}", inner.router.route());

assert!(inner.router.routed());
assert!(client.in_transaction());
assert!(inner.router.route().is_write());
Expand Down
Loading