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

Op_Lock could not trigger pessimistic lock write conflict #428

Open
cfzjywxk opened this issue Nov 24, 2020 · 4 comments
Open

Op_Lock could not trigger pessimistic lock write conflict #428

cfzjywxk opened this issue Nov 24, 2020 · 4 comments

Comments

@cfzjywxk
Copy link
Contributor

Consider such case

func (s *testMvccSuite) TestPessimisticLockConflict(c *C) {
	store, err := NewTestStore("TestPessimisticLockConflict", "TestPessimisticLockConflict", c)
	c.Assert(err, IsNil)
	defer CleanTestStore(store)

	// txn1
	k := []byte("tk")
	v := []byte("v")
	MustPrewritePut(k, k, v, 5, store)
	MustCommit(k, 5, 10, store)

        // txn2
	MustPrewriteLock(k, k, 12, store)
	MustCommit(k, 12, 13, store)

        // txn3
	_, err = PessimisticLock(k, k, 11, lockTTL, 11, false, false, store)
	c.Assert(err, NotNil)
}

The last PessimsiticLock request should get an error since its startTS is smaller than the commitTS of the txn2, but it succeeded.
Seems Op_Lock write record could not be found from the storage engine or is collapsed without keeping a newset one?

@coocood
Copy link
Collaborator

coocood commented Nov 25, 2020

It is not collapsed, it's stored in a different key space, so they don't conflict each other, the commit status of Op_Lock can still be checked by CheckTxnStatus.

@cfzjywxk
Copy link
Contributor Author

It is not collapsed, it's stored in a different key space, so they don't conflict each other, the commit status of Op_Lock can still be checked by CheckTxnStatus.

The getDBItems does't return the Op_Lock record, it's needed to judge if a pessmistic lock request should get write conflict error. Some unit test cases in TiDB will fail using mockstore but not using TiKV because of this incompatibility.

@coocood
Copy link
Collaborator

coocood commented Nov 25, 2020

OK, you can change it to be compatible.

@cfzjywxk
Copy link
Contributor Author

cfzjywxk commented Mar 1, 2021

For optimistic transactions, the write conflict for Op_Lock could not be triggered, examples:
Start a tidb instance with unistore

mysql> create table t1(c1 int primary key, c2 int);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t1 values(1, 10);
Query OK, 1 row affected (0.01 sec)

session1:
mysql> begin optimistic;
Query OK, 0 rows affected (0.00 sec)

session1:
mysql> update t1 set c2 = c2 + 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

session2:
mysql> begin optimistic;
Query OK, 0 rows affected (0.01 sec)

session2:
mysql> select * from t1 for update;
+----+------+
| c1 | c2   |
+----+------+
|  1 |   10 |
+----+------+
1 row in set (0.00 sec)

session2:
mysql> commit;

session1:
mysql> commit; // expected to report write conflict error

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

2 participants