Skip to content

Commit

Permalink
fix log-removal regression
Browse files Browse the repository at this point in the history
* when total size exceeds configured maximum
* with refactoring

Signed-off-by: Alex Aizman <[email protected]>
  • Loading branch information
alex-aizman committed Sep 23, 2024
1 parent 89d06db commit 7e928e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/cli/cli/log_hdlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const getLogUsage = "download the current log or entire log history from: a) sel
indent1 + "\t - 'ais log get NODE_ID /tmp'\t- download the specified node's current log and save it in the specified directory;\n" +
indent1 + "\t - 'ais log get NODE_ID /tmp/out --refresh 10'\t- download the node's current log _as_ /tmp/out\n" +
indent1 + "\t \t and keep updating (ie., appending) the latter every 10s;\n" +
indent1 + "\t - 'ais log get cluster /tmp'\t-\tdownload TAR.GZ archived logs of _all_ nodes in the cluster\n" +
indent1 + "\t - 'ais log get cluster /tmp'\t- download TAR.GZ archived logs of _all_ nodes in the cluster\n" +
indent1 + "\t \t and save the result in the specified local directory (note that 'get cluster' implies '--all');\n" +
indent1 + "\t - 'ais log get NODE_ID --all'\t- given 'NODE-ID' download the node's entire log TAR.GZ archive\n" +
indent1 + "\t - 'ais log get NODE_ID --all --severity e'\t- archive logged errors and warnings"
Expand Down
35 changes: 19 additions & 16 deletions stats/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,29 +661,30 @@ func hkLogs(int64) time.Duration {

var (
tot int64
finfos = make([]rfs.FileInfo, 0, len(dentries)>>1)
n = len(dentries)
nn = n - n>>2
finfos = make([]rfs.FileInfo, 0, nn)
verbose = cmn.Rom.FastV(4, cos.SmoduleStats)
)
for _, logtype := range []string{".INFO.", ".ERROR."} {
for i, logtype := range []string{".INFO.", ".ERROR."} {
finfos, tot = _sizeLogs(dentries, logtype, finfos)
l := len(finfos)
if tot > maxtotal && l > 1 {
go _rmLogs(tot, maxtotal, logdir, logtype, finfos)
if logtype != ".ERROR." {
finfos = make([]rfs.FileInfo, 0, len(dentries)>>1)
}
} else {
if tot > maxtotal {
nlog.Warningln(gcLogs, "cannot cleanup single large", logtype, "size:", tot, "configured max:", maxtotal)
debug.Assert(l == 1)
for _, finfo := range finfos {
nlog.Warningln("\t>>>", gcLogs, filepath.Join(logdir, finfo.Name()))
}
}
clear(finfos)
switch {
case tot < maxtotal:
if verbose {
nlog.Infoln(gcLogs, "skipping:", logtype, "total:", tot, "max:", maxtotal)
}
case l > 1:
go _rmLogs(tot, maxtotal, logdir, logtype, finfos)
if i == 0 {
finfos = make([]rfs.FileInfo, 0, nn)
}
default:
nlog.Warningln(gcLogs, "cannot cleanup a single large", logtype, "size:", tot, "configured max:", maxtotal)
debug.Assert(l == 1)
for _, finfo := range finfos {
nlog.Warningln("\t>>>", gcLogs, filepath.Join(logdir, finfo.Name()))
}
}
}

Expand All @@ -693,6 +694,8 @@ func hkLogs(int64) time.Duration {
// e.g. name: ais.ip-10-0-2-19.root.log.INFO.20180404-031540.2249
// see also: nlog.InfoLogName, nlog.ErrLogName
func _sizeLogs(dentries []os.DirEntry, logtype string, finfos []rfs.FileInfo) (_ []rfs.FileInfo, tot int64) {
clear(finfos)
finfos = finfos[:0]
for _, dent := range dentries {
if !dent.Type().IsRegular() {
continue
Expand Down

0 comments on commit 7e928e5

Please sign in to comment.