Small refactor of gc/scheduler to remove import of metadata

Replace metadata.GCStats with an interface for exposing elapsed time

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
Daniel Nephin
2018-01-03 14:15:07 -05:00
parent e479165a38
commit 06edd193ef
5 changed files with 52 additions and 29 deletions

View File

@@ -204,7 +204,7 @@ func (m *DB) Update(fn func(*bolt.Tx) error) error {
// RegisterMutationCallback registers a function to be called after a metadata
// mutations has been performed.
//
// The callback function in an argument for whether a deletion has occurred
// The callback function is an argument for whether a deletion has occurred
// since the last garbage collection.
func (m *DB) RegisterMutationCallback(fn func(bool)) {
m.dirtyL.Lock()
@@ -219,15 +219,20 @@ type GCStats struct {
SnapshotD map[string]time.Duration
}
// Elapsed returns the duration which elapsed during a collection
func (s GCStats) Elapsed() time.Duration {
return s.MetaD
}
// GarbageCollect starts garbage collection
func (m *DB) GarbageCollect(ctx context.Context) (stats GCStats, err error) {
func (m *DB) GarbageCollect(ctx context.Context) (gc.Stats, error) {
m.wlock.Lock()
t1 := time.Now()
marked, err := m.getMarked(ctx)
if err != nil {
m.wlock.Unlock()
return GCStats{}, err
return nil, err
}
m.dirtyL.Lock()
@@ -259,9 +264,10 @@ func (m *DB) GarbageCollect(ctx context.Context) (stats GCStats, err error) {
}); err != nil {
m.dirtyL.Unlock()
m.wlock.Unlock()
return GCStats{}, err
return nil, err
}
var stats GCStats
var wg sync.WaitGroup
if len(m.dirtySS) > 0 {
@@ -303,7 +309,7 @@ func (m *DB) GarbageCollect(ctx context.Context) (stats GCStats, err error) {
wg.Wait()
return
return stats, err
}
func (m *DB) getMarked(ctx context.Context) (map[gc.Node]struct{}, error) {