Skip to content

Commit ec09e20

Browse files
craig[bot]fqazi
andcommitted
Merge #151496
151496: catalog/lease: prevent lease acquisition during draining r=fqazi a=fqazi Previously, the lease manager only blocked the acquisition of new descriptors while draining was occurring. So, it was possible for internal queries to come in and increase reference counts in a non-deterministic way while we are attempting to drain. To address this, this patch prevent all lease acquisition when draining is occurring. Fixes: #151462 Fixes: #150680 Fixes: #150654 Release note: None Co-authored-by: Faizan Qazi <[email protected]>
2 parents 10cdedf + 5bbc45b commit ec09e20

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pkg/sql/catalog/lease/lease.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import (
6464

6565
var errRenewLease = errors.New("renew lease on id")
6666
var errReadOlderVersion = errors.New("read older descriptor version from store")
67+
var errLeaseManagerIsDraining = errors.New("cannot acquire lease when draining")
6768

6869
// LeaseDuration controls the duration of sql descriptor leases.
6970
var LeaseDuration = settings.RegisterDurationSetting(
@@ -882,7 +883,7 @@ func acquireNodeLease(
882883
},
883884
func(ctx context.Context) (interface{}, error) {
884885
if m.IsDraining() {
885-
return nil, errors.New("cannot acquire lease when draining")
886+
return nil, errLeaseManagerIsDraining
886887
}
887888
newest := m.findNewest(id)
888889
var currentVersion descpb.DescriptorVersion
@@ -1359,6 +1360,9 @@ func (m *Manager) AcquireByName(
13591360
parentSchemaID descpb.ID,
13601361
name string,
13611362
) (LeasedDescriptor, error) {
1363+
if m.IsDraining() {
1364+
return nil, errLeaseManagerIsDraining
1365+
}
13621366
// When offline descriptor leases were not allowed to be cached,
13631367
// attempt to acquire a lease on them would generate a descriptor
13641368
// offline error. Recent changes allow offline descriptor leases
@@ -1531,6 +1535,9 @@ func (m *Manager) Acquire(
15311535
ctx context.Context, timestamp hlc.Timestamp, id descpb.ID,
15321536
) (LeasedDescriptor, error) {
15331537
for {
1538+
if m.IsDraining() {
1539+
return nil, errLeaseManagerIsDraining
1540+
}
15341541
t := m.findDescriptorState(id, true /*create*/)
15351542
desc, _, err := t.findForTimestamp(ctx, timestamp)
15361543
if err == nil {
@@ -1602,8 +1609,12 @@ func (m *Manager) SetDraining(
16021609
t.mu.Lock()
16031610
defer t.mu.Unlock()
16041611
leasesToRelease := t.removeInactiveVersions(ctx)
1605-
// Ensure that all leases are released at this time.
1606-
if buildutil.CrdbTestBuild && assertOnLeakedDescriptor && len(t.mu.active.data) > 0 {
1612+
// Ensure that all leases are released at this time. Ignore any descriptors
1613+
// that have acquisitions in progress.
1614+
if buildutil.CrdbTestBuild &&
1615+
assertOnLeakedDescriptor &&
1616+
len(t.mu.active.data) > 0 &&
1617+
t.mu.acquisitionsInProgress == 0 {
16071618
// Panic that a descriptor may have leaked.
16081619
panic(errors.AssertionFailedf("descriptor leak was detected for: %d (%s)", t.id, t.mu.active))
16091620
}

0 commit comments

Comments
 (0)