|
@@ -12,19 +12,25 @@ func BagCacheClean() {
|
|
log.GlobalLogger.Info("启动清理缓存的 goroutine 维护目录【", cfg.CloudConfig.BagDataDir, "】的 bag 包数量:", cfg.CloudConfig.BagNumber)
|
|
log.GlobalLogger.Info("启动清理缓存的 goroutine 维护目录【", cfg.CloudConfig.BagDataDir, "】的 bag 包数量:", cfg.CloudConfig.BagNumber)
|
|
for {
|
|
for {
|
|
// 收到自杀信号
|
|
// 收到自杀信号
|
|
- if signal := <-ChannelKillDiskClean; signal == 1 {
|
|
|
|
- AddKillTimes("2")
|
|
|
|
- return
|
|
|
|
|
|
+ select {
|
|
|
|
+ case signal := <-ChannelKillDiskClean:
|
|
|
|
+ if signal == 1 {
|
|
|
|
+ AddKillTimes("2")
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
}
|
|
}
|
|
|
|
|
|
// 1 ------- 每10秒清理一次 -------
|
|
// 1 ------- 每10秒清理一次 -------
|
|
- time.Sleep(time.Duration(500) * time.Millisecond)
|
|
|
|
|
|
+ time.Sleep(time.Duration(10) * time.Second)
|
|
// 2 ------- 获取目录下所有bag包 -------
|
|
// 2 ------- 获取目录下所有bag包 -------
|
|
bags := util.ListAbsolutePathWithSuffixAndSort(cfg.CloudConfig.BagDataDir, ".bag")
|
|
bags := util.ListAbsolutePathWithSuffixAndSort(cfg.CloudConfig.BagDataDir, ".bag")
|
|
// 3 如果打包数量超过n个,删除最旧的包{
|
|
// 3 如果打包数量超过n个,删除最旧的包{
|
|
if len(bags) > cfg.CloudConfig.BagNumber {
|
|
if len(bags) > cfg.CloudConfig.BagNumber {
|
|
- log.GlobalLogger.Infof("目录【%v】内文件数量超过【%v】,删除第一个文件")
|
|
|
|
- util.DeleteFile(bags[0])
|
|
|
|
|
|
+ diff := len(bags) - cfg.CloudConfig.BagNumber
|
|
|
|
+ for i := 0; i < diff; i++ {
|
|
|
|
+ util.DeleteFile(bags[i])
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|