Skip to content

Commit 9d024ef

Browse files
committed
catalog/lease: address deadlock with locked lease timestamps
Previously, when locked lease timestamps were used, we held the descriptor state while acquiring close timestamp handles. This could lead to a deadlock, since in other code paths we acquire the close timestamp handle first. To address this, this patch avoids holding the descriptor state lock longer then necessary. Fixes: #156177 Release note: None
1 parent 40466eb commit 9d024ef

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pkg/sql/catalog/lease/lease.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,12 +1321,14 @@ func (m *Manager) purgeOldVersions(
13211321
handle.release(ctx)
13221322
}
13231323
}()
1324-
state := m.findDescriptorState(id, false)
1325-
state.mu.Lock()
1326-
defer state.mu.Unlock()
1327-
// Find the previous version and determine the timestamp handle that
1328-
// it belongs to.
1329-
prev := state.mu.active.findPrevious()
1324+
prev, newest := func() (*descriptorVersionState, *descriptorVersionState) {
1325+
state := m.findDescriptorState(id, false)
1326+
state.mu.Lock()
1327+
defer state.mu.Unlock()
1328+
// Find the previous version and determine the timestamp handle that
1329+
// it belongs to.
1330+
return state.mu.active.findPrevious(), state.mu.active.findNewest()
1331+
}()
13301332
// If there is no previous or the previous version is a historical descriptor,
13311333
// nothing needs to be done (i.e. no active lease or already setup for
13321334
// expiration).
@@ -1358,8 +1360,8 @@ func (m *Manager) purgeOldVersions(
13581360
handle.mu.leasesToRelease[id].(*descriptorVersionState).getExpiration(ctx),
13591361
prev.GetVersion(),
13601362
prev.getExpiration(ctx),
1361-
state.mu.active.findNewest().GetVersion(),
1362-
state.mu.active.findNewest().getExpiration(ctx))
1363+
newest.GetVersion(),
1364+
newest.getExpiration(ctx))
13631365
}
13641366
// Bump the refcount on the previous version of the descriptor and attach
13651367
// it to the relevant timestamp.

0 commit comments

Comments
 (0)