You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[#25105] YSQL: Clear pggate session state on query retry
Summary:
During the course of its execution, a query accumulates state in its pggate session. Some of the state is stored in:
- The foreign key buffer which holds a collections of keys to be inspected, as well as a collection of keys thus far seen by the transaction.
- The explicit row lock buffer which holds a collection of rows that are to be locked explicitly.
- The insert on conflict buffer which holds a collection of keys to be inspected as well a collection of rows thus far modified by the query.
Currently, this state is cleared only at the transaction boundary by operations such as recreating, restarting and aborting a DML transaction.
Notably, this state is NOT cleared when a sub-transaction is rolled back. An example of this is when a query is retried (such as due to a kConflict or a kReadRestart error) in read committed mode.
This works fine with the row lock buffer which is largely idempotent (adding the same key/row to the buffer upon retry did not affect the state). However, it can cause issues with the foreign key buffer ([[ #25234 | GH-25234 ]]).
D39023 introduced a new insert-on-conflict buffer which is not idempotent.
One of the functions of this buffer is to ensure that a row is not modified twice within the same transaction.
Since two iterations of the same query, are likely to modify the same row(s), residual state can lead to the buffer incorrectly deducing that the same row has been modified twice.
This revision:
- Introduces the distinction that some session state is sub-transaction-scoped ie. needs to be cleared at the sub-transaction boundary (such as for each retry/iteration of a query), while others are transaction-scoped ie. can be cleared at the transaction boundary only.
- Explicitly clears sub-transaction-scoped session state when the subtransaction is rolled back.
- Does not alter the behavior of the foreign key buffer.
Jira: DB-14251
Test Plan:
Run the following automated test:
```
./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressIsolationWithoutWaitQueues#testPgRegress'
./yb_build.sh --cxx-test pgwrapper_pg_libpq-test --gtest_filter 'BatchInsertOnConflictTest.InsertOnConflictWithQueryRestart'
```
Jenkins: urgent
Reviewers: patnaik.balivada, pjain, telgersma
Reviewed By: patnaik.balivada, pjain
Subscribers: smishra, yql
Tags: #jenkins-ready
Differential Revision: https://phorge.dev.yugabyte.com/D40460
0 commit comments