Skip to content
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

Consider adding transaction keep-alives when using psql #1826

Open
skuruppu opened this issue May 22, 2024 · 0 comments
Open

Consider adding transaction keep-alives when using psql #1826

skuruppu opened this issue May 22, 2024 · 0 comments

Comments

@skuruppu
Copy link

skuruppu commented May 22, 2024

I came across some unexpected behavior while using PGAdapter with psql. Here's the transaction example.

Transaction T1:

1. BEGIN;
2.
3. /*@LOCK_SCANNED_RANGES=exclusive*/SELECT id, name FROM singers WHERE singerid = 2;

id | name 
---+-----------
 2 | Catalina

4.

5. UPDATE singers SET name = 'Cat' WHERE id = 2;
--> update succeeded

6. COMMIT;

Transaction T2:

1.
2. BEGIN;
3.
4. SELECT id, name FROM singers WHERE id = 2;
--> actual: slow but returns, expected: be blocked on T1

id | name 
---+-----------
 2 | Catalina

5. COMMIT;

The unexpected behavior here is that because I grabbed an exclusive lock in T1 in step 3, I expected the SELECT in step 4 of T2 to block on T1 being committed. What I observed instead is that step 4 in T2 waiting a little bit and returned a result.

It turns out this happens because PGAdapter doesn't send keep-alives to keep transactions active beyond 10 secs. So T1 internally gets aborted after 10 secs of inactivity. Then T2 is able to get a result after T1 has released the locks on those cells of the table.

The reason why PGAdapter doesn't send keep-alives to keep transactions active is to stop users from accidentally holding onto locks for longer than necessary. This makes sense for production apps.

But given that psql is a CLI where users might be trying to run long-running transactions on purpose, it would be nice to keep the transactions alive so you don't get unexpected behaviours like the example above.

olavloite added a commit to googleapis/java-spanner that referenced this issue Jun 10, 2024
Adds a property to the Connection API for keeping read/write
transactions alive. This can be used in CLI-like applications
that might wait a longer period of time for user input. The
property is disabled by default, as enabling it can cause
read/write transactions to hold on to locks for a longer
period of time than intended.

Updates GoogleCloudPlatform/pgadapter#1826
olavloite added a commit to googleapis/java-spanner that referenced this issue Jul 3, 2024
* chore: add property for keep-transaction-alive

Adds a property to the Connection API for keeping read/write
transactions alive. This can be used in CLI-like applications
that might wait a longer period of time for user input. The
property is disabled by default, as enabling it can cause
read/write transactions to hold on to locks for a longer
period of time than intended.

Updates GoogleCloudPlatform/pgadapter#1826

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
surbhigarg92 pushed a commit to surbhigarg92/java-spanner that referenced this issue Jul 3, 2024
* chore: add property for keep-transaction-alive

Adds a property to the Connection API for keeping read/write
transactions alive. This can be used in CLI-like applications
that might wait a longer period of time for user input. The
property is disabled by default, as enabling it can cause
read/write transactions to hold on to locks for a longer
period of time than intended.

Updates GoogleCloudPlatform/pgadapter#1826

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant