-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
92378: opt: add rule to replace outer cols with equivalent non-outer cols r=DrewKimball a=DrewKimball This commit adds three decorrelation rules, `TryRemapJoinOuterColsRight`, `TryRemapJoinOuterColsLeft`, and `TryRemapSelectOuterCols`. These rules match joins and selects that have a correlated input and an equality filter between an outer and a non-outer column from the input. Upon matching, the rules traverse the input as far as it would be valid to push the equality filter through normal push-down rules, and replace any encountered references to the equivalent outer column. This approach avoids interactions with rules like `TryDecorrelateSelect`, which attempt to pull filters *up* the operator tree when correlation is present. Fixes #88885 Release note: None 95620: sql: wait for one version lease if no job created for a descriptor r=chengxiong-ruan a=chengxiong-ruan Previously we only wait for one version in jobs for descriptors performed with schema changes. The problem is that we don't always create jobs for all descriptors modified. We need to wait for one version for these descriptors too. This pr adds logic to wait if there is no jobs created for a descriptor has new version. Fixes: #90600 Release note: None 95800: instancestorage: read instances in a transaction r=ajwerner a=healthy-pod This code change adds `(instancestorage.Reader).GetAllInstancesUsingTxn` to read all instances using the given `*kv.Txn`. Release note: None Epic: CRDB-18735 96004: sql/schemachanger: limit which op/dep rule helpers are shared r=fqazi a=fqazi Previously, the rules helpers were generally shared between releases inside the declarative schema changer. This could be problematic, since some helpers may get modified as new elements get added between releases. To address this, this patch moves most helpers back into individual rules, leaving a small subset as shared. Additionally, this patch version gates TypeFilter, so that only elements for a given release are visible. When comparing 22.2 versus the compatibility release the majority of differences are now linked with sorting changes and some constraint related adjustments (element renames and minor rules adjustment for ops). Epic: none Release note: None 96021: storage: Make logging event listener async for DiskSlow r=sumeerbhola a=itsbilal The pebble logger could block if we're experiencing a slow / stalling disk. If the call to the pebble logger is synchronous from the EventListener passed into Pebble, it could end up slowing down Pebble's internal disk health checks as those rely on EventListener methods being quick to run. This change updates the logging event listener to asynchronously call the logger on a DiskSlow event. Related to #94373. Epic: none Release note: None. Co-authored-by: Drew Kimball <[email protected]> Co-authored-by: Chengxiong Ruan <[email protected]> Co-authored-by: healthy-pod <[email protected]> Co-authored-by: Faizan Qazi <[email protected]> Co-authored-by: Bilal Akhtar <[email protected]>
- Loading branch information
Showing
73 changed files
with
2,953 additions
and
1,932 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
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,124 @@ | ||
// 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 sql | ||
|
||
import ( | ||
"github.com/cockroachdb/cockroach/pkg/jobs" | ||
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// waitOneVersionForNewVersionDescriptorsWithoutJobs is to used wait until all | ||
// descriptors with new versions to converge to one version in the cluster. | ||
// `descIDsInJobs` are collected with `descIDsInSchemaChangeJobs`. We need to do | ||
// this to make sure all descriptors mutated are at one version when the schema | ||
// change finish in the user transaction. In schema change jobs, we do similar | ||
// thing for affected descriptors. But, in some scenario, jobs are not created | ||
// for mutated descriptors. | ||
func (ex *connExecutor) waitOneVersionForNewVersionDescriptorsWithoutJobs( | ||
descIDsInJobs catalog.DescriptorIDSet, | ||
) error { | ||
withNewVersion, err := ex.extraTxnState.descCollection.GetOriginalPreviousIDVersionsForUncommitted() | ||
if err != nil { | ||
return err | ||
} | ||
for _, idVersion := range withNewVersion { | ||
if descIDsInJobs.Contains(idVersion.ID) { | ||
continue | ||
} | ||
if _, err := WaitToUpdateLeases(ex.Ctx(), ex.planner.LeaseMgr(), idVersion.ID); err != nil { | ||
// In most cases (normal schema changes), deleted descriptor should have | ||
// been handled by jobs. So, normally we won't hit into the situation of | ||
// wait for one version of a deleted descriptor. However, we need catch | ||
// ErrDescriptorNotFound here because we have a special case of descriptor | ||
// repairing where we delete descriptors directly and never record the ids | ||
// in jobs payload or details. | ||
if errors.Is(err, catalog.ErrDescriptorNotFound) { | ||
continue | ||
} | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// descIDsInSchemaChangeJobs returns all descriptor IDs with which schema change | ||
// jobs in this transaction will perform. Within schema change jobs, we also | ||
// wait until the whole cluster only has leases on the latest version of these | ||
// descriptors, and we would like to also "wait for one version" for descriptors | ||
// with new versions but not included in any schema change jobs. | ||
func (ex *connExecutor) descIDsInSchemaChangeJobs() (catalog.DescriptorIDSet, error) { | ||
// Get descriptor IDs from legacy schema changer jobs. | ||
var descIDsInJobs catalog.DescriptorIDSet | ||
if err := ex.extraTxnState.jobs.forEachToCreate(func(jobRecord *jobs.Record) error { | ||
switch t := jobRecord.Details.(type) { | ||
case jobspb.SchemaChangeDetails: | ||
// In most cases, the field DescriptorIDs contains descriptor IDs the | ||
// schema change directly affects. Like it could be a table ID if an index | ||
// is created, or it could be a list of schema IDs when dropping a group | ||
// of schemas. | ||
// But it can be confusing sometimes in two types of schema change jobs: | ||
// (1) dropping a database: | ||
// In this scenario, the DescriptorIDs is the ids of tables in this | ||
// database that will be dropped together. And the DroppedDatabaseID field | ||
// is the actual ID of the database that will be dropped. | ||
// (2) any other changes on a database (but not drop): | ||
// For example, when renaming a schema, database's list of all schemas | ||
// need to be updated, and we create a job for this kind of database | ||
// changes. DescriptorIDs is empty in this case and the DescID field in | ||
// the job | ||
// detail is the actual database ID. | ||
for _, descID := range jobRecord.DescriptorIDs { | ||
descIDsInJobs.Add(descID) | ||
} | ||
for _, tbl := range t.DroppedTables { | ||
descIDsInJobs.Add(tbl.ID) | ||
} | ||
for _, id := range t.DroppedTypes { | ||
descIDsInJobs.Add(id) | ||
} | ||
for _, id := range t.DroppedSchemas { | ||
descIDsInJobs.Add(id) | ||
} | ||
descIDsInJobs.Add(t.DroppedDatabaseID) | ||
descIDsInJobs.Add(t.DescID) | ||
} | ||
return nil | ||
}); err != nil { | ||
return catalog.DescriptorIDSet{}, err | ||
} | ||
|
||
// If there is no declarative schema changer job, then we are done. Otherwise, | ||
// we need to check which descriptor has the jobID in its schema change state. | ||
if ex.extraTxnState.schemaChangerState.jobID == jobspb.InvalidJobID { | ||
return descIDsInJobs, nil | ||
} | ||
// Get descriptor IDs with declarative schema changer jobs. | ||
withNewVersion, err := ex.extraTxnState.descCollection.GetOriginalPreviousIDVersionsForUncommitted() | ||
if err != nil { | ||
return catalog.DescriptorIDSet{}, err | ||
} | ||
for _, idVersion := range withNewVersion { | ||
if descIDsInJobs.Contains(idVersion.ID) { | ||
continue | ||
} | ||
desc, err := ex.extraTxnState.descCollection.ByID(ex.state.mu.txn).Get().Desc(ex.Ctx(), idVersion.ID) | ||
if err != nil { | ||
return catalog.DescriptorIDSet{}, err | ||
} | ||
state := desc.GetDeclarativeSchemaChangerState() | ||
if state != nil && state.JobID != jobspb.InvalidJobID { | ||
descIDsInJobs.Add(idVersion.ID) | ||
} | ||
} | ||
return descIDsInJobs, nil | ||
} |
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.