func (t *Thread) cleanUpOnLowDiskSpace() { if len(t.files) == 0 { return // cannot clean up files if we don't have any. } fido := base.Watchdog(time.Minute, "cleaning up low disk space") defer fido.Stop() for { fido.Reset(time.Minute) if len(t.files) > t.conf.MaxDirectoryFiles { v(1, "Thread %v too many files. %d > %d, deleting", t.id, len(t.files), t.conf.MaxDirectoryFiles) t.deleteOldestThreadFiles(len(t.files) - t.conf.MaxDirectoryFiles) continue } df, err := base.PathDiskFreePercentage(t.packetPath) if err != nil { log.Printf("Thread %v could not get the free disk percentage for %q: %v", t.id, t.packetPath, err) return } if df > t.conf.DiskFreePercentage { v(1, "Thread %v disk space is sufficient: %v > %v", t.id, df, t.conf.DiskFreePercentage) return } v(0, "Thread %v disk usage is high (packet path=%q): %d%% < %d%% free\n", t.id, t.packetPath, df, t.conf.DiskFreePercentage) t.deleteOldestThreadFiles(1) // After deleting files, it may take a while for disk stats to be updated. // We add this sleep so we don't accidentally delete WAY more files than // we need to. time.Sleep(100 * time.Millisecond) } }
func (t *Thread) syncFilesWithDisk() { fido := base.Watchdog(time.Minute*5, "syncing files with disk") // 5 min for initial list of files defer fido.Stop() newFilesCnt := 0 for _, filename := range t.listPacketFilesOnDisk() { fido.Reset(time.Minute) // 1 minute for opening each new file if t.files[filename] != nil { continue } if err := t.trackNewFile(filename); err != nil { log.Printf("Thread %v error tracking %q: %v", t.id, filename, err) continue } newFilesCnt++ t.fileLastSeen = time.Now() } if newFilesCnt > 0 { v(0, "Thread %v found %d new blockfiles", t.id, newFilesCnt) } }