Skip to content

Commit

Permalink
sql: wait for one version lease if no job created for a descriptor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chengxiong-ruan committed Jan 20, 2023
1 parent c8c4241 commit 7e09c3c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/sql/conn_executor_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"
"github.com/cockroachdb/cockroach/pkg/sql/clusterunique"
Expand Down Expand Up @@ -1052,6 +1053,31 @@ func (ex *connExecutor) commitSQLTransactionInternal(ctx context.Context) error
if err != nil || withNewVersion == nil {
return err
}

//If there is any descriptor has new version. We want to make sure there is
//only one version of the descriptor in all nodes. In schema changer jobs,
//`WaitForOneVersion` has been called for the descriptors included in jobs. So
//we just need to do this for descriptors not in jobs.
var descIDsInJobs catalog.DescriptorIDSet
for _, jobID := range *ex.extraTxnState.jobs {
job, err := ex.server.cfg.JobRegistry.LoadJob(ctx, jobID)
if err != nil {
return err
}
payload := job.Payload()
for _, descID := range payload.DescriptorIDs {
descIDsInJobs.Add(descID)
}
}
for _, idVersion := range withNewVersion {
if descIDsInJobs.Contains(idVersion.ID) {
continue
}
if _, err := WaitToUpdateLeases(ctx, ex.planner.LeaseMgr(), idVersion.ID); err != nil {
return err
}
}

ex.extraTxnState.descCollection.ReleaseLeases(ctx)
return nil
}
Expand Down

0 comments on commit 7e09c3c

Please sign in to comment.