Skip to content

Commit

Permalink
blobmapping: account blob size in disk usage
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed May 31, 2017
1 parent 1c5dbe5 commit f4695e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
3 changes: 1 addition & 2 deletions control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ func TestControl(t *testing.T) {
du, err := cm.DiskUsage(context.TODO())
assert.NoError(t, err)

// fmt.Printf("du1:\n")
// for _, d := range du {
// fmt.Printf("du1: %+v\n", d)
// fmt.Printf("du: %+v\n", d)
// }

err = snap.Release()
Expand Down
21 changes: 20 additions & 1 deletion snapshot/blobmapping/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,32 @@ func (s *Snapshotter) Remove(ctx context.Context, key string) error {
b = tx.Bucket(bucketByBlob)
b.Delete(blobKey(blob, key))
if len(keyRange(tx, blobKey(blob, ""))) == 0 { // last snapshot
s.opt.Content.Delete(ctx, digest.Digest(blob)) // log error
s.opt.Content.Delete(ctx, blob) // log error
}
}
return nil
})
}

func (s *Snapshotter) Usage(ctx context.Context, key string) (snapshot.Usage, error) {
u, err := s.Snapshotter.Usage(ctx, key)
if err != nil {
return snapshot.Usage{}, err
}
blob, err := s.GetBlob(ctx, key)
if err != nil {
return u, err
}
if blob != "" {
info, err := s.opt.Content.Info(ctx, blob)
if err != nil {
return u, err
}
(&u).Add(snapshot.Usage{Size: info.Size, Inodes: 1})
}
return u, nil
}

// TODO: make Blob/SetBlob part of generic metadata wrapper that can detect
// blob key for deletion logic

Expand Down

0 comments on commit f4695e7

Please sign in to comment.