Skip to content

Commit 186142a

Browse files
committed
remove useless code
1 parent 6e172c8 commit 186142a

File tree

2 files changed

+5
-70
lines changed

2 files changed

+5
-70
lines changed

daemon/lib/garbage_collection.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package lib
22

33
import (
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-
4615
func 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-
}

daemon/lib/sql.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package lib
22

33
import (
44
"database/sql"
5-
"fmt"
65
"os/user"
76
"path"
87

@@ -491,11 +490,12 @@ converted.wish = wish.id AND
491490
wish.input_image = i.id;
492491
`
493492

493+
/*
494494
var getAllNeededLayers = fmt.Sprintf(`
495-
SELECT DISTINCT(
495+
SELECT DISTINCT(
496496
'/cvmfs/' || wish.cvmfs_repo || '/'|| '%s' || '/' || substr(json_extract(layers.value, '$.Digest'), 8)
497-
)
498-
FROM
497+
)
498+
FROM
499499
converted, wish, json_each(converted.manifest, '$.Layers') as layers WHERE
500500
converted.wish = wish.id;
501501
`, subDirInsideRepo)
@@ -525,3 +525,4 @@ func GetAllNeededLayers() ([]string, error) {
525525
}
526526
return layers, nil
527527
}
528+
*/

0 commit comments

Comments
 (0)