@@ -2,7 +2,6 @@ package lib
22
33import (
44 "encoding/json"
5- "fmt"
65 "io/ioutil"
76 "os"
87 "path/filepath"
@@ -13,36 +12,6 @@ import (
1312 da "github.com/cvmfs/docker-graphdriver/daemon/docker-api"
1413)
1514
16- func getAllLayers () []string {
17- path := filepath .Join ("/" , "cvmfs" , "*" , subDirInsideRepo , "*" )
18- paths , _ := filepath .Glob (path )
19- return paths
20- }
21-
22- // this function is based on an "homegrow" implementation of a set intersection, go, since it does not provide generics, does not provides also generic datastructures like sets
23- func findToRemoveLayers (all_layers , needed_layers []string ) (removes []string ) {
24- all := map [string ]bool {}
25- needed := map [string ]bool {}
26- to_remove := map [string ]bool {}
27-
28- for _ , layer := range all_layers {
29- all [layer ] = true
30- }
31- for _ , layer := range needed_layers {
32- needed [layer ] = true
33- }
34- for layer , _ := range all {
35- _ , isNeeded := needed [layer ]
36- if ! isNeeded {
37- to_remove [layer ] = true
38- }
39- }
40- for layer := range to_remove {
41- removes = append (removes , layer )
42- }
43- return
44- }
45-
4615func FindImageToGarbageCollect (CVMFSRepo string ) ([]da.Manifest , error ) {
4716 removeSchedulePath := RemoveScheduleLocation (CVMFSRepo )
4817 llog := func (l * log.Entry ) * log.Entry {
@@ -157,38 +126,3 @@ func GarbageCollectSingleLayer(CVMFSRepo, image, layer string) error {
157126 return err
158127 }
159128}
160-
161- func RemoveUselessLayers () error {
162- all_layers := getAllLayers ()
163- needed_layers , err := GetAllNeededLayers ()
164- if err != nil {
165- return err
166- }
167- to_remove := findToRemoveLayers (all_layers , needed_layers )
168- // to_remove is now a slice of paths that we wish to remove from the
169- // repository.
170- // However those paths are "complete":
171- // `/cvmfs/$repo.name/layers/fffbbbaaa`
172- // we need to group them by the repository they belong to, and then
173- // extract only the last part of the path we care about:
174- // `layers/fffbbbaaa`
175- paths := map [string ][]string {}
176- for _ , path := range to_remove {
177- pathSplitted := strings .Split (path , "/" )
178- repoName := pathSplitted [2 ]
179- paths [repoName ] = append (paths [repoName ], strings .Join (pathSplitted [3 :], "/" ))
180- }
181- fmt .Println (paths )
182- // possible optimization
183- // batch the delete of layers, not all together that it will lock the repo for quite too long
184- // but few of them like 10 or 20 together is something very reasonable.
185- for repoName , layers := range paths {
186- for _ , layer := range layers {
187- err = ExecCommand ("cvmfs_server" , "ingest" , "--delete" , layer , repoName ).Start ()
188- if err != nil {
189- LogE (err ).Warning ("Error in deleting the layer" )
190- }
191- }
192- }
193- return nil
194- }
0 commit comments