Skip to content

Commit ddbfd01

Browse files
committed
feat: add MySQL 8.4-specific replication and group replication templates
Add dedicated templates for MySQL 8.4+ that eliminate deprecation warnings from removed/renamed variables: - repl_crash_safe_options84.gotxt: omits master-info-repository and relay-log-info-repository (removed in 8.4), keeps relay-log-recovery=on - group_repl_options84.gotxt: omits transaction_write_set_extraction (removed in 8.4) and uses log_replica_updates unconditionally - init_slaves_84.gotxt: documents 8.4+ CHANGE REPLICATION SOURCE TO syntax - init_nodes84.gotxt: group replication init using 8.4+ replication commands Update replication.go to use SOURCE_AUTO_POSITION instead of MASTER_AUTO_POSITION for MySQL 8.0.23+, and select the appropriate init_slaves template based on version. Update group_replication.go, multi-source-replication.go, pxc_replication.go, and cmd/single.go to select the 8.4-specific crash-safe and group options templates when the MySQL version is >= 8.4.0.
1 parent 437c392 commit ddbfd01

13 files changed

Lines changed: 192 additions & 24 deletions

cmd/single.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,13 @@ func fillSandboxDefinition(cmd *cobra.Command, args []string, usingImport bool)
400400
common.ErrCheckExitf(err, 1, globals.ErrWhileComparingVersions)
401401
if isMinimumGtid {
402402
sd.GtidOptions = sandbox.SingleTemplates[templateName].Contents
403-
sd.ReplCrashSafeOptions = sandbox.SingleTemplates[globals.TmplReplCrashSafeOptions].Contents
403+
// Use 8.4+ crash-safe options template (no deprecated master-info-repository)
404+
crashSafeTmpl := globals.TmplReplCrashSafeOptions
405+
isMySQL84, _ := common.GreaterOrEqualVersion(sd.Version, globals.MinimumResetBinaryLogsVersion)
406+
if isMySQL84 {
407+
crashSafeTmpl = globals.TmplReplCrashSafeOptions84
408+
}
409+
sd.ReplCrashSafeOptions = sandbox.SingleTemplates[crashSafeTmpl].Contents
404410
sd.ReplOptions = sandbox.SingleTemplates[globals.TmplReplicationOptions].Contents
405411
if sd.ServerId == 0 {
406412
sd.PortAsServerId = true
@@ -418,7 +424,13 @@ func fillSandboxDefinition(cmd *cobra.Command, args []string, usingImport bool)
418424
isMinimumCrashSafe, err := common.HasCapability(sd.Flavor, common.CrashSafe, sd.Version)
419425
common.ErrCheckExitf(err, 1, globals.ErrWhileComparingVersions)
420426
if isMinimumCrashSafe {
421-
sd.ReplCrashSafeOptions = sandbox.SingleTemplates[globals.TmplReplCrashSafeOptions].Contents
427+
// Use 8.4+ crash-safe options template (no deprecated master-info-repository)
428+
crashSafeTmpl := globals.TmplReplCrashSafeOptions
429+
isMySQL84, _ := common.GreaterOrEqualVersion(sd.Version, globals.MinimumResetBinaryLogsVersion)
430+
if isMySQL84 {
431+
crashSafeTmpl = globals.TmplReplCrashSafeOptions84
432+
}
433+
sd.ReplCrashSafeOptions = sandbox.SingleTemplates[crashSafeTmpl].Contents
422434
} else {
423435
common.Exitf(1, globals.ErrOptionRequiresVersion, globals.ReplCrashSafeLabel, common.IntSliceToDottedString(globals.MinimumCrashSafeVersion))
424436
}

globals/template_names.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,13 @@ const (
165165
TmplTidbMyCnf = "tidb_my_cnf"
166166

167167
// group
168-
TmplInitNodes = "init_nodes"
169-
TmplCheckNodes = "check_nodes"
170-
TmplGroupReplOptions = "group_repl_options"
168+
TmplInitNodes = "init_nodes"
169+
TmplCheckNodes = "check_nodes"
170+
TmplGroupReplOptions = "group_repl_options"
171+
TmplInitNodes84 = "init_nodes84"
172+
TmplGroupReplOptions84 = "group_repl_options84"
173+
174+
// MySQL 8.4+ specific templates
175+
TmplInitSlaves84 = "init_slaves_84"
176+
TmplReplCrashSafeOptions84 = "repl_crash_safe_options84"
171177
)

sandbox/group_replication.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ func CreateGroupReplication(sandboxDef SandboxDef, origin string, nodes int, mas
288288
sbItem.LogDirectory = common.DirName(sandboxDef.LogFileName)
289289
}
290290

291+
// Select version-appropriate templates for group replication init
292+
initNodesTmpl := globals.TmplInitNodes
293+
isMySQL84, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
294+
if isMySQL84 {
295+
initNodesTmpl = globals.TmplInitNodes84
296+
}
297+
291298
for i := 1; i <= nodes; i++ {
292299
groupPort := baseGroupPort + i
293300
sandboxDef.Port = basePort + i
@@ -338,18 +345,24 @@ func CreateGroupReplication(sandboxDef SandboxDef, origin string, nodes int, mas
338345
// Version-aware options for group replication
339346
useReplicaUpdates, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumShowReplicaStatusVersion)
340347
useNoWriteSetExtraction, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumNoWriteSetExtractionVersion)
348+
// Use 8.4+ group replication options template when applicable
349+
useMySQL84GroupOptions, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
341350

342351
replicationData := common.StringMap{
343-
"BasePort": basePortText,
344-
"GroupSeeds": connectionString,
345-
"LocalAddresses": fmt.Sprintf("%s:%d", masterIp, groupPort),
346-
"PrimaryMode": singlePrimaryMode,
347-
"UseReplicaUpdates": useReplicaUpdates,
348-
"SkipWriteSetExtraction": useNoWriteSetExtraction,
352+
"BasePort": basePortText,
353+
"GroupSeeds": connectionString,
354+
"LocalAddresses": fmt.Sprintf("%s:%d", masterIp, groupPort),
355+
"PrimaryMode": singlePrimaryMode,
356+
"UseReplicaUpdates": useReplicaUpdates,
357+
"SkipWriteSetExtraction": useNoWriteSetExtraction,
349358
}
350359

360+
groupReplOptionsTmpl := globals.TmplGroupReplOptions
361+
if useMySQL84GroupOptions {
362+
groupReplOptionsTmpl = globals.TmplGroupReplOptions84
363+
}
351364
replOptionsText, err := common.SafeTemplateFill("group_replication",
352-
GroupTemplates[globals.TmplGroupReplOptions].Contents, replicationData)
365+
GroupTemplates[groupReplOptionsTmpl].Contents, replicationData)
353366
if err != nil {
354367
return err
355368
}
@@ -360,8 +373,10 @@ func CreateGroupReplication(sandboxDef SandboxDef, origin string, nodes int, mas
360373

361374
sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplGtidOptions57].Contents)
362375
// master-info-repository and relay-log-info-repository removed in 8.4+
363-
skipCrashSafeOpts, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
364-
if !skipCrashSafeOpts {
376+
if useMySQL84GroupOptions {
377+
// relay-log-recovery is still valid; use the 8.4-specific template
378+
sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplReplCrashSafeOptions84].Contents)
379+
} else {
365380
sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplReplCrashSafeOptions].Contents)
366381
}
367382

