Skip to content

Commit

Permalink
immediate effect on toggle binlog backup (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
caffeinated92 authored Aug 15, 2024
1 parent 18f85b0 commit 01c6c8b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions cluster/cluster_bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ func (cluster *Cluster) BinlogCopyScript(server *ServerMonitor, binlog string, i
time.Sleep(1 * time.Second)
return cluster.BinlogCopyScript(server, binlog, isPurge)
}

cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModTask, config.LvlInfo, "Initiating backup binlog for %s", binlog)
cluster.SetInBinlogBackupState(true)
defer cluster.SetInBinlogBackupState(false)
}
Expand Down
6 changes: 6 additions & 0 deletions cluster/cluster_tgl.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ func (cluster *Cluster) SwitchBackupRestic() {
}
func (cluster *Cluster) SwitchBackupBinlogs() {
cluster.Conf.BackupBinlogs = !cluster.Conf.BackupBinlogs
if cluster.Conf.BackupBinlogs {
for _, sv := range cluster.GetServers() {
go sv.CheckBinaryLogs(true)
}
}
}

func (cluster *Cluster) SwitchCompressBackups() {
cluster.Conf.CompressBackups = !cluster.Conf.CompressBackups
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ func (server *ServerMonitor) Refresh() error {
server.BinaryLogPos = strconv.FormatUint(uint64(server.MasterStatus.Position), 10)

//Detach binlog process from main process
go server.CheckBinaryLogs()
go server.CheckBinaryLogs(false)
}

if !server.DBVersion.IsPostgreSQL() {
Expand Down
4 changes: 2 additions & 2 deletions cluster/srv_binlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (server *ServerMonitor) RefreshBinlogMetadata(oldmetamap map[string]dbhelpe
}

// This process is detached so it will not blocking if waiting
func (server *ServerMonitor) CheckBinaryLogs() error {
func (server *ServerMonitor) CheckBinaryLogs(force bool) error {
cluster := server.ClusterGroup
var err error

Expand All @@ -241,7 +241,7 @@ func (server *ServerMonitor) CheckBinaryLogs() error {
}

// If log has been rotated
if server.BinaryLogFilePrevious != "" && server.BinaryLogFilePrevious != server.BinaryLogFile {
if (server.BinaryLogFilePrevious != "" && server.BinaryLogFilePrevious != server.BinaryLogFile) || force {
// Always running, triggered by binlog rotation
if cluster.Conf.BinlogRotationScript != "" && server.IsMaster() {
cluster.BinlogRotationScript(server)
Expand Down
8 changes: 3 additions & 5 deletions cluster/srv_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2250,6 +2250,7 @@ func (server *ServerMonitor) JobBackupBinlog(binlogfile string, isPurge bool) er
return server.JobBackupBinlog(binlogfile, isPurge)
}

cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModTask, config.LvlInfo, "Initiating backup binlog for %s", binlogfile)
cluster.SetInBinlogBackupState(true)
defer cluster.SetInBinlogBackupState(false)
}
Expand Down Expand Up @@ -2328,7 +2329,7 @@ func (server *ServerMonitor) JobBackupBinlogPurge(binlogfile string) error {
for _, file := range files {
_, ok := keeping[file.Name()]
if strings.HasPrefix(file.Name(), prefix) && !ok {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModTask, config.LvlInfo, "Purging binlog file %s", file.Name())
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModTask, config.LvlInfo, "Purging binlog file from backup dir %s", file.Name())
os.Remove(server.GetMyBackupDirectory() + "/" + file.Name())
}
}
Expand Down Expand Up @@ -2490,6 +2491,7 @@ func (server *ServerMonitor) JobBackupBinlogSSH(binlogfile string, isPurge bool)
return server.JobBackupBinlogSSH(binlogfile, isPurge)
}

cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModTask, config.LvlInfo, "Initiating backup binlog for %s", binlogfile)
cluster.SetInBinlogBackupState(true)
defer cluster.SetInBinlogBackupState(false)
}
Expand Down Expand Up @@ -2557,10 +2559,6 @@ func (server *ServerMonitor) InitiateJobBackupBinlog(binlogfile string, isPurge
server.SetBinaryLogDir(binlogpath)
}

if !isPurge {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModTask, config.LvlInfo, "Initiating backup binlog for %s", binlogfile)
}

switch cluster.Conf.BinlogCopyMode {
case "client", "mysqlbinlog":
return server.JobBackupBinlog(binlogfile, isPurge)
Expand Down

0 comments on commit 01c6c8b

Please sign in to comment.