-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add MySQL 8.4-specific replication and group replication templates (#60) #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -400,7 +400,13 @@ func fillSandboxDefinition(cmd *cobra.Command, args []string, usingImport bool) | |
| common.ErrCheckExitf(err, 1, globals.ErrWhileComparingVersions) | ||
| if isMinimumGtid { | ||
| sd.GtidOptions = sandbox.SingleTemplates[templateName].Contents | ||
| sd.ReplCrashSafeOptions = sandbox.SingleTemplates[globals.TmplReplCrashSafeOptions].Contents | ||
| // Use 8.4+ crash-safe options template (no deprecated master-info-repository) | ||
| crashSafeTmpl := globals.TmplReplCrashSafeOptions | ||
| isMySQL84, _ := common.GreaterOrEqualVersion(sd.Version, globals.MinimumResetBinaryLogsVersion) | ||
| if isMySQL84 { | ||
| crashSafeTmpl = globals.TmplReplCrashSafeOptions84 | ||
| } | ||
| sd.ReplCrashSafeOptions = sandbox.SingleTemplates[crashSafeTmpl].Contents | ||
| sd.ReplOptions = sandbox.SingleTemplates[globals.TmplReplicationOptions].Contents | ||
| if sd.ServerId == 0 { | ||
| sd.PortAsServerId = true | ||
|
|
@@ -418,7 +424,13 @@ func fillSandboxDefinition(cmd *cobra.Command, args []string, usingImport bool) | |
| isMinimumCrashSafe, err := common.HasCapability(sd.Flavor, common.CrashSafe, sd.Version) | ||
| common.ErrCheckExitf(err, 1, globals.ErrWhileComparingVersions) | ||
| if isMinimumCrashSafe { | ||
| sd.ReplCrashSafeOptions = sandbox.SingleTemplates[globals.TmplReplCrashSafeOptions].Contents | ||
| // Use 8.4+ crash-safe options template (no deprecated master-info-repository) | ||
| crashSafeTmpl := globals.TmplReplCrashSafeOptions | ||
| isMySQL84, _ := common.GreaterOrEqualVersion(sd.Version, globals.MinimumResetBinaryLogsVersion) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if isMySQL84 { | ||
| crashSafeTmpl = globals.TmplReplCrashSafeOptions84 | ||
| } | ||
| sd.ReplCrashSafeOptions = sandbox.SingleTemplates[crashSafeTmpl].Contents | ||
|
Comment on lines
+427
to
+433
|
||
| } else { | ||
| common.Exitf(1, globals.ErrOptionRequiresVersion, globals.ReplCrashSafeLabel, common.IntSliceToDottedString(globals.MinimumCrashSafeVersion)) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -165,7 +165,13 @@ const ( | |||||
| TmplTidbMyCnf = "tidb_my_cnf" | ||||||
|
|
||||||
| // group | ||||||
| TmplInitNodes = "init_nodes" | ||||||
| TmplCheckNodes = "check_nodes" | ||||||
| TmplGroupReplOptions = "group_repl_options" | ||||||
| TmplInitNodes = "init_nodes" | ||||||
| TmplCheckNodes = "check_nodes" | ||||||
| TmplGroupReplOptions = "group_repl_options" | ||||||
| TmplInitNodes84 = "init_nodes84" | ||||||
| TmplGroupReplOptions84 = "group_repl_options84" | ||||||
|
|
||||||
| // MySQL 8.4+ specific templates | ||||||
|
||||||
| // MySQL 8.4+ specific templates | |
| // MySQL 8.0.23+ specific templates |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -288,6 +288,13 @@ func CreateGroupReplication(sandboxDef SandboxDef, origin string, nodes int, mas | |||||
| sbItem.LogDirectory = common.DirName(sandboxDef.LogFileName) | ||||||
| } | ||||||
|
|
||||||
| // Select version-appropriate templates for group replication init | ||||||
| initNodesTmpl := globals.TmplInitNodes | ||||||
| isMySQL84, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion) | ||||||
| if isMySQL84 { | ||||||
| initNodesTmpl = globals.TmplInitNodes84 | ||||||
| } | ||||||
|
|
||||||
| for i := 1; i <= nodes; i++ { | ||||||
| groupPort := baseGroupPort + i | ||||||
| sandboxDef.Port = basePort + i | ||||||
|
|
@@ -338,18 +345,24 @@ func CreateGroupReplication(sandboxDef SandboxDef, origin string, nodes int, mas | |||||
| // Version-aware options for group replication | ||||||
| useReplicaUpdates, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumShowReplicaStatusVersion) | ||||||
| useNoWriteSetExtraction, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumNoWriteSetExtractionVersion) | ||||||
| // Use 8.4+ group replication options template when applicable | ||||||
| useMySQL84GroupOptions, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This version check is redundant because it was already performed at line 293 (
Suggested change
|
||||||
|
|
||||||
| replicationData := common.StringMap{ | ||||||
| "BasePort": basePortText, | ||||||
| "GroupSeeds": connectionString, | ||||||
| "LocalAddresses": fmt.Sprintf("%s:%d", masterIp, groupPort), | ||||||
| "PrimaryMode": singlePrimaryMode, | ||||||
| "UseReplicaUpdates": useReplicaUpdates, | ||||||
| "SkipWriteSetExtraction": useNoWriteSetExtraction, | ||||||
| "BasePort": basePortText, | ||||||
| "GroupSeeds": connectionString, | ||||||
| "LocalAddresses": fmt.Sprintf("%s:%d", masterIp, groupPort), | ||||||
| "PrimaryMode": singlePrimaryMode, | ||||||
| "UseReplicaUpdates": useReplicaUpdates, | ||||||
| "SkipWriteSetExtraction": useNoWriteSetExtraction, | ||||||
| } | ||||||
|
|
||||||
| groupReplOptionsTmpl := globals.TmplGroupReplOptions | ||||||
| if useMySQL84GroupOptions { | ||||||
| groupReplOptionsTmpl = globals.TmplGroupReplOptions84 | ||||||
| } | ||||||
| replOptionsText, err := common.SafeTemplateFill("group_replication", | ||||||
| GroupTemplates[globals.TmplGroupReplOptions].Contents, replicationData) | ||||||
| GroupTemplates[groupReplOptionsTmpl].Contents, replicationData) | ||||||
| if err != nil { | ||||||
| return err | ||||||
| } | ||||||
|
|
@@ -360,8 +373,10 @@ func CreateGroupReplication(sandboxDef SandboxDef, origin string, nodes int, mas | |||||
|
|
||||||
| sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplGtidOptions57].Contents) | ||||||
| // master-info-repository and relay-log-info-repository removed in 8.4+ | ||||||
| skipCrashSafeOpts, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion) | ||||||
| if !skipCrashSafeOpts { | ||||||
| if useMySQL84GroupOptions { | ||||||
| // relay-log-recovery is still valid; use the 8.4-specific template | ||||||
| sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplReplCrashSafeOptions84].Contents) | ||||||
| } else { | ||||||
| sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplReplCrashSafeOptions].Contents) | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -487,7 +502,7 @@ func CreateGroupReplication(sandboxDef SandboxDef, origin string, nodes int, mas | |||||
| data: data, | ||||||
| sandboxDir: sandboxDef.SandboxDir, | ||||||
| scripts: []ScriptDef{ | ||||||
| {globals.ScriptInitializeNodes, globals.TmplInitNodes, true}, | ||||||
| {globals.ScriptInitializeNodes, initNodesTmpl, true}, | ||||||
| {globals.ScriptCheckNodes, globals.TmplCheckNodes, true}, | ||||||
| }, | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -328,8 +328,11 @@ func CreatePxcReplication(sandboxDef SandboxDef, origin string, nodes int, maste | |
|
|
||
| sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplGtidOptions57].Contents) | ||
| // master-info-repository and relay-log-info-repository removed in 8.4+ | ||
| skipCrashSafeOpts, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion) | ||
| if !skipCrashSafeOpts { | ||
| isMySQL84pxc, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if isMySQL84pxc { | ||
| // relay-log-recovery is still valid; use 8.4-specific template (no deprecated master-info-repository) | ||
| sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplReplCrashSafeOptions84].Contents) | ||
| } else { | ||
| sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplReplCrashSafeOptions].Contents) | ||
| } | ||
| // 8.0.11 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,9 @@ var ( | |
| //go:embed templates/replication/init_slaves.gotxt | ||
| initSlavesTemplate string | ||
|
|
||
| //go:embed templates/replication/init_slaves_84.gotxt | ||
| initSlaves84Template string | ||
|
|
||
| //go:embed templates/replication/semi_sync_start.gotxt | ||
| semiSyncStartTemplate string | ||
|
|
||
|
|
@@ -135,6 +138,11 @@ var ( | |
| Notes: "Can also be run after calling './clear_all'", | ||
| Contents: initSlavesTemplate, | ||
| }, | ||
| globals.TmplInitSlaves84: TemplateDesc{ | ||
| Description: "Initialize slaves after deployment (MySQL 8.4+ syntax)", | ||
| Notes: "Uses CHANGE REPLICATION SOURCE TO and SOURCE_AUTO_POSITION", | ||
| Contents: initSlaves84Template, | ||
| }, | ||
|
Comment on lines
+141
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify version constant values and usage consistency
echo "=== Version constant definitions ==="
rg -n 'Minimum(ChangeReplicationSource|ResetBinaryLogs)Version' --type=go -A1
echo ""
echo "=== Usage in template selection ==="
rg -n 'TmplInitSlaves84|TmplInitNodes84' --type=go -B3 -A1Repository: ProxySQL/dbdeployer Length of output: 4849 Fix version threshold for template selection to match 8.4+ syntax requirement. The template is named and described for MySQL 8.4+ syntax, but is selected using Update 🤖 Prompt for AI Agents |
||
| globals.TmplSemiSyncStart: TemplateDesc{ | ||
| Description: "Starts semi synch replication ", | ||
| Notes: "", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -224,8 +224,14 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in | |||||||||||||||||||
| changeMasterExtra := "" | ||||||||||||||||||||
| masterAutoPosition := "" | ||||||||||||||||||||
| if sandboxDef.GtidOptions != "" { | ||||||||||||||||||||
| masterAutoPosition += ", MASTER_AUTO_POSITION=1" | ||||||||||||||||||||
| logger.Printf("Adding MASTER_AUTO_POSITION to slaves setup\n") | ||||||||||||||||||||
| useSourceAutoPosition, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion) | ||||||||||||||||||||
| if useSourceAutoPosition { | ||||||||||||||||||||
| masterAutoPosition = ", SOURCE_AUTO_POSITION=1" | ||||||||||||||||||||
| logger.Printf("Adding SOURCE_AUTO_POSITION to slaves setup\n") | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| masterAutoPosition = ", MASTER_AUTO_POSITION=1" | ||||||||||||||||||||
| logger.Printf("Adding MASTER_AUTO_POSITION to slaves setup\n") | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+227
to
+234
|
||||||||||||||||||||
| } | ||||||||||||||||||||
| // 8.0.11 | ||||||||||||||||||||
| // isMinimumNativeAuthPlugin, err := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumNativeAuthPluginVersion) | ||||||||||||||||||||
|
|
@@ -497,6 +503,13 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in | |||||||||||||||||||
| execAllSlaves := "exec_all_" + slavePlural | ||||||||||||||||||||
| execAllMasters := "exec_all_" + masterPlural | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Select the appropriate init_slaves template based on MySQL version | ||||||||||||||||||||
| initSlavesTemplate := globals.TmplInitSlaves | ||||||||||||||||||||
| useNewSourceSyntax, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion) | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This version check is redundant as it was already performed at line 227 (
Suggested change
|
||||||||||||||||||||
| if useNewSourceSyntax { | ||||||||||||||||||||
|
Comment on lines
+506
to
+509
|
||||||||||||||||||||
| // Select the appropriate init_slaves template based on MySQL version | |
| initSlavesTemplate := globals.TmplInitSlaves | |
| useNewSourceSyntax, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion) | |
| if useNewSourceSyntax { | |
| // Select the appropriate init_slaves template based on MySQL version. | |
| // TmplInitSlaves84 is intended for MySQL 8.4+; earlier versions use the legacy template. | |
| initSlavesTemplate := globals.TmplInitSlaves | |
| useInitSlaves84, _ := common.GreaterOrEqualVersion(sandboxDef.Version, "8.4.0") | |
| if useInitSlaves84 { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
|
|
||
| # After customization, these options are added to my.sandbox.cnf | ||
| # MySQL 8.4+ group replication options (transaction_write_set_extraction removed) | ||
| binlog_checksum=NONE | ||
| log_replica_updates=ON | ||
| plugin-load-add=group_replication.so | ||
| group_replication=FORCE_PLUS_PERMANENT | ||
| group_replication_start_on_boot=OFF | ||
| group_replication_bootstrap_group=OFF | ||
| report-host=127.0.0.1 | ||
| loose-group_replication_group_name="{{.BasePort}}-bbbb-cccc-dddd-eeeeeeeeeeee" | ||
| loose-group-replication-local-address={{.LocalAddresses}} | ||
| loose-group-replication-group-seeds={{.GroupSeeds}} | ||
| loose-group-replication-single-primary-mode={{.PrimaryMode}} |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||
| #!{{.ShellPath}} | ||||||
| {{.Copyright}} | ||||||
| # Generated by dbdeployer {{.AppVersion}} using {{.TemplateName}} on {{.DateTime}} | ||||||
| # Uses MySQL 8.4+ replication syntax (CHANGE REPLICATION SOURCE TO) | ||||||
| multi_sb={{.SandboxDir}} | ||||||
| # workaround for Bug#89959 | ||||||
| {{range .Nodes}} | ||||||
| {{.SandboxDir}}/{{.NodeLabel}}{{.Node}}/use -h {{.MasterIp}} -u {{.RplUser}} -p{{.RplPassword}} -e 'set @a=1' | ||||||
| {{end}} | ||||||
| [ -z "$SLEEP_TIME" ] && SLEEP_TIME=1 | ||||||
| {{range .Nodes}} | ||||||
| user_cmd='{{.ResetMasterCmd}};' | ||||||
| user_cmd="$user_cmd {{.ChangeMasterTo}} {{.MasterUserParam}}='rsandbox', {{.MasterPasswordParam}}='rsandbox' {{.ChangeMasterExtra}} FOR CHANNEL 'group_replication_recovery';" | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hardcoded replication credentials ignore configured values. Line 13 always uses Suggested fix- user_cmd="$user_cmd {{.ChangeMasterTo}} {{.MasterUserParam}}='rsandbox', {{.MasterPasswordParam}}='rsandbox' {{.ChangeMasterExtra}} FOR CHANNEL 'group_replication_recovery';"
+ user_cmd="$user_cmd {{.ChangeMasterTo}} {{.MasterUserParam}}='{{.RplUser}}', {{.MasterPasswordParam}}='{{.RplPassword}}' {{.ChangeMasterExtra}} FOR CHANNEL 'group_replication_recovery';"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| echo "# Node {{.Node}} # $user_cmd" | ||||||
| $multi_sb/{{.NodeLabel}}{{.Node}}/use -u root -e "$user_cmd" | ||||||
| {{end}} | ||||||
| echo "" | ||||||
|
|
||||||
| BEFORE_START_CMD="SET GLOBAL group_replication_bootstrap_group=ON;" | ||||||
| START_CMD="START GROUP_REPLICATION;" | ||||||
| AFTER_START_CMD="SET GLOBAL group_replication_bootstrap_group=OFF;" | ||||||
| echo "# Node 1 # $BEFORE_START_CMD" | ||||||
| $multi_sb/n1 -e "$BEFORE_START_CMD" | ||||||
| {{ range .Nodes}} | ||||||
| echo "# Node {{.Node}} # $START_CMD" | ||||||
| $multi_sb/n{{.Node}} -e "$START_CMD" | ||||||
| sleep $SLEEP_TIME | ||||||
| {{end}} | ||||||
| echo "# Node 1 # $AFTER_START_CMD" | ||||||
| $multi_sb/n1 -e "$AFTER_START_CMD" | ||||||
| $multi_sb/check_nodes | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||
| #!{{.ShellPath}} | ||||||
| {{.Copyright}} | ||||||
| # Generated by dbdeployer {{.AppVersion}} using {{.TemplateName}} on {{.DateTime}} | ||||||
|
|
||||||
| # Don't use directly. | ||||||
| # This script is called by 'start_all' when needed | ||||||
| # Uses MySQL 8.4+ replication syntax (CHANGE REPLICATION SOURCE TO) | ||||||
|
||||||
| # Uses MySQL 8.4+ replication syntax (CHANGE REPLICATION SOURCE TO) | |
| # Uses MySQL 8.0.23+ replication syntax (CHANGE REPLICATION SOURCE TO) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
|
|
||
| # replication crash-safe options for MySQL 8.4+ | ||
| # master-info-repository and relay-log-info-repository are removed in 8.4 | ||
| relay-log-recovery=on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a new common.GreaterOrEqualVersion() call to gate 8.4-specific behavior. Since GreaterOrEqualVersion is deprecated, prefer common.HasCapability (if an appropriate capability exists) or VersionToList + GreaterOrEqualVersionList, and avoid ignoring the returned error.