Skip to content

Commit

Permalink
Merge pull request #585 from signal18/purge-binlogs
Browse files Browse the repository at this point in the history
prevent purge when there is only one binlog file
  • Loading branch information
svaroqui authored May 13, 2024
2 parents c652007 + bed321d commit ec79c78
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions cluster/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,5 @@ var clusterError = map[string]string{
"WARN0104": "Enforce replication mode strict but idempotent on server %s",
"WARN0105": "Force Binlog Purge is not yet available in multi master. Skipping",
"WARN0106": "Minimum number of connected replica(s) is not enough to initiate force purging. Minimum replicas: %d. Skipping",
"WARN0107": "Force Binlog Purge can not continue. Oldest binlog is still used by slaves: %s.%d. Skipping",
}
14 changes: 6 additions & 8 deletions cluster/srv_binlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,12 @@ func (server *ServerMonitor) JobBinlogPurgeMaster() {
lastfile := 0

//Accumulating newest binlog size and shifting to oldest
for totalSize < uint(cluster.Conf.ForceBinlogPurgeTotalSize*(1024*1024*1024)) {
for latestbinlog > 0 && totalSize < uint(cluster.Conf.ForceBinlogPurgeTotalSize*(1024*1024*1024)) {
filename := prefix + "." + fmt.Sprintf("%06d", latestbinlog)
if size, ok := server.BinaryLogFiles[filename]; ok {
//accumulating size
totalSize += size
lastfile = latestbinlog //last file based on total size
} else {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, LvlInfo, "Filename not found on %s: %s", server.URL, filename)
}
//Descending
latestbinlog--
Expand All @@ -255,8 +253,8 @@ func (server *ServerMonitor) JobBinlogPurgeMaster() {
for oldestbinlog <= lastfile {
//Halt and return if last binlogfile is same with slave master pos
if oldestbinlog == cluster.SlavesOldestMasterFile.Suffix {
if cluster.StateMachine.CurState.Search("WARN0105") == false {
cluster.StateMachine.AddState("WARN0105", state.State{ErrType: "WARNING", ErrDesc: clusterError["WARN0105"], ErrFrom: "CHECK", ServerUrl: server.URL})
if cluster.StateMachine.CurState.Search("WARN0107") == false {
cluster.StateMachine.AddState("WARN0107", state.State{ErrType: "WARNING", ErrDesc: fmt.Sprintf(clusterError["WARN0107"], cluster.SlavesOldestMasterFile.Prefix, cluster.SlavesOldestMasterFile.Suffix), ErrFrom: "CHECK", ServerUrl: server.URL})
}
return
}
Expand Down Expand Up @@ -439,7 +437,7 @@ func (server *ServerMonitor) CheckAndPurgeBinlogMaster() {
}
} else {
// cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, LvlErr, "Purging check")
if !server.IsPurgingBinlog() {
if !server.IsPurgingBinlog() && len(server.BinaryLogFiles) > 1 {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, LvlDbg, "MariaDB Version is not compatible for max_binlog_total_size, using manual purging")
go server.JobBinlogPurgeMaster()
}
Expand Down Expand Up @@ -467,9 +465,9 @@ func (server *ServerMonitor) CheckAndPurgeBinlogSlave() {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, LvlInfo, err.Error())
}
} else {
if !server.IsPurgingBinlog() {
if !server.IsPurgingBinlog() && len(server.BinaryLogFiles) > 1 {
cluster.LogModulePrintf(cluster.Conf.Verbose, config.ConstLogModGeneral, LvlDbg, "MariaDB Version is not compatible for max_binlog_total_size, using manual purging")
if cluster.StateMachine.CurState.Search("WARN0105") == false {
if cluster.StateMachine.CurState.Search("WARN0107") == false {
go server.JobBinlogPurgeSlave()
}
}
Expand Down

0 comments on commit ec79c78

Please sign in to comment.