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

release-20.1: lease: fix lease retention bug for tables taken offline #61144

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/sql/crdb_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ CREATE TABLE crdb_internal.leases (
ts.mu.Lock()
defer ts.mu.Unlock()

dropped := tree.MakeDBool(tree.DBool(ts.mu.dropped))
takenOffline := tree.MakeDBool(tree.DBool(ts.mu.takenOffline))

for _, state := range ts.mu.active.data {
if p.CheckAnyPrivilege(ctx, &state.TableDescriptor) != nil {
Expand All @@ -410,7 +410,7 @@ CREATE TABLE crdb_internal.leases (
tree.NewDString(state.Name),
tree.NewDInt(tree.DInt(int64(state.GetParentID()))),
&lease.expiration,
dropped,
takenOffline,
); err != nil {
return err
}
Expand Down
23 changes: 14 additions & 9 deletions pkg/sql/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,14 @@ type tableState struct {
// entry is created with the expiration time of the new lease and
// the older entry is removed.
active tableSet
// Indicates that the table has been dropped, or is being dropped.
// Indicates that the descriptor has been, or is being, dropped or taken
// offline.
// If set, leases are released from the store as soon as their
// refcount drops to 0, as opposed to waiting until they expire.
dropped bool
// This flag will be unset by any subsequent lease acquisition, which can
// happen after the table came back online again after having been taken
// offline temporarily (as opposed to dropped).
takenOffline bool
}
}

Expand Down Expand Up @@ -1024,6 +1028,7 @@ func acquireNodeLease(ctx context.Context, m *LeaseManager, id sqlbase.ID) (bool
}
t := m.findTableState(id, false /* create */)
t.mu.Lock()
t.mu.takenOffline = false
defer t.mu.Unlock()
toRelease, err = t.upsertLocked(newCtx, table)
if err != nil {
Expand Down Expand Up @@ -1065,9 +1070,9 @@ func (t *tableState) release(
// when the refcount drops to 0). If so, we'll need to mark the lease as
// invalid.
removeOnceDereferenced = removeOnceDereferenced ||
// Release from the store if the table has been dropped; no leases
// can be acquired any more.
t.mu.dropped ||
// Release from the store if the descriptor has been dropped or taken
// offline.
t.mu.takenOffline ||
// Release from the store if the lease is not for the latest
// version; only leases for the latest version can be acquired.
s != t.mu.active.findNewest()
Expand Down Expand Up @@ -1143,9 +1148,9 @@ func purgeOldVersions(
return nil
}

removeInactives := func(drop bool) {
removeInactives := func(takenOffline bool) {
t.mu.Lock()
t.mu.dropped = drop
t.mu.takenOffline = takenOffline
leases := t.removeInactiveVersions()
t.mu.Unlock()
for _, l := range leases {
Expand Down Expand Up @@ -1892,9 +1897,9 @@ func (m *LeaseManager) refreshSomeLeases(ctx context.Context) {
break
}
table.mu.Lock()
dropped := table.mu.dropped
takenOffline := table.mu.takenOffline
table.mu.Unlock()
if !dropped {
if !takenOffline {
ids = append(ids, k)
}
}
Expand Down