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
3 changes: 3 additions & 0 deletions globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ var (
MinimumRootAuthVersion = NumericVersion{10, 4, 3}
MinimumAdminAddressVersion = NumericVersion{8, 0, 14}
MinimumMySQLShellEmbed = NumericVersion{8, 0, 4}
MinimumShowReplicaStatusVersion = NumericVersion{8, 0, 22}
MinimumChangeReplicationSourceVersion = NumericVersion{8, 0, 23}
MinimumShowBinaryLogStatusVersion = NumericVersion{8, 2, 0}
)

const (
Expand Down
24 changes: 24 additions & 0 deletions sandbox/multi-source-replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ func CreateAllMastersReplication(sandboxDef SandboxDef, origin string, nodes int
data["RplPassword"] = sandboxDef.RplPassword
data["NodeLabel"] = defaults.Defaults().NodePrefix
data["ChangeMasterExtra"] = setChangeMasterProperties("", sandboxDef.ChangeMasterOptions, logger)
replCmds := replicationCommands(sandboxDef.Version)
data["ShowMasterStatus"] = replCmds["ShowMasterStatus"]
data["ShowSlaveStatus"] = replCmds["ShowSlaveStatus"]
data["ChangeMasterTo"] = replCmds["ChangeMasterTo"]
data["StartReplica"] = replCmds["StartReplica"]
data["StopReplica"] = replCmds["StopReplica"]
data["ResetReplica"] = replCmds["ResetReplica"]
data["MasterPosWaitFunc"] = replCmds["MasterPosWaitFunc"]
data["MasterHostParam"] = replCmds["MasterHostParam"]
data["MasterPortParam"] = replCmds["MasterPortParam"]
data["MasterUserParam"] = replCmds["MasterUserParam"]
data["MasterPasswordParam"] = replCmds["MasterPasswordParam"]
Comment on lines +185 to +196
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 block of code populates replication commands into the data map. It is repeated in CreateFanInReplication and with variations in sandbox/replication.go. To improve maintainability and reduce duplication, you could use a loop. This would also make it easier to add new commands in the future.

Suggested change
replCmds := replicationCommands(sandboxDef.Version)
data["ShowMasterStatus"] = replCmds["ShowMasterStatus"]
data["ShowSlaveStatus"] = replCmds["ShowSlaveStatus"]
data["ChangeMasterTo"] = replCmds["ChangeMasterTo"]
data["StartReplica"] = replCmds["StartReplica"]
data["StopReplica"] = replCmds["StopReplica"]
data["ResetReplica"] = replCmds["ResetReplica"]
data["MasterPosWaitFunc"] = replCmds["MasterPosWaitFunc"]
data["MasterHostParam"] = replCmds["MasterHostParam"]
data["MasterPortParam"] = replCmds["MasterPortParam"]
data["MasterUserParam"] = replCmds["MasterUserParam"]
data["MasterPasswordParam"] = replCmds["MasterPasswordParam"]
for k, v := range replicationCommands(sandboxDef.Version) {
data[k] = v
}

logger.Printf("Writing master and slave scripts in %s\n", sandboxDef.SandboxDir)
for _, node := range slaveList {
data["Node"] = node
Expand Down Expand Up @@ -407,6 +419,18 @@ func CreateFanInReplication(sandboxDef SandboxDef, origin string, nodes int, mas
data["NodeLabel"] = defaults.Defaults().NodePrefix
data["ChangeMasterExtra"] = setChangeMasterProperties("", sandboxDef.ChangeMasterOptions, logger)
data["MasterIp"] = masterIp
replCmds := replicationCommands(sandboxDef.Version)
data["ShowMasterStatus"] = replCmds["ShowMasterStatus"]
data["ShowSlaveStatus"] = replCmds["ShowSlaveStatus"]
data["ChangeMasterTo"] = replCmds["ChangeMasterTo"]
data["StartReplica"] = replCmds["StartReplica"]
data["StopReplica"] = replCmds["StopReplica"]
data["ResetReplica"] = replCmds["ResetReplica"]
data["MasterPosWaitFunc"] = replCmds["MasterPosWaitFunc"]
data["MasterHostParam"] = replCmds["MasterHostParam"]
data["MasterPortParam"] = replCmds["MasterPortParam"]
data["MasterUserParam"] = replCmds["MasterUserParam"]
data["MasterPasswordParam"] = replCmds["MasterPasswordParam"]
Comment on lines +422 to +433
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

Similar to the CreateAllMastersReplication function, this block can be simplified using a loop to reduce code duplication and improve maintainability.

Suggested change
replCmds := replicationCommands(sandboxDef.Version)
data["ShowMasterStatus"] = replCmds["ShowMasterStatus"]
data["ShowSlaveStatus"] = replCmds["ShowSlaveStatus"]
data["ChangeMasterTo"] = replCmds["ChangeMasterTo"]
data["StartReplica"] = replCmds["StartReplica"]
data["StopReplica"] = replCmds["StopReplica"]
data["ResetReplica"] = replCmds["ResetReplica"]
data["MasterPosWaitFunc"] = replCmds["MasterPosWaitFunc"]
data["MasterHostParam"] = replCmds["MasterHostParam"]
data["MasterPortParam"] = replCmds["MasterPortParam"]
data["MasterUserParam"] = replCmds["MasterUserParam"]
data["MasterPasswordParam"] = replCmds["MasterPasswordParam"]
for k, v := range replicationCommands(sandboxDef.Version) {
data[k] = v
}

logger.Printf("Writing master and slave scripts in %s\n", sandboxDef.SandboxDir)
for _, slave := range slist {
data["Node"] = slave
Expand Down
81 changes: 79 additions & 2 deletions sandbox/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,47 @@ import (
"github.com/pkg/errors"
)

func replicationCommands(version string) map[string]string {
cmds := map[string]string{
"ShowMasterStatus": "show master status",
"ShowSlaveStatus": "show slave status",
"ChangeMasterTo": "CHANGE MASTER TO",
"StartReplica": "START SLAVE",
"StopReplica": "STOP SLAVE",
"ResetReplica": "RESET SLAVE",
"MasterPosWaitFunc": "master_pos_wait",
"MasterHostParam": "master_host",
"MasterPortParam": "master_port",
"MasterUserParam": "master_user",
"MasterPasswordParam": "master_password",
}

useReplicaStatus, _ := common.GreaterOrEqualVersion(version, globals.MinimumShowReplicaStatusVersion)
if useReplicaStatus {
cmds["ShowSlaveStatus"] = "show replica status"
cmds["StartReplica"] = "START REPLICA"
cmds["StopReplica"] = "STOP REPLICA"
cmds["ResetReplica"] = "RESET REPLICA"
cmds["MasterPosWaitFunc"] = "source_pos_wait"
}

useChangeSource, _ := common.GreaterOrEqualVersion(version, globals.MinimumChangeReplicationSourceVersion)
if useChangeSource {
cmds["ChangeMasterTo"] = "CHANGE REPLICATION SOURCE TO"
cmds["MasterHostParam"] = "source_host"
cmds["MasterPortParam"] = "source_port"
cmds["MasterUserParam"] = "source_user"
cmds["MasterPasswordParam"] = "source_password"
}

useBinaryLogStatus, _ := common.GreaterOrEqualVersion(version, globals.MinimumShowBinaryLogStatusVersion)
if useBinaryLogStatus {
cmds["ShowMasterStatus"] = "show binary log status"
}

Comment on lines +47 to +69
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

common.GreaterOrEqualVersion is marked DEPRECATED in common/checks.go and it returns errors for non-x.y.z version strings. Here the error is ignored (_, _ := ...), so any unexpected version format silently falls back to old replication syntax (breaking the MySQL 8.4+/9.x compatibility this PR targets). Consider switching to the capability system (common.HasCapability) by adding new feature flags, or parse once with common.VersionToList and compare with GreaterOrEqualVersionList, and handle/log parse errors explicitly.

Suggested change
useReplicaStatus, _ := common.GreaterOrEqualVersion(version, globals.MinimumShowReplicaStatusVersion)
if useReplicaStatus {
cmds["ShowSlaveStatus"] = "show replica status"
cmds["StartReplica"] = "START REPLICA"
cmds["StopReplica"] = "STOP REPLICA"
cmds["ResetReplica"] = "RESET REPLICA"
cmds["MasterPosWaitFunc"] = "source_pos_wait"
}
useChangeSource, _ := common.GreaterOrEqualVersion(version, globals.MinimumChangeReplicationSourceVersion)
if useChangeSource {
cmds["ChangeMasterTo"] = "CHANGE REPLICATION SOURCE TO"
cmds["MasterHostParam"] = "source_host"
cmds["MasterPortParam"] = "source_port"
cmds["MasterUserParam"] = "source_user"
cmds["MasterPasswordParam"] = "source_password"
}
useBinaryLogStatus, _ := common.GreaterOrEqualVersion(version, globals.MinimumShowBinaryLogStatusVersion)
if useBinaryLogStatus {
cmds["ShowMasterStatus"] = "show binary log status"
}
versionList, err := common.VersionToList(version)
if err != nil {
fmt.Fprintf(os.Stderr, "warning: unable to parse MySQL version %q: %v; using legacy replication commands\n", version, err)
return cmds
}
minShowReplicaStatusVersionList, err := common.VersionToList(globals.MinimumShowReplicaStatusVersion)
if err != nil {
fmt.Fprintf(os.Stderr, "warning: unable to parse minimum show replica status version %q: %v; leaving slave status commands unchanged\n", globals.MinimumShowReplicaStatusVersion, err)
} else {
useReplicaStatus := common.GreaterOrEqualVersionList(versionList, minShowReplicaStatusVersionList)
if useReplicaStatus {
cmds["ShowSlaveStatus"] = "show replica status"
cmds["StartReplica"] = "START REPLICA"
cmds["StopReplica"] = "STOP REPLICA"
cmds["ResetReplica"] = "RESET REPLICA"
cmds["MasterPosWaitFunc"] = "source_pos_wait"
}
}
minChangeSourceVersionList, err := common.VersionToList(globals.MinimumChangeReplicationSourceVersion)
if err != nil {
fmt.Fprintf(os.Stderr, "warning: unable to parse minimum change replication source version %q: %v; leaving CHANGE MASTER TO command unchanged\n", globals.MinimumChangeReplicationSourceVersion, err)
} else {
useChangeSource := common.GreaterOrEqualVersionList(versionList, minChangeSourceVersionList)
if useChangeSource {
cmds["ChangeMasterTo"] = "CHANGE REPLICATION SOURCE TO"
cmds["MasterHostParam"] = "source_host"
cmds["MasterPortParam"] = "source_port"
cmds["MasterUserParam"] = "source_user"
cmds["MasterPasswordParam"] = "source_password"
}
}
minBinaryLogStatusVersionList, err := common.VersionToList(globals.MinimumShowBinaryLogStatusVersion)
if err != nil {
fmt.Fprintf(os.Stderr, "warning: unable to parse minimum show binary log status version %q: %v; leaving master status command unchanged\n", globals.MinimumShowBinaryLogStatusVersion, err)
} else {
useBinaryLogStatus := common.GreaterOrEqualVersionList(versionList, minBinaryLogStatusVersionList)
if useBinaryLogStatus {
cmds["ShowMasterStatus"] = "show binary log status"
}
}

Copilot uses AI. Check for mistakes.
return cmds
}

type Slave struct {
Node int
Port int
Expand Down Expand Up @@ -188,7 +229,12 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in
}
if isMinimumNativeAuthPlugin {
if !sandboxDef.NativeAuthPlugin {
sandboxDef.ChangeMasterOptions = append(sandboxDef.ChangeMasterOptions, "GET_MASTER_PUBLIC_KEY=1")
useNewSourceSyntax, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion)
if useNewSourceSyntax {
sandboxDef.ChangeMasterOptions = append(sandboxDef.ChangeMasterOptions, "GET_SOURCE_PUBLIC_KEY=1")
} else {
sandboxDef.ChangeMasterOptions = append(sandboxDef.ChangeMasterOptions, "GET_MASTER_PUBLIC_KEY=1")
Comment on lines +232 to +236
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This uses common.GreaterOrEqualVersion (deprecated) and ignores the parse error. If sandboxDef.Version isn’t strictly x.y.z (e.g., includes a prefix), this will silently choose GET_MASTER_PUBLIC_KEY even when the new CHANGE REPLICATION SOURCE TO syntax is active, which can break authentication on newer MySQL. Prefer common.HasCapability (new feature flag) or compare parsed version lists and handle the error explicitly.

Copilot uses AI. Check for mistakes.
}
}
}
slaves := nodes - 1
Expand All @@ -199,6 +245,7 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in
timestamp := time.Now()

changeMasterExtra = setChangeMasterProperties(changeMasterExtra, sandboxDef.ChangeMasterOptions, logger)
replCmds := replicationCommands(sandboxDef.Version)
var data = common.StringMap{
"ShellPath": sandboxDef.ShellPath,
"Copyright": globals.ShellScriptCopyright,
Expand All @@ -216,6 +263,17 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in
"ChangeMasterExtra": changeMasterExtra,
"MasterAutoPosition": masterAutoPosition,
"Slaves": []common.StringMap{},
"ShowMasterStatus": replCmds["ShowMasterStatus"],
"ShowSlaveStatus": replCmds["ShowSlaveStatus"],
"ChangeMasterTo": replCmds["ChangeMasterTo"],
"StartReplica": replCmds["StartReplica"],
"StopReplica": replCmds["StopReplica"],
"ResetReplica": replCmds["ResetReplica"],
"MasterPosWaitFunc": replCmds["MasterPosWaitFunc"],
"MasterHostParam": replCmds["MasterHostParam"],
"MasterPortParam": replCmds["MasterPortParam"],
"MasterUserParam": replCmds["MasterUserParam"],
"MasterPasswordParam": replCmds["MasterPasswordParam"],
}

logger.Printf("Defining replication data: %v\n", stringMapToJson(data))
Expand Down Expand Up @@ -308,7 +366,17 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in
"ChangeMasterExtra": changeMasterExtra,
"MasterAutoPosition": masterAutoPosition,
"RplUser": sandboxDef.RplUser,
"RplPassword": sandboxDef.RplPassword})
"RplPassword": sandboxDef.RplPassword,
"ChangeMasterTo": replCmds["ChangeMasterTo"],
"StartReplica": replCmds["StartReplica"],
"ShowSlaveStatus": replCmds["ShowSlaveStatus"],
"ShowMasterStatus": replCmds["ShowMasterStatus"],
"MasterHostParam": replCmds["MasterHostParam"],
"MasterPortParam": replCmds["MasterPortParam"],
"MasterUserParam": replCmds["MasterUserParam"],
"MasterPasswordParam": replCmds["MasterPasswordParam"],
"MasterPosWaitFunc": replCmds["MasterPosWaitFunc"],
})
sandboxDef.LoadGrants = false
sandboxDef.Prompt = fmt.Sprintf("%s%d", slaveLabel, i)
sandboxDef.DirName = fmt.Sprintf("%s%d", nodeLabel, i)
Expand Down Expand Up @@ -369,6 +437,15 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in
"MasterAutoPosition": masterAutoPosition,
"SlaveAbbr": slaveAbbr,
"SandboxDir": sandboxDef.SandboxDir,
"ChangeMasterTo": replCmds["ChangeMasterTo"],
"StartReplica": replCmds["StartReplica"],
"ShowSlaveStatus": replCmds["ShowSlaveStatus"],
"ShowMasterStatus": replCmds["ShowMasterStatus"],
"MasterHostParam": replCmds["MasterHostParam"],
"MasterPortParam": replCmds["MasterPortParam"],
"MasterUserParam": replCmds["MasterUserParam"],
"MasterPasswordParam": replCmds["MasterPasswordParam"],
"MasterPosWaitFunc": replCmds["MasterPosWaitFunc"],
}
logger.Printf("Defining replication node data: %v\n", stringMapToJson(dataSlave))
logger.Printf("Create slave script %d\n", i)
Expand Down
4 changes: 2 additions & 2 deletions sandbox/templates/replication/check_multi_source.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ do
port=$($SBDIR/{{.NodeLabel}}$M/use -BN -e "show variables like 'port'")
server_id=$($SBDIR/{{.NodeLabel}}$M/use -BN -e "show variables like 'server_id'")
echo "$port - $server_id"
$SBDIR/{{.NodeLabel}}$M/use -e 'show master status\G' | grep "File\|Position\|Executed"
$SBDIR/{{.NodeLabel}}$M/use -e '{{.ShowMasterStatus}}\G' | grep "File\|Position\|Executed"
done
for S in $SLAVES
do
echo "# Slave $S"
port=$($SBDIR/{{.NodeLabel}}$S/use -BN -e "show variables like 'port'")
server_id=$($SBDIR/{{.NodeLabel}}$S/use -BN -e "show variables like 'server_id'")
echo "$port - $server_id"
$SBDIR/{{.NodeLabel}}$S/use -e 'show slave status\G' | grep "\(Running:\|Master_Log_Pos\|\<Master_Log_File\|Retrieved\|Channel\|Executed\)"
$SBDIR/{{.NodeLabel}}$S/use -e '{{.ShowSlaveStatus}}\G' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|\<Master_Log_File|\<Source_Log_File|Retrieved|Channel|Executed)"
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

grep -E + \< is not portable (BSD/macOS grep doesn’t support \< word-boundary anchors in extended regex). This may prevent matching Master_Log_File/Source_Log_File and hide important status lines. Prefer a portable ERE such as (^|[[:space:]])(Master_Log_File|Source_Log_File): or avoid \< entirely and anchor another way.

Suggested change
$SBDIR/{{.NodeLabel}}$S/use -e '{{.ShowSlaveStatus}}\G' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|\<Master_Log_File|\<Source_Log_File|Retrieved|Channel|Executed)"
$SBDIR/{{.NodeLabel}}$S/use -e '{{.ShowSlaveStatus}}\G' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|Master_Log_File:|Source_Log_File:|Retrieved|Channel|Executed)"

Copilot uses AI. Check for mistakes.
done
4 changes: 2 additions & 2 deletions sandbox/templates/replication/check_slaves.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ echo "{{.MasterLabel}}"
port=$($SBDIR/{{.MasterLabel}}/use -BN -e "show variables like 'port'")
server_id=$($SBDIR/{{.MasterLabel}}/use -BN -e "show variables like 'server_id'")
echo "$port - $server_id"
$SBDIR/{{.MasterLabel}}/use -e 'show master status\G' | grep "File\|Position\|Executed"
$SBDIR/{{.MasterLabel}}/use -e '{{.ShowMasterStatus}}\G' | grep "File\|Position\|Executed"
{{ range .Slaves }}
echo "{{.SlaveLabel}}{{.Node}}"
port=$($SBDIR/{{.NodeLabel}}{{.Node}}/use -BN -e "show variables like 'port'")
server_id=$($SBDIR/{{.NodeLabel}}{{.Node}}/use -BN -e "show variables like 'server_id'")
echo "$port - $server_id"
$SBDIR/{{.NodeLabel}}{{.Node}}/use -e 'show slave status\G' | grep "\(Running:\|Master_Log_Pos\|\<Master_Log_File\|Retrieved\|Executed\|Auto_Position\)"
$SBDIR/{{.NodeLabel}}{{.Node}}/use -e '{{.ShowSlaveStatus}}\G' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|\<Master_Log_File|\<Source_Log_File|Retrieved|Executed|Auto_Position)"
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

