Skip to content

Commit

Permalink
enhancement: clean up the raft log when the remaining space is insuff…
Browse files Browse the repository at this point in the history
…icient; limit size of raft logs and rotate

Signed-off-by: wenjia322 <[email protected]>
  • Loading branch information
wenjia322 committed Oct 13, 2020
1 parent e76cb1f commit 514852b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 21 deletions.
9 changes: 7 additions & 2 deletions util/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,14 @@ func InitLog(dir, module string, level Level, rotate *LogRotate) (*Log, error) {
return nil, fmt.Errorf("[InitLog] stats disk space: %s",
err.Error())
}
minRatio := float64(fs.Blocks*uint64(fs.
Bsize)) * DefaultHeadRatio / 1024 / 1024
var minRatio float64
if float64(fs.Bavail*uint64(fs.Bsize)) < float64(fs.Blocks*uint64(fs.Bsize))*DefaultHeadRatio {
minRatio = float64(fs.Bavail*uint64(fs.Bsize)) * DefaultHeadRatio / 1024 / 1024
} else {
minRatio = float64(fs.Blocks*uint64(fs.Bsize)) * DefaultHeadRatio / 1024 / 1024
}
rotate.SetHeadRoomMb(int64(math.Min(minRatio, DefaultHeadRoom)))

minRollingSize := int64(fs.Bavail * uint64(fs.Bsize) / uint64(len(levelPrefixes)))
if minRollingSize < DefaultMinRollingSize {
minRollingSize = DefaultMinRollingSize
Expand Down
2 changes: 1 addition & 1 deletion util/log/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package log
const (
// DefaultRollingSize Specifies at what size to roll the output log at
// Units: byte
DefaultRollingSize = 20 * 1024 * 1024 * 1024
DefaultRollingSize = 5 * 1024 * 1024 * 1024
DefaultMinRollingSize = 200 * 1024 * 1024
// DefaultHeadRoom The tolerance for the log space limit (in megabytes)
DefaultHeadRoom = 50 * 1024
Expand Down
111 changes: 93 additions & 18 deletions vendor/github.com/tiglabs/raft/util/log/log.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 514852b

Please sign in to comment.