cache: add more metadata values to snapshots

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2017-07-25 12:11:52 -07:00
parent 24eeb9d2ee
commit 38ac00090c
12 changed files with 641 additions and 122 deletions

View File

@ -29,8 +29,8 @@ import math "math"
import _ "github.com/gogo/protobuf/gogoproto"
import _ "github.com/golang/protobuf/ptypes/timestamp"
import github_com_opencontainers_go_digest "github.com/opencontainers/go-digest"
import time "time"
import github_com_opencontainers_go_digest "github.com/opencontainers/go-digest"
import (
context "golang.org/x/net/context"
@ -54,6 +54,7 @@ var _ = time.Kitchen
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
type DiskUsageRequest struct {
Filter string `protobuf:"bytes,1,opt,name=filter,proto3" json:"filter,omitempty"`
}
func (m *DiskUsageRequest) Reset() { *m = DiskUsageRequest{} }
@ -61,6 +62,13 @@ func (m *DiskUsageRequest) String() string { return proto.CompactText
func (*DiskUsageRequest) ProtoMessage() {}
func (*DiskUsageRequest) Descriptor() ([]byte, []int) { return fileDescriptorControl, []int{0} }
func (m *DiskUsageRequest) GetFilter() string {
if m != nil {
return m.Filter
}
return ""
}
type DiskUsageResponse struct {
Record []*UsageRecord `protobuf:"bytes,1,rep,name=record" json:"record,omitempty"`
}
@ -78,10 +86,15 @@ func (m *DiskUsageResponse) GetRecord() []*UsageRecord {
}
type UsageRecord struct {
ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
Mutable bool `protobuf:"varint,2,opt,name=Mutable,proto3" json:"Mutable,omitempty"`
InUse bool `protobuf:"varint,3,opt,name=InUse,proto3" json:"InUse,omitempty"`
Size_ int64 `protobuf:"varint,4,opt,name=Size,proto3" json:"Size,omitempty"`
ID string `protobuf:"bytes,1,opt,name=ID,proto3" json:"ID,omitempty"`
Mutable bool `protobuf:"varint,2,opt,name=Mutable,proto3" json:"Mutable,omitempty"`
InUse bool `protobuf:"varint,3,opt,name=InUse,proto3" json:"InUse,omitempty"`
Size_ int64 `protobuf:"varint,4,opt,name=Size,proto3" json:"Size,omitempty"`
Parent string `protobuf:"bytes,5,opt,name=Parent,proto3" json:"Parent,omitempty"`
CreatedAt time.Time `protobuf:"bytes,6,opt,name=CreatedAt,stdtime" json:"CreatedAt"`
LastUsedAt *time.Time `protobuf:"bytes,7,opt,name=LastUsedAt,stdtime" json:"LastUsedAt,omitempty"`
UsageCount int64 `protobuf:"varint,8,opt,name=UsageCount,proto3" json:"UsageCount,omitempty"`
Description string `protobuf:"bytes,9,opt,name=Description,proto3" json:"Description,omitempty"`
}
func (m *UsageRecord) Reset() { *m = UsageRecord{} }
@ -117,6 +130,41 @@ func (m *UsageRecord) GetSize_() int64 {
return 0
}
func (m *UsageRecord) GetParent() string {
if m != nil {
return m.Parent
}
return ""
}
func (m *UsageRecord) GetCreatedAt() time.Time {
if m != nil {
return m.CreatedAt
}
return time.Time{}
}
func (m *UsageRecord) GetLastUsedAt() *time.Time {
if m != nil {
return m.LastUsedAt
}
return nil
}
func (m *UsageRecord) GetUsageCount() int64 {
if m != nil {
return m.UsageCount
}
return 0
}
func (m *UsageRecord) GetDescription() string {
if m != nil {
return m.Description
}
return ""
}
type SolveRequest struct {
Ref string `protobuf:"bytes,1,opt,name=Ref,proto3" json:"Ref,omitempty"`
Definition [][]byte `protobuf:"bytes,2,rep,name=Definition" json:"Definition,omitempty"`
@ -655,6 +703,12 @@ func (m *DiskUsageRequest) MarshalTo(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
if len(m.Filter) > 0 {
dAtA[i] = 0xa
i++
i = encodeVarintControl(dAtA, i, uint64(len(m.Filter)))
i += copy(dAtA[i:], m.Filter)
}
return i, nil
}
@ -734,6 +788,41 @@ func (m *UsageRecord) MarshalTo(dAtA []byte) (int, error) {
i++
i = encodeVarintControl(dAtA, i, uint64(m.Size_))
}
if len(m.Parent) > 0 {
dAtA[i] = 0x2a
i++
i = encodeVarintControl(dAtA, i, uint64(len(m.Parent)))
i += copy(dAtA[i:], m.Parent)
}
dAtA[i] = 0x32
i++
i = encodeVarintControl(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt)))
n1, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.CreatedAt, dAtA[i:])
if err != nil {
return 0, err
}
i += n1
if m.LastUsedAt != nil {
dAtA[i] = 0x3a
i++
i = encodeVarintControl(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(*m.LastUsedAt)))
n2, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.LastUsedAt, dAtA[i:])
if err != nil {
return 0, err
}
i += n2
}
if m.UsageCount != 0 {
dAtA[i] = 0x40
i++
i = encodeVarintControl(dAtA, i, uint64(m.UsageCount))
}
if len(m.Description) > 0 {
dAtA[i] = 0x4a
i++
i = encodeVarintControl(dAtA, i, uint64(len(m.Description)))
i += copy(dAtA[i:], m.Description)
}
return i, nil
}
@ -962,21 +1051,21 @@ func (m *Vertex) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0x2a
i++
i = encodeVarintControl(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(*m.Started)))
n1, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.Started, dAtA[i:])
n3, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.Started, dAtA[i:])
if err != nil {
return 0, err
}
i += n1
i += n3
}
if m.Completed != nil {
dAtA[i] = 0x32
i++
i = encodeVarintControl(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(*m.Completed)))
n2, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.Completed, dAtA[i:])
n4, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.Completed, dAtA[i:])
if err != nil {
return 0, err
}
i += n2
i += n4
}
if len(m.Error) > 0 {
dAtA[i] = 0x3a
@ -1039,30 +1128,30 @@ func (m *VertexStatus) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0x32
i++
i = encodeVarintControl(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp)))
n3, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i:])
n5, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i:])
if err != nil {
return 0, err
}
i += n3
i += n5
if m.Started != nil {
dAtA[i] = 0x3a
i++
i = encodeVarintControl(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(*m.Started)))
n4, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.Started, dAtA[i:])
n6, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.Started, dAtA[i:])
if err != nil {
return 0, err
}
i += n4
i += n6
}
if m.Completed != nil {
dAtA[i] = 0x42
i++
i = encodeVarintControl(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(*m.Completed)))
n5, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.Completed, dAtA[i:])
n7, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(*m.Completed, dAtA[i:])
if err != nil {
return 0, err
}
i += n5
i += n7
}
return i, nil
}
@ -1091,11 +1180,11 @@ func (m *VertexLog) MarshalTo(dAtA []byte) (int, error) {
dAtA[i] = 0x12
i++
i = encodeVarintControl(dAtA, i, uint64(github_com_gogo_protobuf_types.SizeOfStdTime(m.Timestamp)))
n6, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i:])
n8, err := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.Timestamp, dAtA[i:])
if err != nil {
return 0, err
}
i += n6
i += n8
if m.Stream != 0 {
dAtA[i] = 0x18
i++
@ -1164,6 +1253,10 @@ func encodeVarintControl(dAtA []byte, offset int, v uint64) int {
func (m *DiskUsageRequest) Size() (n int) {
var l int
_ = l
l = len(m.Filter)
if l > 0 {
n += 1 + l + sovControl(uint64(l))
}
return n
}
@ -1195,6 +1288,23 @@ func (m *UsageRecord) Size() (n int) {
if m.Size_ != 0 {
n += 1 + sovControl(uint64(m.Size_))
}
l = len(m.Parent)
if l > 0 {
n += 1 + l + sovControl(uint64(l))
}
l = github_com_gogo_protobuf_types.SizeOfStdTime(m.CreatedAt)
n += 1 + l + sovControl(uint64(l))
if m.LastUsedAt != nil {
l = github_com_gogo_protobuf_types.SizeOfStdTime(*m.LastUsedAt)
n += 1 + l + sovControl(uint64(l))
}
if m.UsageCount != 0 {
n += 1 + sovControl(uint64(m.UsageCount))
}
l = len(m.Description)
if l > 0 {
n += 1 + l + sovControl(uint64(l))
}
return n
}
@ -1420,6 +1530,35 @@ func (m *DiskUsageRequest) Unmarshal(dAtA []byte) error {
return fmt.Errorf("proto: DiskUsageRequest: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Filter", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowControl
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthControl
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Filter = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipControl(dAtA[iNdEx:])
@ -1639,6 +1778,146 @@ func (m *UsageRecord) Unmarshal(dAtA []byte) error {
break
}
}
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Parent", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowControl
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthControl
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Parent = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 6:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field CreatedAt", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowControl
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthControl
}
postIndex := iNdEx + msglen
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(&m.CreatedAt, dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 7:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field LastUsedAt", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowControl
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthControl
}
postIndex := iNdEx + msglen
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.LastUsedAt == nil {
m.LastUsedAt = new(time.Time)
}
if err := github_com_gogo_protobuf_types.StdTimeUnmarshal(m.LastUsedAt, dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 8:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field UsageCount", wireType)
}
m.UsageCount = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowControl
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.UsageCount |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 9:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Description", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowControl
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthControl
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Description = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipControl(dAtA[iNdEx:])
@ -3145,58 +3424,64 @@ var (
func init() { proto.RegisterFile("control.proto", fileDescriptorControl) }
var fileDescriptorControl = []byte{
// 844 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x55, 0xdd, 0x8e, 0xdb, 0x44,
0x14, 0x66, 0xec, 0xac, 0x93, 0x9c, 0xcd, 0x56, 0xcb, 0x08, 0x55, 0x96, 0x11, 0x49, 0x30, 0x37,
0x51, 0xa5, 0x7a, 0xdb, 0x00, 0x12, 0x5a, 0x24, 0x04, 0x21, 0x95, 0xd8, 0x15, 0x7b, 0x33, 0xdb,
0xc2, 0xb5, 0x93, 0x9c, 0x75, 0xad, 0x75, 0x3c, 0x61, 0x66, 0x1c, 0x6d, 0x78, 0x0a, 0x78, 0x0d,
0x6e, 0x79, 0x06, 0x44, 0x2f, 0xb9, 0xe6, 0xa2, 0xa0, 0x7d, 0x00, 0x9e, 0x01, 0xcd, 0x8c, 0x9d,
0x7a, 0x9b, 0x4d, 0x7f, 0xd2, 0x2b, 0xcf, 0x19, 0x7f, 0xe7, 0xef, 0x3b, 0x3f, 0x03, 0x07, 0x53,
0x9e, 0x2b, 0xc1, 0xb3, 0x68, 0x21, 0xb8, 0xe2, 0xf4, 0x70, 0xce, 0x27, 0xab, 0x68, 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bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xa4, 0x56, 0xc1, 0x6e, 0xdb, 0x46,
0x10, 0x2d, 0x49, 0x99, 0x92, 0x46, 0x72, 0xe0, 0x2e, 0x8a, 0x80, 0x50, 0x51, 0x49, 0x65, 0x2f,
0x82, 0x81, 0xd0, 0x89, 0xda, 0x02, 0x85, 0x0b, 0x14, 0x89, 0xac, 0x00, 0xb5, 0x11, 0x03, 0xc5,
0x3a, 0x6e, 0xcf, 0x94, 0x34, 0x66, 0x08, 0x53, 0x5c, 0x75, 0x77, 0x29, 0x58, 0xfd, 0x8a, 0xf6,
0x37, 0x7a, 0xed, 0x17, 0xf4, 0x50, 0x34, 0xc7, 0x9e, 0x7b, 0x48, 0x0b, 0x7f, 0x40, 0xbf, 0xa1,
0xd8, 0x5d, 0x92, 0xa6, 0x23, 0x2b, 0x4e, 0x9c, 0x93, 0x76, 0x56, 0x33, 0x6f, 0x77, 0xde, 0x9b,
0x99, 0x25, 0x6c, 0x4f, 0x59, 0x2a, 0x39, 0x4b, 0x82, 0x05, 0x67, 0x92, 0x91, 0x9d, 0x39, 0x9b,
0xac, 0x82, 0x49, 0x16, 0x27, 0xb3, 0xf3, 0x58, 0x06, 0xcb, 0x47, 0x9d, 0x07, 0x51, 0x2c, 0x5f,
0x64, 0x93, 0x60, 0xca, 0xe6, 0x7b, 0x11, 0x8b, 0xd8, 0x9e, 0x76, 0x9c, 0x64, 0x67, 0xda, 0xd2,
0x86, 0x5e, 0x19, 0x80, 0x4e, 0x2f, 0x62, 0x2c, 0x4a, 0xf0, 0xca, 0x4b, 0xc6, 0x73, 0x14, 0x32,
0x9c, 0x2f, 0x8c, 0x83, 0xbf, 0x0b, 0x3b, 0xe3, 0x58, 0x9c, 0x9f, 0x8a, 0x30, 0x42, 0x8a, 0x3f,
0x66, 0x28, 0x24, 0xb9, 0x0f, 0xee, 0x59, 0x9c, 0x48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0xb8, 0x49, 0xc1, 0x09, 0x00,
0x00,
}

View File

@ -17,6 +17,7 @@ service Control {
}
message DiskUsageRequest {
string filter = 1;
}
message DiskUsageResponse {
@ -28,6 +29,11 @@ message UsageRecord {
bool Mutable = 2;
bool InUse = 3;
int64 Size = 4;
string Parent = 5;
google.protobuf.Timestamp CreatedAt = 6 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
google.protobuf.Timestamp LastUsedAt = 7 [(gogoproto.stdtime) = true];
int64 UsageCount = 8;
string Description = 9;
}
message SolveRequest {

101
cache/manager.go vendored
View File

@ -3,6 +3,7 @@ package cache
import (
"context"
"sync"
"time"
"github.com/Sirupsen/logrus"
cdsnapshot "github.com/containerd/containerd/snapshot"
@ -27,8 +28,8 @@ type ManagerOpt struct {
}
type Accessor interface {
Get(ctx context.Context, id string) (ImmutableRef, error)
New(ctx context.Context, s ImmutableRef, opt ...RefOption) (MutableRef, error)
Get(ctx context.Context, id string, opts ...RefOption) (ImmutableRef, error)
New(ctx context.Context, s ImmutableRef, opts ...RefOption) (MutableRef, error)
GetMutable(ctx context.Context, id string) (MutableRef, error) // Rebase?
}
@ -87,14 +88,14 @@ func (cm *cacheManager) Close() error {
return cm.md.Close()
}
func (cm *cacheManager) Get(ctx context.Context, id string) (ImmutableRef, error) {
func (cm *cacheManager) Get(ctx context.Context, id string, opts ...RefOption) (ImmutableRef, error) {
cm.mu.Lock()
defer cm.mu.Unlock()
return cm.get(ctx, id)
return cm.get(ctx, id, opts...)
}
func (cm *cacheManager) get(ctx context.Context, id string) (ImmutableRef, error) {
rec, err := cm.load(ctx, id)
func (cm *cacheManager) get(ctx context.Context, id string, opts ...RefOption) (ImmutableRef, error) {
rec, err := cm.load(ctx, id, opts...)
if err != nil {
return nil, err
}
@ -114,7 +115,7 @@ func (cm *cacheManager) get(ctx context.Context, id string) (ImmutableRef, error
return rec.ref(), nil
}
func (cm *cacheManager) load(ctx context.Context, id string) (*cacheRecord, error) {
func (cm *cacheManager) load(ctx context.Context, id string, opts ...RefOption) (*cacheRecord, error) {
if rec, ok := cm.records[id]; ok {
return rec, nil
}
@ -144,7 +145,7 @@ func (cm *cacheManager) load(ctx context.Context, id string) (*cacheRecord, erro
var parent ImmutableRef
if info.Parent != "" {
parent, err = cm.get(ctx, info.Parent)
parent, err = cm.get(ctx, info.Parent, opts...)
if err != nil {
return nil, err
}
@ -157,6 +158,14 @@ func (cm *cacheManager) load(ctx context.Context, id string) (*cacheRecord, erro
parent: parent,
md: &md,
}
if err := initializeMetadata(rec, opts...); err != nil {
if parent != nil {
parent.Release(ctx)
}
return nil, err
}
cm.records[id] = rec
return rec, nil
}
@ -195,13 +204,11 @@ func (cm *cacheManager) New(ctx context.Context, s ImmutableRef, opts ...RefOpti
md: &md,
}
for _, opt := range opts {
if err := opt(rec); err != nil {
if parent != nil {
parent.Release(ctx)
}
return nil, err
if err := initializeMetadata(rec, opts...); err != nil {
if parent != nil {
parent.Release(ctx)
}
return nil, err
}
cm.mu.Lock()
@ -248,10 +255,14 @@ func (cm *cacheManager) DiskUsage(ctx context.Context) ([]*client.UsageInfo, err
cm.mu.Lock()
type cacheUsageInfo struct {
refs int
parent string
size int64
mutable bool
refs int
parent string
size int64
mutable bool
createdAt time.Time
usageCount int
lastUsedAt *time.Time
description string
}
m := make(map[string]*cacheUsageInfo, len(cm.records))
@ -264,10 +275,15 @@ func (cm *cacheManager) DiskUsage(ctx context.Context) ([]*client.UsageInfo, err
cr.mu.Unlock()
continue
}
usageCount, lastUsedAt := getLastUsed(cr.md)
c := &cacheUsageInfo{
refs: len(cr.refs),
mutable: cr.mutable,
size: getSize(cr.md),
refs: len(cr.refs),
mutable: cr.mutable,
size: getSize(cr.md),
createdAt: getCreatedAt(cr.md),
usageCount: usageCount,
lastUsedAt: lastUsedAt,
description: getDescription(cr.md),
}
if cr.parent != nil {
c.parent = cr.parent.ID()
@ -298,10 +314,15 @@ func (cm *cacheManager) DiskUsage(ctx context.Context) ([]*client.UsageInfo, err
var du []*client.UsageInfo
for id, cr := range m {
c := &client.UsageInfo{
ID: id,
Mutable: cr.mutable,
InUse: cr.refs > 0,
Size: cr.size,
ID: id,
Mutable: cr.mutable,
InUse: cr.refs > 0,
Size: cr.size,
Parent: cr.parent,
CreatedAt: cr.createdAt,
Description: cr.description,
LastUsedAt: cr.lastUsedAt,
UsageCount: cr.usageCount,
}
du = append(du, c)
}
@ -353,5 +374,33 @@ type withMetadata interface {
}
func CachePolicyRetain(m withMetadata) error {
return setCachePolicy(m.Metadata(), cachePolicyRetain)
return queueCachePolicy(m.Metadata(), cachePolicyRetain)
}
func WithDescription(descr string) RefOption {
return func(m withMetadata) error {
return queueDescription(m.Metadata(), descr)
}
}
func initializeMetadata(m withMetadata, opts ...RefOption) error {
md := m.Metadata()
if tm := getCreatedAt(md); !tm.IsZero() {
return nil
}
for _, opt := range opts {
if err := opt(m); err != nil {
return err
}
}
if err := queueCreatedAt(md); err != nil {
return err
}
if err := md.Commit(); err != nil {
return err
}
return nil
}

100
cache/metadata.go vendored
View File

@ -1,6 +1,8 @@
package cache
import (
"time"
"github.com/boltdb/bolt"
"github.com/moby/buildkit/cache/metadata"
"github.com/pkg/errors"
@ -18,6 +20,10 @@ const keySize = "snapshot.size"
const keyEqualMutable = "cache.equalMutable"
const keyEqualImmutable = "cache.equalImmutable"
const keyCachePolicy = "cache.cachePolicy"
const keyDescription = "cache.description"
const keyCreatedAt = "cache.createdAt"
const keyLastUsedAt = "cache.lastUsedAt"
const keyUsageCount = "cache.usageCount"
func setSize(si *metadata.StorageItem, s int64) error {
v, err := metadata.NewValue(s)
@ -72,14 +78,15 @@ func clearEqualMutable(si *metadata.StorageItem) error {
return nil
}
func setCachePolicy(si *metadata.StorageItem, p cachePolicy) error {
func queueCachePolicy(si *metadata.StorageItem, p cachePolicy) error {
v, err := metadata.NewValue(p)
if err != nil {
return errors.Wrap(err, "failed to create size value")
return errors.Wrap(err, "failed to create cachePolicy value")
}
return si.Update(func(b *bolt.Bucket) error {
si.Queue(func(b *bolt.Bucket) error {
return si.SetValue(b, keyCachePolicy, v)
})
return nil
}
func getCachePolicy(si *metadata.StorageItem) cachePolicy {
@ -93,3 +100,90 @@ func getCachePolicy(si *metadata.StorageItem) cachePolicy {
}
return p
}
func queueDescription(si *metadata.StorageItem, descr string) error {
v, err := metadata.NewValue(descr)
if err != nil {
return errors.Wrap(err, "failed to create description value")
}
si.Queue(func(b *bolt.Bucket) error {
return si.SetValue(b, keyDescription, v)
})
return nil
}
func getDescription(si *metadata.StorageItem) string {
v := si.Get(keyDescription)
if v == nil {
return ""
}
var str string
if err := v.Unmarshal(&str); err != nil {
return ""
}
return str
}
func queueCreatedAt(si *metadata.StorageItem) error {
v, err := metadata.NewValue(time.Now().UnixNano())
if err != nil {
return errors.Wrap(err, "failed to create createdAt value")
}
si.Queue(func(b *bolt.Bucket) error {
return si.SetValue(b, keyCreatedAt, v)
})
return nil
}
func getCreatedAt(si *metadata.StorageItem) time.Time {
v := si.Get(keyCreatedAt)
if v == nil {
return time.Time{}
}
var tm int64
if err := v.Unmarshal(&tm); err != nil {
return time.Time{}
}
return time.Unix(tm/1e9, tm%1e9)
}
func getLastUsed(si *metadata.StorageItem) (int, *time.Time) {
v := si.Get(keyUsageCount)
if v == nil {
return 0, nil
}
var usageCount int
if err := v.Unmarshal(&usageCount); err != nil {
return 0, nil
}
v = si.Get(keyLastUsedAt)
if v == nil {
return usageCount, nil
}
var lastUsedTs int64
if err := v.Unmarshal(&lastUsedTs); err != nil || lastUsedTs == 0 {
return usageCount, nil
}
tm := time.Unix(lastUsedTs/1e9, lastUsedTs%1e9)
return usageCount, &tm
}
func updateLastUsed(si *metadata.StorageItem) error {
count, _ := getLastUsed(si)
count++
v, err := metadata.NewValue(count)
if err != nil {
return errors.Wrap(err, "failed to create usageCount value")
}
v2, err := metadata.NewValue(time.Now().UnixNano())
if err != nil {
return errors.Wrap(err, "failed to create lastUsedAt value")
}
return si.Update(func(b *bolt.Bucket) error {
if err := si.SetValue(b, keyUsageCount, v); err != nil {
return err
}
return si.SetValue(b, keyLastUsedAt, v2)
})
}

13
cache/refs.go vendored
View File

@ -184,6 +184,8 @@ func (sr *immutableRef) release(ctx context.Context) error {
sr.viewMount = nil
}
updateLastUsed(sr.md)
delete(sr.refs, sr)
if len(sr.refs) == 0 {
@ -240,6 +242,16 @@ func (sr *mutableRef) commit(ctx context.Context) (ImmutableRef, error) {
md: &md,
}
if descr := getDescription(sr.md); descr != "" {
if err := queueDescription(&md, descr); err != nil {
return nil, err
}
}
if err := initializeMetadata(rec); err != nil {
return nil, err
}
sr.cm.records[id] = rec
if err := sr.md.Commit(); err != nil {
@ -279,6 +291,7 @@ func (sr *mutableRef) Release(ctx context.Context) error {
func (sr *mutableRef) release(ctx context.Context) error {
delete(sr.refs, sr)
updateLastUsed(sr.md)
if getCachePolicy(sr.md) != cachePolicyRetain {
if sr.equalImmutable != nil {
if getCachePolicy(sr.equalImmutable.md) == cachePolicyRetain {

View File

@ -3,6 +3,7 @@ package client
import (
"context"
"sort"
"time"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/pkg/errors"
@ -13,8 +14,12 @@ type UsageInfo struct {
Mutable bool
InUse bool
Size int64
// Meta string
// LastUsed time.Time
CreatedAt time.Time
LastUsedAt *time.Time
UsageCount int
Parent string
Description string
}
func (c *Client) DiskUsage(ctx context.Context) ([]*UsageInfo, error) {
@ -27,10 +32,15 @@ func (c *Client) DiskUsage(ctx context.Context) ([]*UsageInfo, error) {
for _, d := range resp.Record {
du = append(du, &UsageInfo{
ID: d.ID,
Mutable: d.Mutable,
InUse: d.InUse,
Size: d.Size_,
ID: d.ID,
Mutable: d.Mutable,
InUse: d.InUse,
Size: d.Size_,
Parent: d.Parent,
CreatedAt: d.CreatedAt,
Description: d.Description,
UsageCount: int(d.UsageCount),
LastUsedAt: d.LastUsedAt,
})
}

View File

@ -3,10 +3,12 @@ package main
import (
"context"
"fmt"
"io"
"os"
"text/tabwriter"
units "github.com/docker/go-units"
"github.com/moby/buildkit/client"
"github.com/urfave/cli"
)
@ -14,6 +16,12 @@ var diskUsageCommand = cli.Command{
Name: "du",
Usage: "disk usage",
Action: diskUsage,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "verbose, v",
Usage: "Verbose output",
},
},
}
func diskUsage(clicontext *cli.Context) error {
@ -29,10 +37,47 @@ func diskUsage(clicontext *cli.Context) error {
tw := tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0)
fmt.Fprintln(tw, "ID\tRECLAIMABLE\tSIZE\tLAST ACCESSED")
if clicontext.Bool("verbose") {
printVerbose(tw, du)
} else {
printTable(tw, du)
}
total := int64(0)
reclaimable := int64(0)
printSummary(tw, du)
return nil
}
func printKV(w io.Writer, k string, v interface{}) {
fmt.Fprintf(w, "%s:\t%v\n", k, v)
}
func printVerbose(tw *tabwriter.Writer, du []*client.UsageInfo) {
for _, di := range du {
printKV(tw, "ID", di.ID)
if di.Parent != "" {
printKV(tw, "Parent", di.Parent)
}
printKV(tw, "Created at", di.CreatedAt)
printKV(tw, "Mutable", di.Mutable)
printKV(tw, "Reclaimable", !di.InUse)
printKV(tw, "Size", units.HumanSize(float64(di.Size)))
if di.Description != "" {
printKV(tw, "Description", di.Description)
}
printKV(tw, "Usage count", di.UsageCount)
if di.LastUsedAt != nil {
printKV(tw, "Last used", di.LastUsedAt)
}
fmt.Fprintf(tw, "\n")
}
tw.Flush()
}
func printTable(tw *tabwriter.Writer, du []*client.UsageInfo) {
fmt.Fprintln(tw, "ID\tRECLAIMABLE\tSIZE\tLAST ACCESSED")
for _, di := range du {
id := di.ID
@ -40,6 +85,17 @@ func diskUsage(clicontext *cli.Context) error {
id += "*"
}
fmt.Fprintf(tw, "%s\t%v\t%s\t\n", id, !di.InUse, units.HumanSize(float64(di.Size)))
}
tw.Flush()
}
func printSummary(tw *tabwriter.Writer, du []*client.UsageInfo) {
total := int64(0)
reclaimable := int64(0)
for _, di := range du {
if di.Size > 0 {
total += di.Size
if !di.InUse {
@ -48,12 +104,8 @@ func diskUsage(clicontext *cli.Context) error {
}
}
tw.Flush()
tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0)
fmt.Fprintf(tw, "Reclaimable:\t%s\n", units.HumanSize(float64(reclaimable)))
fmt.Fprintf(tw, "Total:\t%s\n", units.HumanSize(float64(total)))
tw.Flush()
return nil
}

View File

@ -60,10 +60,15 @@ func (c *Controller) DiskUsage(ctx context.Context, _ *controlapi.DiskUsageReque
resp := &controlapi.DiskUsageResponse{}
for _, r := range du {
resp.Record = append(resp.Record, &controlapi.UsageRecord{
ID: r.ID,
Mutable: r.Mutable,
InUse: r.InUse,
Size_: r.Size,
ID: r.ID,
Mutable: r.Mutable,
InUse: r.InUse,
Size_: r.Size,
Parent: r.Parent,
UsageCount: int64(r.UsageCount),
Description: r.Description,
CreatedAt: r.CreatedAt,
LastUsedAt: r.LastUsedAt,
})
}
return resp, nil

View File

@ -2,7 +2,9 @@ package solver
import (
"encoding/json"
"fmt"
"sort"
"strings"
"github.com/moby/buildkit/cache"
"github.com/moby/buildkit/solver/pb"
@ -80,7 +82,7 @@ func (e *execOp) Run(ctx context.Context, inputs []Reference) ([]Reference, erro
if m.Readonly && ref != nil {
outputs = append(outputs, newSharedRef(ref).Clone())
} else {
active, err := e.cm.New(ctx, ref) // TODO: should be method
active, err := e.cm.New(ctx, ref, cache.WithDescription(fmt.Sprintf("mount %s from exec %s", m.Dest, strings.Join(e.op.Meta.Args, " ")))) // TODO: should be method
if err != nil {
return nil, err
}

View File

@ -3,6 +3,7 @@ package containerimage
import (
gocontext "context"
"encoding/json"
"fmt"
"net/http"
"sync"
"time"
@ -149,7 +150,7 @@ func (p *puller) Snapshot(ctx context.Context) (cache.ImmutableRef, error) {
}
unpackProgressDone(nil)
return p.is.CacheAccessor.Get(ctx, chainid)
return p.is.CacheAccessor.Get(ctx, chainid, cache.WithDescription(fmt.Sprintf("pulled from %s", p.ref)))
}
func (is *imageSource) unpack(ctx context.Context, desc ocispec.Descriptor) (string, error) {

View File

@ -2,6 +2,7 @@ package git
import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
@ -78,7 +79,7 @@ func (gs *gitSource) mountRemote(ctx context.Context, remote string) (target str
initializeRepo := false
if remoteRef == nil {
remoteRef, err = gs.cache.New(ctx, nil, cache.CachePolicyRetain)
remoteRef, err = gs.cache.New(ctx, nil, cache.CachePolicyRetain, cache.WithDescription(fmt.Sprintf("shared git repo for %s", remote)))
if err != nil {
return "", nil, errors.Wrapf(err, "failed to create new mutable for %s", remote)
}
@ -262,7 +263,7 @@ func (gs *gitSourceHandler) Snapshot(ctx context.Context) (out cache.ImmutableRe
}
}
checkoutRef, err := gs.cache.New(ctx, nil)
checkoutRef, err := gs.cache.New(ctx, nil, cache.WithDescription(fmt.Sprintf("git snapshot for %s#%s", gs.src.Remote, ref)))
if err != nil {
return nil, errors.Wrapf(err, "failed to create new mutable for %s", gs.src.Remote)
}

View File

@ -1,6 +1,7 @@
package local
import (
"fmt"
"time"
"github.com/Sirupsen/logrus"
@ -106,7 +107,7 @@ func (ls *localSourceHandler) Snapshot(ctx context.Context) (out cache.Immutable
}
if mutable == nil {
m, err := ls.cm.New(ctx, nil, cache.CachePolicyRetain)
m, err := ls.cm.New(ctx, nil, cache.CachePolicyRetain, cache.WithDescription(fmt.Sprintf("local source for %s", ls.src.Name)))
if err != nil {
return nil, err
}