yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
8.99k stars 1.07k forks source link

[YSQL] Incorrectly blocking conflicting insert on nonexistent row with single-RPC locking in RC and RR isolation levels #18316

Open foucher opened 1 year ago

foucher commented 1 year ago

Jira Link: DB-7306

Description

In RR and RC isolation modes, when selecting a row that does not exist by PK, an insertion of a row with that PK hangs.

Setup:

CREATE TABLE t (k int PRIMARY KEY);

Session 1:

BEGIN ISOLATION LEVEL REPEATABLE READ;
SELECT * FROM t WHERE k=1 FOR UPDATE;

Session 2:

BEGIN ISOLATION LEVEL REPEATABLE READ;
INSERT INTO t VALUES (1);
COMMIT;

Expected (well, prior behavior, and behavior with yb_lock_pk_single_rpc set to false in ysqlsh:

Result:

Warning: Please confirm that this issue does not contain any sensitive information

foucher commented 1 year ago

Several of us met and the current plan is the following:

At a high level, this does about the same work that the previous code using a LockRows node did--in that case, we did one RPC to read the row, and then if it existed, we would send the row marks to lock a specific ybctid. So this new method just removes the need for the second RPC.

An autoflag is now required, in case PG is upgraded (and would send single-RPC lock+select), but tserver is not. Without an autoflag for this, YugabyteDB would exhibit the behavior described in this bug.

foucher commented 1 year ago

Another set of people met, and the new plan is the following:

An autoflag is still required.