Skip to content

Update statement does not always block when a different transaction has an exclusive lock for a row #88995

@beikov

Description

@beikov

Describe the problem

Update statement does not always block when a different transaction has an exclusive lock for a row.

To Reproduce

  1. On connection 1, start TX1
  2. TX1: Run select * from tbl1 t where t.id = 1 for update of t to lock a single row
  3. On connection 2, start TX2
  4. TX2: Run SET statement_timeout TO 100
  5. TX2: Run select * from tbl1 t where t.id = 1
  6. TX2: Run update tbl1 t set t.value = 'changed' where t.id = 1

Expected behavior

TX2 should block at step 6. since TX1 has a lock on the row, and TX2 should run into a timeout. It seems though, that "sometimes" the statement at step 6. succeeds.

As it is with timeout based stuff, this hard to reproduce reliably, but I wanted to report this anyway, as I believe there might be a concurrency issue lurking in CockroachDB that you might be able to find by looking at the code with this given example. The issue happened after a lot of other Hibernate testcases were executed i.e. after a lot of statements like create table, insert, select, update, delete, drop table.

Environment:

  • CockroachDB version: 21.2.15
  • Server OS: Linux Docker
  • Client app: JDBC/Hibernate

Here are SQL log excerpts from the run:

    drop table if exists T_LOCK_A cascade
    create table T_LOCK_A (
       id bigint not null,
        a_value varchar(255),
        primary key (id)
    )

... lots of insert, select for update, update, delete statements

    insert 
    into
        T_LOCK_A
        (a_value, id) 
    values
        (?, ?)
[subsystem] TRACE g.hibernate.orm.jdbc.bind JdbcBindingLogging:28 - binding parameter [1] as [VARCHAR] - [it]
[subsystem] TRACE g.hibernate.orm.jdbc.bind JdbcBindingLogging:28 - binding parameter [2] as [BIGINT] - [6]

TX1 starts:

16:30:14,930 DEBUG SQL:128 - 
    select
        a1_0.id,
        a1_0.a_value 
    from
        T_LOCK_A a1_0 for update of a1_0
[subsystem] TRACE ibernate.orm.jdbc.extract JdbcExtractingLogging:28 - extracted value ([1] : [BIGINT]) - [6]
[subsystem] TRACE ibernate.orm.jdbc.extract JdbcExtractingLogging:28 - extracted value ([2] : [VARCHAR]) - [it]

TX2 starts: 

16:30:14,932 DEBUG SQL:128 - 
    select
        a1_0.id,
        a1_0.a_value 
    from
        T_LOCK_A a1_0 
    where
        a1_0.id=?
[subsystem] TRACE g.hibernate.orm.jdbc.bind JdbcBindingLogging:28 - binding parameter [1] as [BIGINT] - [6]
[subsystem] TRACE ibernate.orm.jdbc.extract JdbcExtractingLogging:28 - extracted value ([1] : [BIGINT]) - [6]
[subsystem] TRACE ibernate.orm.jdbc.extract JdbcExtractingLogging:28 - extracted value ([2] : [VARCHAR]) - [it]
16:30:14,936 DEBUG SQL:128 - 
    UPDATE
        T_LOCK_A 
    SET
        a_value = ? 
    where
        id = ?
[subsystem] TRACE g.hibernate.orm.jdbc.bind JdbcBindingLogging:28 - binding parameter [1] as [VARCHAR] - [changed]
[subsystem] TRACE g.hibernate.orm.jdbc.bind JdbcBindingLogging:28 - binding parameter [2] as [BIGINT] - [6]

Jira issue: CRDB-20070

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-communityOriginated from the communityT-kvKV TeamX-blathers-triagedblathers was able to find an owner

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions