pgcat icon indicating copy to clipboard operation
pgcat copied to clipboard

Added the `transparent` mode

Open mdashti opened this issue 1 year ago • 0 comments

This is a preview for the transparent mode, which transparently supports distributed transactions (with two-phase commit).

The current PR is created for the purpose of getting your feedback.

The main missing element is the lack of tests in the PR, which will be added soon.

Please note that I've tried to move the PR-specific changes to client_xact.rs, server_xact.rs, and query_messages.rs, but it's natural for some of those functions to become a part of client.rs, server.rs and messages.rs respectively. This is especially true for the functions that can be methods of Client or Server.

Here's an example of how you can try this PR (using the default pgcat settings (i.e., pgcat.toml in the repo root):

Step 1: connect to pgcat:

PGPASSWORD="sharding_user" psql sharded_db -h 127.0.0.1 -p 6432 -U sharding_user

Step 2: Initialize your database:

set shard to '0'; drop table if exists test_tbl; 
set shard to '1'; drop table if exists test_tbl; 

set shard to '0'; create table test_tbl (n int); 
set shard to '1'; create table test_tbl (n int); 

set shard to '0'; insert into test_tbl values (2), (4);
set shard to '1'; insert into test_tbl values (1), (3);

Step 3: run a distributed transaction:

set shard to '0'; begin; select * from test_tbl where n >= 3;

-- implicitly begins a distributed transaction
set shard to '1'; select * from test_tbl where n >= 3;

-- commits the distributed transaction
commit;

mdashti avatar Sep 22 '23 09:09 mdashti