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-21.2: sql: support for temporary table clean up for tenants #70129

Merged
merged 1 commit into from
Sep 14, 2021
Merged
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
25 changes: 16 additions & 9 deletions pkg/sql/temporary_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,22 @@ func (c *TemporaryObjectCleaner) doTemporaryObjectCleanup(
)
}

// We only want to perform the cleanup if we are holding the meta1 lease.
// This ensures only one server can perform the job at a time.
isLeaseholder, err := c.isMeta1LeaseholderFunc(ctx, c.db.Clock().NowAsClockTimestamp())
if err != nil {
return err
}
if !isLeaseholder {
log.Infof(ctx, "skipping temporary object cleanup run as it is not the leaseholder")
return nil
// For tenants, we will completely skip this logic since you
// can only have a single pod. So, we can execute the logic
// to clean up tables directly here without any coordination.
if c.codec.ForSystemTenant() {
// We only want to perform the cleanup if we are holding the meta1 lease.
// This ensures only one server can perform the job at a time.
isLeaseHolder, err := c.isMeta1LeaseholderFunc(ctx, c.db.Clock().NowAsClockTimestamp())
if err != nil {
return err
}
// For the system tenant we will check if the lease is held. For tenants
// every single POD will try to execute this clean up logic.
if !isLeaseHolder {
log.Infof(ctx, "skipping temporary object cleanup run as it is not the leaseholder")
return nil
}
}

c.metrics.ActiveCleaners.Inc(1)
Expand Down