@@ -2,14 +2,14 @@ package scheduler
22
33import (
44 "context"
5- "errors"
65 "fmt"
76 "sync"
87 "time"
98
9+ "github.com/containerd/containerd/gc"
1010 "github.com/containerd/containerd/log"
11- "github.com/containerd/containerd/metadata"
1211 "github.com/containerd/containerd/plugin"
12+ "github.com/pkg/errors"
1313)
1414
1515// config configures the garbage collection policies.
@@ -95,7 +95,12 @@ func init() {
9595 return nil , err
9696 }
9797
98- m := newScheduler (md .(* metadata.DB ), ic .Config .(* config ))
98+ mdCollector , ok := md .(collector )
99+ if ! ok {
100+ return nil , errors .Errorf ("%s %T must implement collector" , plugin .MetadataPlugin , md )
101+ }
102+
103+ m := newScheduler (mdCollector , ic .Config .(* config ))
99104
100105 ic .Meta .Exports = map [string ]string {
101106 "PauseThreshold" : fmt .Sprint (m .pauseThreshold ),
@@ -119,7 +124,7 @@ type mutationEvent struct {
119124
120125type collector interface {
121126 RegisterMutationCallback (func (bool ))
122- GarbageCollect (context.Context ) (metadata. GCStats , error )
127+ GarbageCollect (context.Context ) (gc. Stats , error )
123128}
124129
125130type gcScheduler struct {
@@ -128,7 +133,7 @@ type gcScheduler struct {
128133 eventC chan mutationEvent
129134
130135 waiterL sync.Mutex
131- waiters []chan metadata. GCStats
136+ waiters []chan gc. Stats
132137
133138 pauseThreshold float64
134139 deletionThreshold int
@@ -171,12 +176,12 @@ func newScheduler(c collector, cfg *config) *gcScheduler {
171176 return s
172177}
173178
174- func (s * gcScheduler ) ScheduleAndWait (ctx context.Context ) (metadata. GCStats , error ) {
179+ func (s * gcScheduler ) ScheduleAndWait (ctx context.Context ) (gc. Stats , error ) {
175180 return s .wait (ctx , true )
176181}
177182
178- func (s * gcScheduler ) wait (ctx context.Context , trigger bool ) (metadata. GCStats , error ) {
179- wc := make (chan metadata. GCStats , 1 )
183+ func (s * gcScheduler ) wait (ctx context.Context , trigger bool ) (gc. Stats , error ) {
184+ wc := make (chan gc. Stats , 1 )
180185 s .waiterL .Lock ()
181186 s .waiters = append (s .waiters , wc )
182187 s .waiterL .Unlock ()
@@ -190,15 +195,15 @@ func (s *gcScheduler) wait(ctx context.Context, trigger bool) (metadata.GCStats,
190195 }()
191196 }
192197
193- var gcStats metadata. GCStats
198+ var gcStats gc. Stats
194199 select {
195200 case stats , ok := <- wc :
196201 if ! ok {
197- return metadata. GCStats {} , errors .New ("gc failed" )
202+ return gcStats , errors .New ("gc failed" )
198203 }
199204 gcStats = stats
200205 case <- ctx .Done ():
201- return metadata. GCStats {} , ctx .Err ()
206+ return gcStats , ctx .Err ()
202207 }
203208
204209 return gcStats , nil
@@ -301,9 +306,9 @@ func (s *gcScheduler) run(ctx context.Context) {
301306 continue
302307 }
303308
304- log .G (ctx ).WithField ("d" , stats .MetaD ).Debug ("garbage collected" )
309+ log .G (ctx ).WithField ("d" , stats .Elapsed () ).Debug ("garbage collected" )
305310
306- gcTime += stats .MetaD
311+ gcTime += stats .Elapsed ()
307312 collections ++
308313 triggered = false
309314 deletions = 0
0 commit comments