Skip to content
Snippets Groups Projects
Commit c681c76c authored by Edward Welch's avatar Edward Welch Committed by Ed
Browse files

periodically clean up positions file, removing any files which no longer exist

parent 3f8963ce
No related branches found
No related tags found
No related merge requests found
......@@ -107,6 +107,7 @@ func (p *Positions) run() {
return
case <-ticker.C:
p.save()
p.cleanup()
}
}
}
......@@ -124,6 +125,21 @@ func (p *Positions) save() {
}
}
func (p *Positions) cleanup() {
for k := range p.positions {
if _, err := os.Stat(k); err == nil {
// File still exists.
} else if os.IsNotExist(err) {
// File no longer exists.
p.Remove(k)
} else {
// Can't determine if file exists or not, some other error.
level.Warn(p.logger).Log("msg", "could not determine if log file "+
"still exists while cleaning positions file", "error", err)
}
}
}
func readPositionsFile(filename string) (map[string]int64, error) {
buf, err := ioutil.ReadFile(filepath.Clean(filename))
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment