[autofile/group] do not panic when checking size

It's OK if the head will grow a little bit bigger, but we'll avoid
panic.

Refs #2703
This commit is contained in:
Anton Kaliaev 2018-11-06 13:14:47 +01:00
parent 091d2c3e5e
commit 13badc1d29
2 changed files with 6 additions and 4 deletions

View File

@ -29,3 +29,4 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
- [crypto/merkle] [\#2756](https://github.com/tendermint/tendermint/issues/2756) Fix crypto/merkle ProofOperators.Verify to check bounds on keypath parts.
- [mempool] fix a bug where we create a WAL despite `wal_dir` being empty
- [p2p] \#2771 Fix `peer-id` label name in prometheus metrics
- [autofile] [\#2703] do not panic when checking Head size

View File

@ -230,7 +230,8 @@ func (g *Group) checkHeadSizeLimit() {
}
size, err := g.Head.Size()
if err != nil {
panic(err)
g.Logger.Error("Group's head may grow without bound", "head", g.Head.Path, "err", err)
return
}
if size >= limit {
g.RotateFile()
@ -252,11 +253,11 @@ func (g *Group) checkTotalSizeLimit() {
}
if index == gInfo.MaxIndex {
// Special degenerate case, just do nothing.
g.Logger.Info("Group's head may grow without bound", "head", g.Head.Path)
g.Logger.Error("Group's head may grow without bound", "head", g.Head.Path)
return
}
pathToRemove := filePathForIndex(g.Head.Path, index, gInfo.MaxIndex)
fileInfo, err := os.Stat(pathToRemove)
fInfo, err := os.Stat(pathToRemove)
if err != nil {
g.Logger.Error("Failed to fetch info for file", "file", pathToRemove)
continue
@ -266,7 +267,7 @@ func (g *Group) checkTotalSizeLimit() {
g.Logger.Error("Failed to remove path", "path", pathToRemove)
return
}
totalSize -= fileInfo.Size()
totalSize -= fInfo.Size()
}
}