Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cmd/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +403 to +409
Copy link

Copilot AI Apr 2, 2026

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.

Copilot uses AI. Check for mistakes.
sd.ReplOptions = sandbox.SingleTemplates[globals.TmplReplicationOptions].Contents
if sd.ServerId == 0 {
sd.PortAsServerId = true
Expand All @@ -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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This version check and the subsequent template selection logic (lines 428-432) are identical to the block at lines 404-408. Consider refactoring this logic into a common variable or a helper function to improve maintainability and avoid duplication.

if isMySQL84 {
crashSafeTmpl = globals.TmplReplCrashSafeOptions84
}
sd.ReplCrashSafeOptions = sandbox.SingleTemplates[crashSafeTmpl].Contents
Comment on lines +427 to +433
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: this introduces another common.GreaterOrEqualVersion() call (deprecated) for 8.4 gating. Please use the non-deprecated helpers and handle the comparison error instead of discarding it.

Copilot uses AI. Check for mistakes.
} else {
common.Exitf(1, globals.ErrOptionRequiresVersion, globals.ReplCrashSafeLabel, common.IntSliceToDottedString(globals.MinimumCrashSafeVersion))
}
Expand Down
12 changes: 9 additions & 3 deletions globals/template_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “MySQL 8.4+ specific templates” section includes TmplInitSlaves84, but current selection logic uses it for >= 8.0.23. Please adjust the comment/grouping (or rename the template) so this list doesn’t misrepresent the version boundary.

Suggested change
// MySQL 8.4+ specific templates
// MySQL 8.0.23+ specific templates

Copilot uses AI. Check for mistakes.
TmplInitSlaves84 = "init_slaves_84"
TmplReplCrashSafeOptions84 = "repl_crash_safe_options84"
)
35 changes: 25 additions & 10 deletions sandbox/group_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This version check is redundant because it was already performed at line 293 (isMySQL84). Additionally, performing this check inside the loop is inefficient as sandboxDef.Version remains constant across iterations.

Suggested change
useMySQL84GroupOptions, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
useMySQL84GroupOptions := isMySQL84


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
}
Expand All @@ -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)
}

