Documentation
¶
Overview ¶
Package migration contains the logic for running online schema changes.
Index ¶
- type CutOver
- type Migration
- type Runner
- func (r *Runner) Cancel()
- func (r *Runner) Close() error
- func (r *Runner) DumpCheckpoint(ctx context.Context) error
- func (r *Runner) Progress() status.Progress
- func (r *Runner) Result() status.WorkflowResult
- func (r *Runner) Run(ctx context.Context) (retErr error)
- func (r *Runner) SetLogger(logger *slog.Logger)
- func (r *Runner) SetMetricsSink(sink metrics.Sink)
- func (r *Runner) Status() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CutOver ¶
type CutOver struct {
// contains filtered or unexported fields
}
func NewCutOver ¶
func NewCutOver(db *sql.DB, config []*cutoverConfig, feed change.Source, dbConfig *dbconn.DBConfig, logger *slog.Logger) (*CutOver, error)
NewCutOver contains the logic to perform the final cut over. It can cutover multiple tables at once based on config. A replication feed which is used to ensure consistency before the cut over.
type Migration ¶
type Migration struct {
Host string `name:"host" help:"Hostname" optional:""`
Username string `name:"username" help:"User" optional:""`
Password *string `name:"password" help:"Password" optional:""`
Database string `name:"database" help:"Database" optional:""`
ConfFile string `name:"conf" help:"MySQL conf file" optional:"" type:"existingfile"`
Threads int `` /* 158-byte string literal not displayed */
WriteThreads int `` /* 150-byte string literal not displayed */
// MaxConnections is the size of the main connection pool, set verbatim and
// never recomputed (see the MaxOpenConnections assignment in Runner.Run).
//
// The connections it spends are the server's max_connections, shared with
// the production workload, so this is spirit's claim on someone else's
// budget rather than a description of what spirit could use. Ask for more
// than the server can spare and the copy does not slow down, it dies on
// `Error 1040: Too many connections`.
//
// The thread ceilings bound how far the copier scales its own workers and
// can exceed this. When they do, the workers contend for connections instead
// of each being guaranteed one, which costs throughput and nothing else.
//
// Zero means "use the default" (normalizeOptions fills it in), matching
// Threads and WriteThreads. Negative is rejected by Validate, as is any
// value too small for the migration to finish on; see minPoolSize.
MaxConnections int `` /* 203-byte string literal not displayed */
// EnableExperimentalAutoscaling turns on dynamic thread scaling driven by
// throttler feedback. When it engages (an Aurora target with at least
// autoscale.MinVCPUs) it takes over both thread counts: Threads and
// WriteThreads are ignored, and each pool's starting size and ceiling are
// derived from the instance instead — see the override in
// setupCopierCheckerAndReplClient and autoscale.ReadBounds. See issue #831.
EnableExperimentalAutoscaling bool `` /* 257-byte string literal not displayed */
// TargetChunkSize is the in-memory byte budget the copier sizes each copy
// chunk against (the memory signal; see table.DefaultTargetChunkBytes and
// pkg/table/README.md). A zero value means "use the default"
// (normalizeOptions fills it in), so callers that construct Migration
// programmatically don't have to set it.
// The Kong default below must stay equal to table.DefaultTargetChunkBytes.
TargetChunkSize uint64 `name:"target-chunk-size" help:"In-memory byte budget per copy chunk (in bytes)" optional:"" default:"16777216"`
ReplicaDSN string `` /* 157-byte string literal not displayed */
ReplicaMaxLag time.Duration `` /* 299-byte string literal not displayed */
LockWaitTimeout time.Duration `name:"lock-wait-timeout" help:"The DDL lock_wait_timeout required for checksum and cutover" optional:"" default:"30s"`
SkipDropAfterCutover bool `name:"skip-drop-after-cutover" help:"Keep old table after completing cutover" optional:"" default:"false"`
DeferCutOver bool `name:"defer-cutover" help:"Defer cutover (and checksum) until sentinel table is dropped" optional:"" default:"false"`
Statement string `name:"statement" help:"The SQL statement to run" required:""`
// TLS Configuration
TLSMode string `` /* 142-byte string literal not displayed */
TLSCertificatePath string `name:"tls-ca" help:"Path to custom TLS CA certificate file" optional:""`
CheckpointMaxAge time.Duration `name:"checkpoint-max-age" help:"Maximum age of a checkpoint before refusing to resume from it" optional:"" default:"168h"`
ChecksumYieldTimeout time.Duration `` /* 203-byte string literal not displayed */
// MaxCommitLatency throttles when observed commit latency exceeds this
// threshold. Currently auto-enabled only on Aurora (auto-detected); the
// default 100ms is intentionally a high upper bound to only cut the most
// extreme tail latencies. See issue #468.
MaxCommitLatency time.Duration `` /* 160-byte string literal not displayed */
// Hidden options for now (supports more obscure cash/sq usecases)
InterpolateParams bool `name:"interpolate-params" help:"Enable interpolate params for DSN" optional:"" default:"false" hidden:""`
// Used for tests so we can concurrently execute without issues even though
// the sentinel name is shared. Basically it will be true here, but false
// in the tests unless we set it explicitly true.
RespectSentinel bool `name:"respect-sentinel" help:"Look for sentinel table to exist and block if it does" optional:"" default:"true" hidden:""`
// contains filtered or unexported fields
}
func (*Migration) Validate ¶ added in v0.11.0
Validate is called by Kong after parsing to reject invalid flag values. Zero values mean "use the default" (normalizeOptions fills them in), so they are not rejected here; only explicitly-negative or otherwise invalid values are caught.
The cross-flag check on MaxConnections is the exception, and it is here because it has nowhere else to be: the pool is set to that number verbatim and never recomputed, so a number too small to work is a migration that stalls somewhere in the middle rather than one that fails at startup.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
func (*Runner) DumpCheckpoint ¶
DumpCheckpoint is called approximately every minute. It writes the current state of the migration to the checkpoint table, which can be used in recovery. Previously resuming from checkpoint would always restart at the copier, but it can now also resume at the checksum phase.
func (*Runner) Result ¶ added in v0.17.0
func (r *Runner) Result() status.WorkflowResult
Result returns correctness evidence retained from the most recent Run invocation. It is intentionally separate from phase metrics.
func (*Runner) SetMetricsSink ¶
func (*Runner) Status ¶
Status returns the periodic report on the whole migration: a header line plus one indented row per subsystem (see status.Block). It deliberately absorbs what used to be separate periodic lines from the change feed (flushes, rotations) and the checkpoint dumper, which each ran on their own interval — see github.com/block/spirit/issues/329.