forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jobs,migration: introduce long running migration job
This commit introduces a job to run long-running migration. This empowers long-running migrations with leases, pausability, and cancelability. Fixes cockroachdb#58183 Release note: None
- Loading branch information
Showing
22 changed files
with
1,308 additions
and
476 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
Large diffs are not rendered by default.
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
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,16 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "migrationjob", | ||
srcs = ["migration_job.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/migration/migrationjob", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/jobs", | ||
"//pkg/jobs/jobspb", | ||
"//pkg/migration", | ||
"//pkg/migration/migrations", | ||
"//pkg/settings/cluster", | ||
"//pkg/sql", | ||
], | ||
) |
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 2018 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 migrationjob contains the jobs.Resumer implementation | ||
// used for long-running migrations. | ||
package migrationjob | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/jobs" | ||
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb" | ||
"github.com/cockroachdb/cockroach/pkg/migration" | ||
"github.com/cockroachdb/cockroach/pkg/migration/migrations" | ||
"github.com/cockroachdb/cockroach/pkg/settings/cluster" | ||
"github.com/cockroachdb/cockroach/pkg/sql" | ||
) | ||
|
||
func init() { | ||
jobs.RegisterConstructor(jobspb.TypeLongRunningMigration, func(job *jobs.Job, settings *cluster.Settings) jobs.Resumer { | ||
return &resumer{j: job} | ||
}) | ||
} | ||
|
||
type resumer struct { | ||
j *jobs.Job | ||
} | ||
|
||
var _ jobs.Resumer = (*resumer)(nil) | ||
|
||
func (r resumer) Resume(ctx context.Context, execCtxI interface{}) error { | ||
// TODO(ajwerner): add some check to see if we're done. | ||
execCtx := execCtxI.(sql.JobExecContext) | ||
pl := r.j.Payload() | ||
cv := *pl.GetLongRunningMigration().ClusterVersion | ||
m, ok := migrations.GetMigration(cv) | ||
if !ok { | ||
return nil | ||
} | ||
return m.(*migration.KVMigration).Run(ctx, cv, execCtx.MigrationCluster()) | ||
} | ||
|
||
// The long-running migration resumer has no reverting logic. | ||
func (r resumer) OnFailOrCancel(ctx context.Context, execCtx interface{}) error { | ||
return 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
Oops, something went wrong.