Skip to content

Commit

Permalink
skip unlock remote table for remote txn (#16130)
Browse files Browse the repository at this point in the history
skip unlock remote table for remote txn

Approved by: @zhangxu19830126
  • Loading branch information
iamlinjunhong committed May 15, 2024
1 parent 10c7f69 commit a6c1f3d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
55 changes: 55 additions & 0 deletions pkg/lockservice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,61 @@ func TestReLockSuccWithLockTableBindChanged(t *testing.T) {
)
}

func TestIssue16121(t *testing.T) {
runLockServiceTestsWithLevel(
t,
zapcore.DebugLevel,
[]string{"s1", "s2"},
time.Second*1,
func(alloc *lockTableAllocator, s []*service) {
l1 := s[0]
l2 := s[1]

ctx, cancel := context.WithTimeout(
context.Background(),
time.Second*10)
defer cancel()
option := pb.LockOptions{
Granularity: pb.Granularity_Row,
Mode: pb.LockMode_Exclusive,
Policy: pb.WaitPolicy_Wait,
}

_, err := l1.Lock(
ctx,
0,
[][]byte{{1}},
[]byte("txn1"),
option)
require.NoError(t, err)
require.NoError(t, l1.Unlock(ctx, []byte("txn1"), timestamp.Timestamp{}))

_, err = l2.Lock(
ctx,
0,
[][]byte{{1}},
[]byte("txn2"),
option)
require.NoError(t, err)

// change lock table to remote from local
b := l1.tableGroups.get(0, 0).getBind()
b.ServiceID = l2.serviceID
r := &remoteLockTable{
serviceID: l2.serviceID,
bind: b,
}
l1.tableGroups.Lock()
l1.tableGroups.holders[0].tables[0] = r
l1.tableGroups.Unlock()

require.NoError(t, l2.Unlock(ctx, []byte("txn2"), timestamp.Timestamp{}))

},
nil,
)
}

func TestReLockSuccWithBindChanged(t *testing.T) {
runLockServiceTestsWithLevel(
t,
Expand Down
12 changes: 11 additions & 1 deletion pkg/lockservice/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ func (txn *activeTxn) close(
// cancel all blocked waiters
txn.cancelBlocks()

isRemoteTable := txn.remoteService != ""
canSkipTable := func(isRemoteTable bool, l lockTable) bool {
if isRemoteTable {
if _, ok := l.(*remoteLockTable); ok {
return true
}
}
return false
}

n := len(txn.lockHolders)
var wg sync.WaitGroup
v2.TxnUnlockTableTotalHistogram.Observe(float64(n))
Expand All @@ -147,7 +157,7 @@ func (txn *activeTxn) close(
// LockTable, it is a bug.
panic(err)
}
if l == nil {
if l == nil || canSkipTable(isRemoteTable, l) {
continue
}

Expand Down

0 comments on commit a6c1f3d

Please sign in to comment.