Skip to content

Commit

Permalink
table/tables: fix assertion protocol for partition reorganize (#42497)
Browse files Browse the repository at this point in the history
close #42426
  • Loading branch information
tiancaiamao authored Mar 23, 2023
1 parent c5d10fb commit e68d3b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
17 changes: 11 additions & 6 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,12 @@ func (t *TableCommon) UpdateRecord(ctx context.Context, sctx sessionctx.Context,
})

if t.shouldAssert(sctx) {
if err = txn.SetAssertion(key, kv.SetAssertExist); err != nil {
return err
}
err = txn.SetAssertion(key, kv.SetAssertExist)
} else {
err = txn.SetAssertion(key, kv.SetAssertUnknown)
}
if err != nil {
return err
}

if err = injectMutationError(t, txn, sh); err != nil {
Expand Down Expand Up @@ -1346,9 +1349,11 @@ func (t *TableCommon) removeRowData(ctx sessionctx.Context, h kv.Handle) error {
})
if t.shouldAssert(ctx) {
err = txn.SetAssertion(key, kv.SetAssertExist)
if err != nil {
return err
}
} else {
err = txn.SetAssertion(key, kv.SetAssertUnknown)
}
if err != nil {
return err
}
return txn.Delete(key)
}
Expand Down
21 changes: 21 additions & 0 deletions tests/realtikvtest/sessiontest/session_fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,24 @@ func TestKill(t *testing.T) {
tk := testkit.NewTestKit(t, store)
tk.MustExec("kill connection_id();")
}

func TestIssue42426(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("CREATE TABLE `sbtest1` (" +
"`id` bigint(20) NOT NULL AUTO_INCREMENT," +
"`k` int(11) NOT NULL DEFAULT '0'," +
"`c` char(120) NOT NULL DEFAULT ''," +
"`pad` char(60) NOT NULL DEFAULT ''," +
"PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */," +
"KEY `k_1` (`k`)" +
") PARTITION BY RANGE (`id`)" +
"(PARTITION `pnew` VALUES LESS THAN (10000000)," +
"PARTITION `p5` VALUES LESS THAN (MAXVALUE));")
tk.MustExec(`INSERT INTO sbtest1 (id, k, c, pad) VALUES (502571, 499449, "init", "val");`)
tk.MustExec(`BEGIN`)
tk.MustExec(`DELETE FROM sbtest1 WHERE id=502571;`)
tk.MustExec(`INSERT INTO sbtest1 (id, k, c, pad) VALUES (502571, 499449, "abc", "def");`)
tk.MustExec(`COMMIT;`)
}

0 comments on commit e68d3b1

Please sign in to comment.