-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
107633: sql/schemachanger: DROP INDEX could drop unrelated foreign keys r=fqazi a=fqazi Previously, when DROP INDEX was resolving and iterating over foreign keys, it did not validate that these foreign keys were related to the index we were dropping. As a result, if any table referred back to the target table with the index, we would analyze its foreign keys. If cascade wasn't specified this could incorrectly end up blocking the DROP INDEX on unrelated foreign key references assuming they need our index. Or worse with cascade we could remove foreign key constraints in other tables. To address this, this patch filters the back references to only look at ones related to the target table, which causes the correct set to be analuzed / dropped. Fixes: #107576 Release note (bug fix): Dropping an index could end up failing or cleaning foreign keys (when CASCADE is specified) on other tables referencing the target table with this index. 107646: sql: use a random minute for the sql-stats-compaction job default recurrence r=maryliag a=rafiss ### scheduledjobs: move MaybeRewriteCronExpr into package This was moved from the schematelemetrycontroller package. There are no code changes in this commit. ---- ### sql: use a random minute for the sql-stats-compaction job default recurrence Now, the sql-stats-compaction job that is created during cluster initialization will be scheduled on a random minute in the hour, rather than at the top of the hour. This will only affect clusters that are initialized after this change is released. Any existing clusters will continue to keep whatever recurrence they had before, which defaulted to `@hourly.` This change was made because we have observed that this job can cause CPU spikes on the serverless host clusters, since different tenants all had this job scheduled for the same time. --- see: https://cockroachlabs.slack.com/archives/C04U1BTF8/p1688829944578639 refs: #54537 Epic: None Release note: None Co-authored-by: Faizan Qazi <[email protected]> Co-authored-by: Rafi Shamim <[email protected]>
- Loading branch information
Showing
20 changed files
with
167 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package scheduledjobs | ||
|
||
import ( | ||
"fmt" | ||
"hash/fnv" | ||
"math/rand" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/util/uuid" | ||
) | ||
|
||
const ( | ||
cronWeekly = "@weekly" | ||
cronDaily = "@daily" | ||
cronHourly = "@hourly" | ||
) | ||
|
||
// MaybeRewriteCronExpr is used to rewrite the interval-oriented cron exprs | ||
// into an equivalent frequency interval but with an offset derived from the | ||
// uuid. For a given pair of inputs, the output of this function will always | ||
// be the same. If the input cronExpr is not a special form as denoted by | ||
// the keys of cronExprRewrites, it will be returned unmodified. This rewrite | ||
// occurs in order to uniformly distribute the production of telemetry logs | ||
// over the intended time interval to avoid bursts. | ||
func MaybeRewriteCronExpr(id uuid.UUID, cronExpr string) string { | ||
if f, ok := cronExprRewrites[cronExpr]; ok { | ||
hash := fnv.New64a() // arbitrary hash function | ||
_, _ = hash.Write(id.GetBytes()) | ||
return f(rand.New(rand.NewSource(int64(hash.Sum64())))) | ||
} | ||
return cronExpr | ||
} | ||
|
||
var cronExprRewrites = map[string]func(r *rand.Rand) string{ | ||
cronWeekly: func(r *rand.Rand) string { | ||
return fmt.Sprintf("%d %d * * %d", r.Intn(60), r.Intn(23), r.Intn(7)) | ||
}, | ||
cronDaily: func(r *rand.Rand) string { | ||
return fmt.Sprintf("%d %d * * *", r.Intn(60), r.Intn(23)) | ||
}, | ||
cronHourly: func(r *rand.Rand) string { | ||
return fmt.Sprintf("%d * * * *", r.Intn(60)) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.