grep -E treats \< differently across platforms (notably BSD/macOS grep, which doesn’t support \< word-boundary anchors in ERE). With -E this can end up looking for a literal < and fail to match Master_Log_File/Source_Log_File, making the script miss key replication fields. Use a portable pattern (e.g., match (^|[[:space:]])(Master_Log_File|Source_Log_File):), or drop \< and rely on -w/anchoring.

Suggested change
$SBDIR/{{.NodeLabel}}{{.Node}}/use -e '{{.ShowSlaveStatus}}\G' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|\<Master_Log_File|\<Source_Log_File|Retrieved|Executed|Auto_Position)"
$SBDIR/{{.NodeLabel}}{{.Node}}/use -e '{{.ShowSlaveStatus}}\G' | grep -E "(Running:|Master_Log_Pos|Source_Log_Pos|Master_Log_File:|Source_Log_File:|Retrieved|Executed|Auto_Position)"

Copilot uses AI. Check for mistakes.
{{end}}
4 changes: 2 additions & 2 deletions sandbox/templates/replication/init_slaves.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ fi

{{ range .Slaves }}
echo "initializing {{.SlaveLabel}} {{.Node}}"
echo 'CHANGE MASTER TO master_host="{{.MasterIp}}", master_port={{.MasterPort}}, master_user="{{.RplUser}}", master_password="{{.RplPassword}}" {{.MasterAutoPosition}} {{.ChangeMasterExtra}}' | $SBDIR/{{.NodeLabel}}{{.Node}}/use -u root
$SBDIR/{{.NodeLabel}}{{.Node}}/use -u root -e 'START SLAVE'
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
Expand Down
8 changes: 4 additions & 4 deletions sandbox/templates/replication/multi_source.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ do
then
master_port=$($SBDIR/n$master -BN -e 'select @@port')
$SBDIR/n$master -BN -h {{.MasterIp}} --port=$master_port -u {{.RplUser}} -p{{.RplPassword}} -e 'set @a=1'
user_cmd="$user_cmd CHANGE MASTER TO MASTER_USER='{{.RplUser}}', "
user_cmd="$user_cmd MASTER_PASSWORD='{{.RplPassword}}', master_host='{{.MasterIp}}', "
user_cmd="$user_cmd master_port=$master_port {{.ChangeMasterExtra}} FOR CHANNEL '{{.NodeLabel}}$master';"
user_cmd="$user_cmd START SLAVE FOR CHANNEL '{{.NodeLabel}}$master';"
user_cmd="$user_cmd {{.ChangeMasterTo}} {{.MasterUserParam}}='{{.RplUser}}', "
user_cmd="$user_cmd {{.MasterPasswordParam}}='{{.RplPassword}}', {{.MasterHostParam}}='{{.MasterIp}}', "
user_cmd="$user_cmd {{.MasterPortParam}}=$master_port {{.ChangeMasterExtra}} FOR CHANNEL '{{.NodeLabel}}$master';"
user_cmd="$user_cmd {{.StartReplica}} FOR CHANNEL '{{.NodeLabel}}$master';"
fi
done
VERBOSE_SQL=""
Expand Down
10 changes: 5 additions & 5 deletions sandbox/templates/replication/test_replication.gotxt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MASTER_RECS=$($MASTER -BN -e 'select count(*) from test.t1')

