-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration: migrate into span configs infrastructure
We need a version gate before switching over to the span configs infrastructure by default (#73876, future commit). In a mixed-version cluster we need to wait for the host tenant to have fully populated system.span_configurations (read: reconciled) at least once before it's safe to using it as a view for all split/config decisions. clusterversion.EnsureSpanConfigReconciliation We also want to ensure that the view over all configs maintained per-store is at least as up-to-date as some full reconciliation timestamp. clusterversion.EnsureSpanConfigSubscription Without a version gate, it would be possible for a replica on a new-binary-server to apply static fallback configs (assuming no entries in `system.span_configurations`), in violation of explicit configs directly set by the user. Though unlikely, it's also possible for us to merge all ranges into a single one (with no entries in system.span_configurations, the infrastructure can erroneously conclude that there are zero split points). To get past all this, we author a three-step migration, two with attached migrations for each of the steps above (in order), and a final cluster version gate. clusterversion.EnableSpanConfigStore Release note: None
- Loading branch information
1 parent
5d7f4d3
commit aeb410a
Showing
15 changed files
with
503 additions
and
11 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,76 @@ | ||
// Copyright 2021 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 migrations | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/clusterversion" | ||
"github.com/cockroachdb/cockroach/pkg/jobs" | ||
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb" | ||
"github.com/cockroachdb/cockroach/pkg/migration" | ||
"github.com/cockroachdb/cockroach/pkg/server/serverpb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/cockroach/pkg/util/retry" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
func ensureSpanConfigReconciliation( | ||
ctx context.Context, _ clusterversion.ClusterVersion, d migration.TenantDeps, j *jobs.Job, | ||
) error { | ||
if !d.Codec.ForSystemTenant() { | ||
return nil | ||
} | ||
|
||
for r := retry.StartWithCtx(ctx, base.DefaultRetryOptions()); r.Next(); { | ||
row, err := d.InternalExecutor.QueryRowEx(ctx, "get-spanconfig-progress", nil, | ||
sessiondata.NodeUserSessionDataOverride, | ||
`SELECT progress FROM system.jobs WHERE id = (SELECT job_id FROM [SHOW AUTOMATIC JOBS] WHERE job_type = 'AUTO SPAN CONFIG RECONCILIATION')`) | ||
if err != nil { | ||
return err | ||
} | ||
if row == nil { | ||
log.Warningf(ctx, "reconciliation job not found") | ||
continue | ||
} | ||
progress, err := jobs.UnmarshalProgress(row[0]) | ||
if err != nil { | ||
return err | ||
} | ||
sp, ok := progress.GetDetails().(*jobspb.Progress_AutoSpanConfigReconciliation) | ||
if !ok { | ||
log.Fatal(ctx, "unexpected job progress type") | ||
} | ||
if sp.AutoSpanConfigReconciliation.Checkpoint.IsEmpty() { | ||
log.Warningf(ctx, "waiting for span config reconciliation...") | ||
continue | ||
} | ||
|
||
return nil | ||
} | ||
|
||
return errors.Newf("unable to reconcile span configs") | ||
} | ||
|
||
func ensureSpanConfigSubscription( | ||
ctx context.Context, _ clusterversion.ClusterVersion, deps migration.SystemDeps, _ *jobs.Job, | ||
) error { | ||
return deps.Cluster.UntilClusterStable(ctx, func() error { | ||
return deps.Cluster.ForEveryNode(ctx, "ensure-span-config-subscription", | ||
func(ctx context.Context, client serverpb.MigrationClient) error { | ||
req := &serverpb.WaitForSpanConfigSubscriptionRequest{} | ||
_, err := client.WaitForSpanConfigSubscription(ctx, req) | ||
return err | ||
}) | ||
}) | ||
} |
Oops, something went wrong.