-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#20549] YSQL: Fix Read Committed txn read time (snapshots) management
Summary: In read committed transaction each statement resets read time at the beginning to read the latest data from DB. This read time must be used by the whole statement. It is possible that statement calls another statement during execution which may selects its own read time. Simplest example is the function call ``` CREATE FUNCTION foo(n INT) RETURNS INT AS DECLARE vvv INT; BEGIN SELECT v FROM aux_t WHERE k = n INTO vvv; -- selects own read time before execution RETURN nnn; END; UPDATE t SET v = v + 10 WHERE foo(k) = v -- selects own read time before execution ``` `PgClientSession` class preserves read time after applying latest operations. As a result when `statement_1` continue execution after calling of the `statement_2` read time selected by the `statement_2` will be used (it is preserved in `PgClientSession` object). To handle this scenario YSQL should restore read time for `statement_1` prior to continue its execution. Postgres code uses stack of `Snapshot` structures for this purpose. Each statement uses its own snapshot data. And prior to continue execution of `statement_1` postgres sets `statement_1`'s snapshot as active. This diff reuses postgres' infrastructure of snapshots and store `read_time_serial_no` in the newly created field `yb_read_time_point_handle` of `SnapshotData` structure. When particular snapshot become active appropriate `read_time_serial_no` is propagated to the `PgTxnManager` object. Further RW operations will be sent to `PgClientSession` object with this `read_time_serial_no`. As a result all the `statement_1`'s operations will use same `read_time_serial_no` (i.e. same read time) even in case other statements are called in the middle. Jira: DB-9557 Test Plan: Jenkins New unit tests are introduced ``` ./yb_build.sh --gtest_filter PgTxnTest.ReadAtMultipleTimestamps ./yb_build.sh --gtest_filter PgTxnTest.ReadAtMultipleTimestampsWithConflict ``` Reviewers: pjain, amartsinchyk, patnaik.balivada Reviewed By: pjain Subscribers: ybase, bogdan, yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D32313
- Loading branch information
1 parent
507d287
commit edbd06b
Showing
17 changed files
with
458 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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.