Expand Down Expand Up @@ -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},
},
}
Expand Down
16 changes: 16 additions & 0 deletions sandbox/group_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,29 @@ var (
//go:embed templates/group/init_nodes.gotxt
initNodesTemplate string

//go:embed templates/group/init_nodes84.gotxt
initNodes84Template string

//go:embed templates/group/check_nodes.gotxt
checkNodesTemplate string

//go:embed templates/group/group_repl_options.gotxt
groupReplOptionsTemplate string

//go:embed templates/group/group_repl_options84.gotxt
groupReplOptions84Template string

GroupTemplates = TemplateCollection{
globals.TmplInitNodes: TemplateDesc{
Description: "Initialize group replication after deployment",
Notes: "",
Contents: initNodesTemplate,
},
globals.TmplInitNodes84: TemplateDesc{
Description: "Initialize group replication after deployment (MySQL 8.4+ syntax)",
Notes: "Uses CHANGE REPLICATION SOURCE TO syntax",
Contents: initNodes84Template,
},
globals.TmplCheckNodes: TemplateDesc{
Description: "Checks the status of group replication",
Notes: "",
Expand All @@ -52,5 +63,10 @@ var (
Notes: "",
Contents: groupReplOptionsTemplate,
},
globals.TmplGroupReplOptions84: TemplateDesc{
Description: "replication options for Group replication node (MySQL 8.4+)",
Notes: "Excludes transaction_write_set_extraction removed in 8.4",
Contents: groupReplOptions84Template,
},
}
)
14 changes: 10 additions & 4 deletions sandbox/multi-source-replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ func CreateAllMastersReplication(sandboxDef SandboxDef, origin string, nodes int
}

sandboxDef.GtidOptions = SingleTemplates[globals.TmplGtidOptions57].Contents
skipCrashSafeOpts, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
if !skipCrashSafeOpts {
isMySQL84allMasters, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
if isMySQL84allMasters {
// relay-log-recovery is still valid; use 8.4-specific template (no deprecated master-info-repository)
sandboxDef.ReplCrashSafeOptions = SingleTemplates[globals.TmplReplCrashSafeOptions84].Contents
} else {
sandboxDef.ReplCrashSafeOptions = SingleTemplates[globals.TmplReplCrashSafeOptions].Contents
}
if sandboxDef.DirName == "" {
Expand Down Expand Up @@ -325,8 +328,11 @@ func CreateFanInReplication(sandboxDef SandboxDef, origin string, nodes int, mas
slaveList = globals.SlaveListValue
}
sandboxDef.GtidOptions = SingleTemplates[globals.TmplGtidOptions57].Contents
skipCrashSafe2, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
if !skipCrashSafe2 {
isMySQL84fanIn, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
if isMySQL84fanIn {
// relay-log-recovery is still valid; use 8.4-specific template (no deprecated master-info-repository)
sandboxDef.ReplCrashSafeOptions = SingleTemplates[globals.TmplReplCrashSafeOptions84].Contents
} else {
sandboxDef.ReplCrashSafeOptions = SingleTemplates[globals.TmplReplCrashSafeOptions].Contents
}
if sandboxDef.DirName == "" {
Expand Down
7 changes: 5 additions & 2 deletions sandbox/pxc_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This version check is performed inside a loop (starting at line 249), but sandboxDef.Version is constant. Moving this check outside the loop would be more efficient.

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
Expand Down
8 changes: 8 additions & 0 deletions sandbox/repl_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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 -A1

Repository: 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 MinimumChangeReplicationSourceVersion (8.0.23) instead of MinimumResetBinaryLogsVersion (8.4.0). This inconsistency conflicts with the "MySQL 8.4+ syntax" description and differs from the parallel TmplInitNodes84 template in sandbox/group_replication.go, which correctly uses MinimumResetBinaryLogsVersion for 8.4-specific features.

Update sandbox/replication.go (around line 508) to select TmplInitSlaves84 using MinimumResetBinaryLogsVersion instead, ensuring the template is only applied to MySQL versions that actually support its declared 8.4+ syntax.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sandbox/repl_templates.go` around lines 141 - 145, The template
globals.TmplInitSlaves84 is described as MySQL 8.4+ but the selection logic in
replication.go currently uses MinimumChangeReplicationSourceVersion (8.0.23);
update that selection to use MinimumResetBinaryLogsVersion (8.4.0) instead so
TmplInitSlaves84 is only applied for MySQL versions that support the 8.4+ syntax
(mirror the approach used for TmplInitNodes84 in sandbox/group_replication.go).

globals.TmplSemiSyncStart: TemplateDesc{
Description: "Starts semi synch replication ",
Notes: "",
Expand Down
19 changes: 16 additions & 3 deletions sandbox/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New code uses common.GreaterOrEqualVersion(), which is marked DEPRECATED (common/checks.go notes to use GreaterOrEqualVersionList + flavors or common.HasCapability). Consider switching this version gate to the non-deprecated helpers to avoid adding more deprecated call sites (and handle/propagate the comparison error instead of discarding it).

Copilot uses AI. Check for mistakes.
}
// 8.0.11
// isMinimumNativeAuthPlugin, err := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumNativeAuthPluginVersion)
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This version check is redundant as it was already performed at line 227 (useSourceAutoPosition). Reusing the existing variable improves readability and efficiency.

Suggested change
useNewSourceSyntax, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion)
useNewSourceSyntax := useSourceAutoPosition

if useNewSourceSyntax {
Comment on lines +506 to +509
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The init-slaves template selection uses MinimumChangeReplicationSourceVersion (8.0.23) to choose globals.TmplInitSlaves84. Either the template/name should reflect that it targets 8.0.23+ (not 8.4+), or the selection should use the 8.4 gate if the intent is truly “84+”. Leaving this as-is is confusing and makes future maintenance harder.

Suggested change
// 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 {

Copilot uses AI. Check for mistakes.
initSlavesTemplate = globals.TmplInitSlaves84
}

sb := ScriptBatch{
tc: ReplicationTemplates,
logger: logger,
Expand All @@ -515,7 +528,7 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in
{globals.ScriptMetadataAll, globals.TmplMetadataAll, true},
{useAllSlaves, globals.TmplUseAllSlaves, true},
{useAllMasters, globals.TmplUseAllMasters, true},
{initializeSlaves, globals.TmplInitSlaves, true},
{initializeSlaves, initSlavesTemplate, true},
{checkSlaves, globals.TmplCheckSlaves, true},
{masterAbbr, globals.TmplMaster, true},
{execAllSlaves, globals.TmplExecAllSlaves, true},
Expand Down
8 changes: 8 additions & 0 deletions sandbox/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ var (
//go:embed templates/single/repl_crash_safe_options.gotxt
replCrashSafeOptions string

//go:embed templates/single/repl_crash_safe_options84.gotxt
replCrashSafeOptions84 string

//go:embed templates/single/gtid_options_56.gotxt
gtidOptions56 string

Expand Down Expand Up @@ -218,6 +221,11 @@ var (
Notes: "",
Contents: replCrashSafeOptions,
},
globals.TmplReplCrashSafeOptions84: TemplateDesc{
Description: "Replication crash safe options for MySQL 8.4+",
Notes: "Excludes master-info-repository and relay-log-info-repository removed in 8.4",
Contents: replCrashSafeOptions84,
},
globals.TmplExposeDdTables: TemplateDesc{
Description: "Commands needed to enable data dictionary table usage",
Notes: "",
Expand Down
14 changes: 14 additions & 0 deletions sandbox/templates/group/group_repl_options84.gotxt
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}}
31 changes: 31 additions & 0 deletions sandbox/templates/group/init_nodes84.gotxt
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';"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Hardcoded replication credentials ignore configured values.

Line 13 always uses 'rsandbox' credentials, which can fail group replication init when RplUser/RplPassword are customized.

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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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';"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sandbox/templates/group/init_nodes84.gotxt` at line 13, The template
hardcodes replication credentials ('rsandbox') in the user_cmd string; update
the construction of user_cmd (the line building user_cmd that uses
.ChangeMasterTo, .MasterUserParam, .MasterPasswordParam, .ChangeMasterExtra and
FOR CHANNEL 'group_replication_recovery') to inject the configured replication
username and password fields (e.g. .RplUser and .RplPassword) instead of the
literal 'rsandbox', preserving existing quoting/escaping and placement of
.MasterUserParam/.MasterPasswordParam so customized RplUser/RplPassword values
are used during group replication init.

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
32 changes: 32 additions & 0 deletions sandbox/templates/replication/init_slaves_84.gotxt
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)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header says the script is for “MySQL 8.4+”, but in code it’s selected starting at 8.0.23 (MinimumChangeReplicationSourceVersion). Please update the comment (and/or the template name) so it matches the actual version range where it’s used.

Suggested change
# Uses MySQL 8.4+ replication syntax (CHANGE REPLICATION SOURCE TO)
# Uses MySQL 8.0.23+ replication syntax (CHANGE REPLICATION SOURCE TO)

Copilot uses AI. Check for mistakes.
SBDIR={{.SandboxDir}}
cd "$SBDIR"
# workaround for Bug#89959
$SBDIR/{{.MasterLabel}}/use -h {{.MasterIp}} -u {{.RplUser}} -p{{.RplPassword}} -e 'set @a=1'
if [ ! -f needs_initialization ]
then
# First run: root is running without password
export NOPASSWORD=1
fi

{{ range .Slaves }}
echo "initializing {{.SlaveLabel}} {{.Node}}"
echo '{{.ChangeMasterTo}} {{.MasterHostParam}}="{{.MasterIp}}", {{.MasterPortParam}}={{.MasterPort}}, {{.MasterUserParam}}="{{.RplUser}}", {{.MasterPasswordParam}}="{{.RplPassword}}" {{.MasterAutoPosition}} {{.ChangeMasterExtra}}' | $SBDIR/{{.NodeLabel}}{{.Node}}/use -u root
$SBDIR/{{.NodeLabel}}{{.Node}}/use -u root -e '{{.StartReplica}}'
{{end}}
if [ -x ./post_initialization ]
then
unset NOPASSWORD
./post_initialization > post_initialization.log 2>&1
exit_code=$?
if [ "$exit_code" == "0" ]
then
rm -f ./post_initialization
fi
fi
4 changes: 4 additions & 0 deletions sandbox/templates/single/repl_crash_safe_options84.gotxt
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
Loading