@@ -487,7 +502,7 @@ func CreateGroupReplication(sandboxDef SandboxDef, origin string, nodes int, mas
487502
data: data,
488503
sandboxDir: sandboxDef.SandboxDir,
489504
scripts: []ScriptDef{
490-
{globals.ScriptInitializeNodes, globals.TmplInitNodes, true},
505+
{globals.ScriptInitializeNodes, initNodesTmpl, true},
491506
{globals.ScriptCheckNodes, globals.TmplCheckNodes, true},
492507
},
493508
}

sandbox/group_templates.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,29 @@ var (
3030
//go:embed templates/group/init_nodes.gotxt
3131
initNodesTemplate string
3232

33+
//go:embed templates/group/init_nodes84.gotxt
34+
initNodes84Template string
35+
3336
//go:embed templates/group/check_nodes.gotxt
3437
checkNodesTemplate string
3538

3639
//go:embed templates/group/group_repl_options.gotxt
3740
groupReplOptionsTemplate string
3841

42+
//go:embed templates/group/group_repl_options84.gotxt
43+
groupReplOptions84Template string
44+
3945
GroupTemplates = TemplateCollection{
4046
globals.TmplInitNodes: TemplateDesc{
4147
Description: "Initialize group replication after deployment",
4248
Notes: "",
4349
Contents: initNodesTemplate,
4450
},
51+
globals.TmplInitNodes84: TemplateDesc{
52+
Description: "Initialize group replication after deployment (MySQL 8.4+ syntax)",
53+
Notes: "Uses CHANGE REPLICATION SOURCE TO syntax",
54+
Contents: initNodes84Template,
55+
},
4556
globals.TmplCheckNodes: TemplateDesc{
4657
Description: "Checks the status of group replication",
4758
Notes: "",
@@ -52,5 +63,10 @@ var (
5263
Notes: "",
5364
Contents: groupReplOptionsTemplate,
5465
},
66+
globals.TmplGroupReplOptions84: TemplateDesc{
67+
Description: "replication options for Group replication node (MySQL 8.4+)",
68+
Notes: "Excludes transaction_write_set_extraction removed in 8.4",
69+
Contents: groupReplOptions84Template,
70+
},
5571
}
5672
)

sandbox/multi-source-replication.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,11 @@ func CreateAllMastersReplication(sandboxDef SandboxDef, origin string, nodes int
113113
}
114114

115115
sandboxDef.GtidOptions = SingleTemplates[globals.TmplGtidOptions57].Contents
116-
skipCrashSafeOpts, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
117-
if !skipCrashSafeOpts {
116+
isMySQL84allMasters, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
117+
if isMySQL84allMasters {
118+
// relay-log-recovery is still valid; use 8.4-specific template (no deprecated master-info-repository)
119+
sandboxDef.ReplCrashSafeOptions = SingleTemplates[globals.TmplReplCrashSafeOptions84].Contents
120+
} else {
118121
sandboxDef.ReplCrashSafeOptions = SingleTemplates[globals.TmplReplCrashSafeOptions].Contents
119122
}
120123
if sandboxDef.DirName == "" {
@@ -325,8 +328,11 @@ func CreateFanInReplication(sandboxDef SandboxDef, origin string, nodes int, mas
325328
slaveList = globals.SlaveListValue
326329
}
327330
sandboxDef.GtidOptions = SingleTemplates[globals.TmplGtidOptions57].Contents
328-
skipCrashSafe2, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
329-
if !skipCrashSafe2 {
331+
isMySQL84fanIn, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
332+
if isMySQL84fanIn {
333+
// relay-log-recovery is still valid; use 8.4-specific template (no deprecated master-info-repository)
334+
sandboxDef.ReplCrashSafeOptions = SingleTemplates[globals.TmplReplCrashSafeOptions84].Contents
335+
} else {
330336
sandboxDef.ReplCrashSafeOptions = SingleTemplates[globals.TmplReplCrashSafeOptions].Contents
331337
}
332338
if sandboxDef.DirName == "" {

sandbox/pxc_replication.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,11 @@ func CreatePxcReplication(sandboxDef SandboxDef, origin string, nodes int, maste
328328

329329
sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplGtidOptions57].Contents)
330330
// master-info-repository and relay-log-info-repository removed in 8.4+
331-
skipCrashSafeOpts, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
332-
if !skipCrashSafeOpts {
331+
isMySQL84pxc, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumResetBinaryLogsVersion)
332+
if isMySQL84pxc {
333+
// relay-log-recovery is still valid; use 8.4-specific template (no deprecated master-info-repository)
334+
sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplReplCrashSafeOptions84].Contents)
335+
} else {
333336
sandboxDef.ReplOptions += fmt.Sprintf("\n%s\n", SingleTemplates[globals.TmplReplCrashSafeOptions].Contents)
334337
}
335338
// 8.0.11

sandbox/repl_templates.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ var (
3030
//go:embed templates/replication/init_slaves.gotxt
3131
initSlavesTemplate string
3232

33+
//go:embed templates/replication/init_slaves_84.gotxt
34+
initSlaves84Template string
35+
3336
//go:embed templates/replication/semi_sync_start.gotxt
3437
semiSyncStartTemplate string
3538

@@ -135,6 +138,11 @@ var (
135138
Notes: "Can also be run after calling './clear_all'",
136139
Contents: initSlavesTemplate,
137140
},
141+
globals.TmplInitSlaves84: TemplateDesc{
142+
Description: "Initialize slaves after deployment (MySQL 8.4+ syntax)",
143+
Notes: "Uses CHANGE REPLICATION SOURCE TO and SOURCE_AUTO_POSITION",
144+
Contents: initSlaves84Template,
145+
},
138146
globals.TmplSemiSyncStart: TemplateDesc{
139147
Description: "Starts semi synch replication ",
140148
Notes: "",

sandbox/replication.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,14 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in
224224
changeMasterExtra := ""
225225
masterAutoPosition := ""
226226
if sandboxDef.GtidOptions != "" {
227-
masterAutoPosition += ", MASTER_AUTO_POSITION=1"
228-
logger.Printf("Adding MASTER_AUTO_POSITION to slaves setup\n")
227+
useSourceAutoPosition, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion)
228+
if useSourceAutoPosition {
229+
masterAutoPosition = ", SOURCE_AUTO_POSITION=1"
230+
logger.Printf("Adding SOURCE_AUTO_POSITION to slaves setup\n")
231+
} else {
232+
masterAutoPosition = ", MASTER_AUTO_POSITION=1"
233+
logger.Printf("Adding MASTER_AUTO_POSITION to slaves setup\n")
234+
}
229235
}
230236
// 8.0.11
231237
// isMinimumNativeAuthPlugin, err := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumNativeAuthPluginVersion)
@@ -497,6 +503,13 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in
497503
execAllSlaves := "exec_all_" + slavePlural
498504
execAllMasters := "exec_all_" + masterPlural
499505

506+
// Select the appropriate init_slaves template based on MySQL version
507+
initSlavesTemplate := globals.TmplInitSlaves
508+
useNewSourceSyntax, _ := common.GreaterOrEqualVersion(sandboxDef.Version, globals.MinimumChangeReplicationSourceVersion)
509+
if useNewSourceSyntax {
510+
initSlavesTemplate = globals.TmplInitSlaves84
511+
}
512+
500513
sb := ScriptBatch{
501514
tc: ReplicationTemplates,
502515
logger: logger,
@@ -515,7 +528,7 @@ func CreateMasterSlaveReplication(sandboxDef SandboxDef, origin string, nodes in
515528
{globals.ScriptMetadataAll, globals.TmplMetadataAll, true},
516529
{useAllSlaves, globals.TmplUseAllSlaves, true},
517530
{useAllMasters, globals.TmplUseAllMasters, true},
518-
{initializeSlaves, globals.TmplInitSlaves, true},
531+
{initializeSlaves, initSlavesTemplate, true},
519532
{checkSlaves, globals.TmplCheckSlaves, true},
520533
{masterAbbr, globals.TmplMaster, true},
521534
{execAllSlaves, globals.TmplExecAllSlaves, true},

sandbox/templates.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ var (
128128
//go:embed templates/single/repl_crash_safe_options.gotxt
129129
replCrashSafeOptions string
130130

131+
//go:embed templates/single/repl_crash_safe_options84.gotxt
132+
replCrashSafeOptions84 string
133+
131134
//go:embed templates/single/gtid_options_56.gotxt
132135
gtidOptions56 string
133136

@@ -218,6 +221,11 @@ var (
218221
Notes: "",
219222
Contents: replCrashSafeOptions,
220223
},
224+
globals.TmplReplCrashSafeOptions84: TemplateDesc{
225+
Description: "Replication crash safe options for MySQL 8.4+",
226+
Notes: "Excludes master-info-repository and relay-log-info-repository removed in 8.4",
227+
Contents: replCrashSafeOptions84,
228+
},
221229
globals.TmplExposeDdTables: TemplateDesc{
222230
Description: "Commands needed to enable data dictionary table usage",
223231
Notes: "",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# After customization, these options are added to my.sandbox.cnf
3+
# MySQL 8.4+ group replication options (transaction_write_set_extraction removed)
4+
binlog_checksum=NONE
5+
log_replica_updates=ON
6+
plugin-load-add=group_replication.so
7+
group_replication=FORCE_PLUS_PERMANENT
8+
group_replication_start_on_boot=OFF
9+
group_replication_bootstrap_group=OFF
10+
report-host=127.0.0.1
11+
loose-group_replication_group_name="{{.BasePort}}-bbbb-cccc-dddd-eeeeeeeeeeee"
12+
loose-group-replication-local-address={{.LocalAddresses}}
13+
loose-group-replication-group-seeds={{.GroupSeeds}}
14+
loose-group-replication-single-primary-mode={{.PrimaryMode}}

0 commit comments

Comments
 (0)