Documentation
¶
Index ¶
- func ApplyGTIDPurged(ctx context.Context, db *sql.DB, dumpGTIDSet string, force bool) error
- func BuildReplicationSQL(info ReplicationInfo) (string, error)
- func StartReplication(ctx context.Context, db *sql.DB, info ReplicationInfo, opts StartOptions) error
- type FileLoad
- type Importer
- type LoadState
- type ReplicationInfo
- type StartOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyGTIDPurged ¶
ApplyGTIDPurged seeds the target server's GTID history from the dump's captured gtid_set so the target can replicate from the dump source with SOURCE_AUTO_POSITION=1.
Safety gates, in order:
- the dump GTID set must be well-formed (it is embedded in SQL);
- gtid_mode must be ON on the target;
- a running replication channel always aborts; a configured-but-stopped channel requires force;
- if the target's gtid_executed is non-empty, it must be a subset of the dump's set (anything extra means transactions the dump source never had — errant; use go-gtids to inspect). A subset still requires force, because clearing it takes RESET MASTER / RESET BINARY LOGS AND GTIDS, which destroys the target's binlog history.
The cheap path — empty gtid_executed, e.g. a fresh instance loaded with --skip-binlog — needs no reset and no force.
func BuildReplicationSQL ¶ added in v0.3.0
func BuildReplicationSQL(info ReplicationInfo) (string, error)
BuildReplicationSQL renders ready-to-run replication setup statements from the dump's recorded coordinates. Nothing is executed — the output is for the operator to review and run manually (or pipe into the mysql client).
When the dump carries a GTID set, the GTID AUTO_POSITION variant is emitted as the runnable block and file/position as a commented alternative; without a GTID set, file/position is the runnable block. The MySQL 5.7 CHANGE MASTER syntax is always included as a commented block.
func StartReplication ¶ added in v0.3.0
func StartReplication(ctx context.Context, db *sql.DB, info ReplicationInfo, opts StartOptions) error
StartReplication configures the target as a replica of the dump source and starts it, then waits for both threads to come up healthy.
Safety gates, matching ApplyGTIDPurged:
- a RUNNING replication channel always aborts;
- a configured-but-stopped channel requires force;
- in GTID mode, the target's gtid_executed must equal the dump's GTID set (seed it with --set-gtid-purged) — anything less re-fetches rows the load already inserted, anything more is errant.
Types ¶
type FileLoad ¶
type FileLoad struct {
Path string
IsSchema bool
IsPost bool // trigger/routine/event file — loaded serially after all data
}
FileLoad represents a single SQL file to load.
type Importer ¶
type Importer struct {
// contains filtered or unexported fields
}
Importer loads SQL files produced by go-dump into a MySQL server.
func (*Importer) ImportDirectory ¶
ImportDirectory loads all SQL files in dir matching pattern. Schema (definition) files are loaded serially first; data files run in parallel. Pass a non-nil LoadState to enable resume (skip already-loaded files).
func (*Importer) ImportFile ¶
ImportFile loads a single SQL file.
func (*Importer) SetSkipBinlog ¶
SetSkipBinlog makes every load connection run SET SQL_LOG_BIN=0, so the restore is written to the target only — not to its binlog, its replicas, or its GTID history. Requires SUPER or SYSTEM_VARIABLES_ADMIN on the target.
type LoadState ¶
type LoadState struct {
StartTime time.Time `json:"start_time"`
CompletedFiles []string `json:"completed_files"`
FileProgress map[string]int64 `json:"file_progress,omitempty"`
// contains filtered or unexported fields
}
LoadState persists which files have been successfully loaded, enabling --resume. Written atomically to <directory>/load-state.json after each successful file load. FileProgress tracks partially-loaded data files by the number of statements committed so far, so an interrupted load resumes mid-file instead of replaying rows that are already in the target.
func NewLoadState ¶
NewLoadState reads an existing load-state.json from dir, or returns a fresh state.
func (*LoadState) Mark ¶
Mark records name as complete and flushes the state file atomically. Any partial progress entry for name is dropped — completed files are tracked by CompletedFiles alone.
type ReplicationInfo ¶ added in v0.3.0
type ReplicationInfo struct {
SourceHost string
SourcePort int
ReplUser string // "<repl_user>" placeholder when empty
ReplPassword string // "<repl_password>" placeholder when empty
BinlogFile string
BinlogPos int
GTIDSet string // raw from metadata.json; sanitised and validated here
}
ReplicationInfo carries everything needed to point a replica seeded from a dump at the dump's source server. Coordinates come from the dump's metadata.json; host, port, user, and password may be overridden by flags when the replica reaches the source by a different address or account.
type StartOptions ¶ added in v0.3.0
type StartOptions struct {
Mode string // "auto", "gtid", or "file-pos"
SourceSSL bool // add SOURCE_SSL = 1 (encrypt the replication connection)
GetSourcePublicKey bool // add GET_SOURCE_PUBLIC_KEY = 1 (caching_sha2_password without TLS)
Force bool // allow acting on a configured-but-stopped channel
}
StartOptions controls StartReplication.