Browse Source

[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
pull/2799/head
Anton Kaliaev 6 years ago
parent
commit
13badc1d29
2 changed files with 6 additions and 4 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +5
    -4
      libs/autofile/group.go

+ 1
- 0
CHANGELOG_PENDING.md 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

+ 5
- 4
libs/autofile/group.go 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()
}
}


Loading…
Cancel
Save