master_status=master_status$$
slave_status=slave_status$$
$MASTER -e 'show master status\G' > $master_status
$MASTER -e '{{.ShowMasterStatus}}\G' > $master_status
master_binlog=$(grep 'File:' $master_status | awk '{print $2}' )
master_pos=$(grep 'Position:' $master_status | awk '{print $2}' )
echo "# {{.MasterLabel}} log: $master_binlog - Position: $master_pos - Rows: $MASTER_RECS"
Expand Down Expand Up @@ -98,7 +98,7 @@ do
then
sleep 3
else
S_READY=$($SLAVE -BN -e "select master_pos_wait('$master_binlog', $master_pos,60)")
S_READY=$($SLAVE -BN -e "select {{.MasterPosWaitFunc}}('$master_binlog', $master_pos,60)")
# master_pos_wait can return 0 or a positive number for successful replication
# Any result that is not NULL or -1 is acceptable
if [ "$S_READY" != "-1" -a "$S_READY" != "NULL" ]
Comment on lines 102 to 104
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The inline comment still refers to master_pos_wait, but on MySQL 8.0.22+ the template now calls {{.MasterPosWaitFunc}} (which can be source_pos_wait). Update the comment to avoid misleading readers/debugging output when the newer function is in use.

Suggested change
# master_pos_wait can return 0 or a positive number for successful replication
# Any result that is not NULL or -1 is acceptable
if [ "$S_READY" != "-1" -a "$S_READY" != "NULL" ]
# The position wait function ({{.MasterPosWaitFunc}}) can return 0 or a positive number for successful replication
# Any result that is not NULL or -1 is acceptable
if [ "$S_READY" != "-1" -a "$SREADY" != "NULL" ]

Copilot uses AI. Check for mistakes.
Expand All @@ -109,10 +109,10 @@ do
fi
if [ -f initialize_{{.SlaveLabel}}s ]
then
$SLAVE -e 'show slave status\G' > $slave_status
IO_RUNNING=$(grep -w Slave_IO_Running $slave_status | awk '{print $2}')
$SLAVE -e '{{.ShowSlaveStatus}}\G' > $slave_status
IO_RUNNING=$(grep -E -w "Slave_IO_Running|Replica_IO_Running" $slave_status | awk '{print $2}')
ok_equal $IO_RUNNING Yes "{{.SlaveLabel}} #$SLAVE_N IO thread is running"
SQL_RUNNING=$(grep -w Slave_IO_Running $slave_status | awk '{print $2}')
SQL_RUNNING=$(grep -E -w "Slave_SQL_Running|Replica_SQL_Running" $slave_status | awk '{print $2}')
ok_equal $SQL_RUNNING Yes "{{.SlaveLabel}} #$SLAVE_N SQL thread is running"
rm -f $slave_status
fi
Expand Down
Loading