(tlog *logs.Logger)
| 60 | } |
| 61 | |
| 62 | func (f *Funclet) tmpRecycleTask(tlog *logs.Logger) (err error) { |
| 63 | tlog.Infof("[tmp recycle task] start task") |
| 64 | defer tlog.Infof("[tmp recycle task] finish task") |
| 65 | defer func() { |
| 66 | if err := recover(); err != nil { |
| 67 | tlog.Errorf("[tmp recycle task] occurred panic: %s, stask [%s]", err, debug.Stack()) |
| 68 | } |
| 69 | }() |
| 70 | ids := make([]string, 0) |
| 71 | f.ContainerManager.ContainerMap.CMap.Range(func(k, v interface{}) bool { |
| 72 | cid, ok := k.(string) |
| 73 | if !ok { |
| 74 | tlog.Errorf("containers map key is invalid, key %+v", k) |
| 75 | err = fmt.Errorf("[tmp recycle task] failed: containers map key is invalid") |
| 76 | return false |
| 77 | } |
| 78 | ids = append(ids, cid) |
| 79 | return true |
| 80 | }) |
| 81 | if err != nil { |
| 82 | return |
| 83 | } |
| 84 | tlog.V(9).Infof("[tmp recycle task] all container ids %v", ids) |
| 85 | |
| 86 | // TODO: Try more aggressive way! |
| 87 | paths, err := f.TmpManager.SnapshotTmpPaths() |
| 88 | if err != nil { |
| 89 | tlog.Errorf("[tmp recycle task] shapshot tmp path failed: %s", err) |
| 90 | return |
| 91 | } |
| 92 | tlog.V(9).Infof("[tmp recycle task] all tmp paths %v", paths) |
| 93 | recycleList := make([]string, 0) |
| 94 | for _, path := range *paths { |
| 95 | pathName := strings.TrimPrefix(path, tmp.RunnersTmpPath) |
| 96 | pathName = strings.TrimLeft(pathName, "/") |
| 97 | cID, err := f.PathManager.GetContainerID(pathName) |
| 98 | if err != nil { |
| 99 | tlog.Errorf("[tmp recycle task] get container name by path name failed: %s", err) |
| 100 | continue |
| 101 | } |
| 102 | cp, err := f.PathManager.GetPaths(cID) |
| 103 | if err != nil { |
| 104 | tlog.Errorf("[tmp recycle task] get container paths by container id failed: %s", err) |
| 105 | continue |
| 106 | } |
| 107 | if cp.PathName == "" { |
| 108 | tlog.Error("[tmp recycle task] get container paths by container id failed: path name is empty") |
| 109 | continue |
| 110 | } |
| 111 | if pathName != cp.PathName { |
| 112 | recycleList = append(recycleList, pathName) |
| 113 | } |
| 114 | } |
| 115 | tlog.V(4).Infof("[tmp recycle task] all recycle paths %v", recycleList) |
| 116 | for _, pathName := range recycleList { |
| 117 | tlog.V(6).Infof("[tmp recycle task] remove tmp storage path %s ", pathName) |
| 118 | if err := f.TmpManager.RemoveTmpStorage(pathName); err != nil { |
| 119 | tlog.Errorf("[tmp recycle task] remove tmp storage %s failed: %s", pathName, err) |
no test coverage detected