From 123af61c0bd897c0892d7a0fb51574a78698de8a Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 2 Jan 2020 16:38:21 -0800 Subject: [PATCH] Add Cleanup to snapshot API Cleanup is an optional method a snapshotter may implement. Cleanup can be used to cleanup resources after a snapshot has been removed. This function allows a snapshotter to defer longer resource cleanup until after snapshot removals are completed. Adding this to the API allows proxy snapshotters to leverage this enhancement. Signed-off-by: Derek McGowan --- api/next.pb.txt | 15 + api/services/snapshots/v1/snapshots.pb.go | 345 ++++++++++++++++++---- api/services/snapshots/v1/snapshots.proto | 5 + contrib/snapshotservice/service.go | 13 + metadata/snapshot.go | 9 +- services/snapshots/service.go | 19 ++ snapshots/proxy/proxy.go | 7 + snapshots/snapshotter.go | 11 + 8 files changed, 354 insertions(+), 70 deletions(-) diff --git a/api/next.pb.txt b/api/next.pb.txt index f5e29bfe0f0b..e7dc63663be1 100755 --- a/api/next.pb.txt +++ b/api/next.pb.txt @@ -3446,6 +3446,16 @@ file { json_name: "inodes" } } + message_type { + name: "CleanupRequest" + field { + name: "snapshotter" + number: 1 + label: LABEL_OPTIONAL + type: TYPE_STRING + json_name: "snapshotter" + } + } enum_type { name: "Kind" value { @@ -3529,6 +3539,11 @@ file { input_type: ".containerd.services.snapshots.v1.UsageRequest" output_type: ".containerd.services.snapshots.v1.UsageResponse" } + method { + name: "Cleanup" + input_type: ".containerd.services.snapshots.v1.CleanupRequest" + output_type: ".google.protobuf.Empty" + } } options { go_package: "github.com/containerd/containerd/api/services/snapshots/v1;snapshots" diff --git a/api/services/snapshots/v1/snapshots.pb.go b/api/services/snapshots/v1/snapshots.pb.go index b5e34a06de87..07c985624f7a 100644 --- a/api/services/snapshots/v1/snapshots.pb.go +++ b/api/services/snapshots/v1/snapshots.pb.go @@ -777,6 +777,45 @@ func (m *UsageResponse) XXX_DiscardUnknown() { var xxx_messageInfo_UsageResponse proto.InternalMessageInfo +type CleanupRequest struct { + Snapshotter string `protobuf:"bytes,1,opt,name=snapshotter,proto3" json:"snapshotter,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CleanupRequest) Reset() { *m = CleanupRequest{} } +func (*CleanupRequest) ProtoMessage() {} +func (*CleanupRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_cfc0ddf12791f168, []int{17} +} +func (m *CleanupRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *CleanupRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_CleanupRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalTo(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *CleanupRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_CleanupRequest.Merge(m, src) +} +func (m *CleanupRequest) XXX_Size() int { + return m.Size() +} +func (m *CleanupRequest) XXX_DiscardUnknown() { + xxx_messageInfo_CleanupRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_CleanupRequest proto.InternalMessageInfo + func init() { proto.RegisterEnum("containerd.services.snapshots.v1.Kind", Kind_name, Kind_value) proto.RegisterType((*PrepareSnapshotRequest)(nil), "containerd.services.snapshots.v1.PrepareSnapshotRequest") @@ -800,6 +839,7 @@ func init() { proto.RegisterType((*ListSnapshotsResponse)(nil), "containerd.services.snapshots.v1.ListSnapshotsResponse") proto.RegisterType((*UsageRequest)(nil), "containerd.services.snapshots.v1.UsageRequest") proto.RegisterType((*UsageResponse)(nil), "containerd.services.snapshots.v1.UsageResponse") + proto.RegisterType((*CleanupRequest)(nil), "containerd.services.snapshots.v1.CleanupRequest") } func init() { @@ -807,71 +847,73 @@ func init() { } var fileDescriptor_cfc0ddf12791f168 = []byte{ - // 1022 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x4f,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xfb, 0xca, 0x41, 0x19, 0x90, 0x8f, 0x2a, 0xe5, 0x67, 0x29, 0x49, - 0x59, 0x3a, 0x3b, 0x57, 0x6f, 0xb1, 0x25, 0x76, 0x79, 0x21, 0x05, 0xe2, 0xc5, 0xd2, 0x41, 0xe5, - 0xa8, 0x9c, 0x8a, 0x2a, 0x2b, 0x67, 0xe7, 0x2a, 0xb0, 0x95, 0x62, 0x95, 0x5a, 0x3d, 0x8c, 0x54, - 0x48, 0x94, 0x9e, 0xec, 0xed, 0x55, 0x0e, 0x0e, 0xca, 0xdb, 0xa9, 0x98, 0xf2, 0xee, 0xd9, 0xb9, - 0xba, 0xcc, 0x96, 0xbd, 0x2e, 0x4a, 0x71, 0x4d, 0x59, 0x7a, 0xfd, 0x63, 0x2e, 0xf2, 0xcb, 0x4f, - 0x39, 0xce, 0xa0, 0xf0, 0xcf, 0x22, 0x24, 0x06, 0x1a, 0xa3, 0xef, 0x60, 0x51, 0x3c, 0x32, 0xd0, - 0x46, 0xd8, 0x87, 0x8f, 0xf2, 0x30, 0x84, 0xa5, 0x10, 0xb1, 0x0b, 0x32, 0x8f, 0xf0, 0xe3, 0x50, - 0x8f, 0x05, 0xe5, 0xfe, 0xac, 0x66, 0xc2, 0x6d, 0x13, 0xe2, 0xde, 0x3d, 0x8c, 0xf4, 0xe9, 0x08, - 0x57, 0xae, 0x7d, 0xe5, 0x6e, 0x70, 0x03, 0xe1, 0xec, 0x18, 0xe2, 0x5e, 0x32, 0xd0, 0x83, 0x90, - 0x97, 0x9f, 0x92, 0xb9, 0x56, 0xf3, 0x65, 0xf6, 0x48, 0x67, 0xd0, 0xde, 0x63, 0x20, 0x08, 0xf4, - 0xc4, 0x67, 0xc3, 0xff, 0x42, 0x77, 0x41, 0x66, 0x3d, 0x35, 0x48, 0x66, 0x26, 0x5c, 0xa4, 0x41, - 0x32, 0x33, 0xb1, 0x65, 0x7f, 0x0b, 0x71, 0xaf, 0x6b, 0x05, 0x89, 0x68, 0x62, 0x67, 0x56, 0x36, - 0x66, 0x37, 0x14, 0xce, 0xfb, 0x20, 0xb3, 0x16, 0x84, 0x02, 0x90, 0x9f, 0xd4, 0xfe, 0x94, 0x07, - 0x33, 0xdb, 0x79, 0x8e, 0xef, 0x4a, 0xe8, 0x14, 0x16, 0x78, 0x7b, 0x41, 0x5a, 0x00, 0xf6, 0x23, - 0xbd, 0x4c, 0xd1, 0x03, 0xef, 0xf7, 0x7c, 0x6d, 0x7d, 0x75, 0xf1, 0x26, 0x17, 0xf9, 0xed, 0x4d, - 0x2e, 0xf2, 0xfd, 0x65, 0x4e, 0xba, 0xb8, 0xcc, 0x49, 0xbf, 0x5e, 0xe6, 0xa4, 0x3f, 0x2f, 0x73, - 0xd2, 0x8b, 0xed, 0xf0, 0x7f, 0xa3, 0x9b, 0x83, 0xc9, 0xf3, 0xc8, 0x49, 0x9c, 0x1f, 0xa5, 0x8f, - 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x3b, 0x8b, 0xa6, 0xa4, 0xde, 0x0e, 0x00, 0x00, + // 1047 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x4f, 0x6f, 0x1b, 0x45, + 0x14, 0xf7, 0xda, 0x5b, 0x27, 0x79, 0x4e, 0x82, 0x99, 0x3a, 0xae, 0xb5, 0x20, 0x67, 0xe5, 0x03, + 0x8a, 0x38, 0xec, 0xb6, 0x46, 0xb4, 0x69, 0x73, 0xc1, 0x71, 0x0c, 0x72, 0xd2, 0xa4, 0x68, 0xf3, + 0xa7, 0x4d, 0x41, 0x54, 0x1b, 0x7b, 0xec, 0xac, 0xec, 0xfd, 0x83, 0x67, 0xec, 0xca, 0x20, 0x21, + 0x8e, 0x55, 0x4e, 0x7c, 0x81, 0x9c, 0xe0, 0x43, 0x20, 0x3e, 0x41, 0x8e, 0x48, 0x5c, 0x38, 0x01, + 0xcd, 0x97, 0xe0, 0x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f6, 0x57, 0x57, 0xaf, 0xb3, 0x91, 0xdf, 0x5f, 0x67, 0x23, 0xdf, 0x5f, 0x67, 0xa5, 0xab, + 0xeb, 0xac, 0xf4, 0xeb, 0x75, 0x56, 0xfa, 0xeb, 0x3a, 0x2b, 0x3d, 0xdf, 0x99, 0xfd, 0xb7, 0x78, + 0xab, 0x37, 0x79, 0x16, 0x39, 0x8b, 0xf3, 0x88, 0x1f, 0xfd, 0x17, 0x00, 0x00, 0xff, 0xff, 0x20, + 0x9c, 0x85, 0x7f, 0x67, 0x0f, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -895,6 +937,7 @@ type SnapshotsClient interface { Update(ctx context.Context, in *UpdateSnapshotRequest, opts ...grpc.CallOption) (*UpdateSnapshotResponse, error) List(ctx context.Context, in *ListSnapshotsRequest, opts ...grpc.CallOption) (Snapshots_ListClient, error) Usage(ctx context.Context, in *UsageRequest, opts ...grpc.CallOption) (*UsageResponse, error) + Cleanup(ctx context.Context, in *CleanupRequest, opts ...grpc.CallOption) (*types1.Empty, error) } type snapshotsClient struct { @@ -1009,6 +1052,15 @@ func (c *snapshotsClient) Usage(ctx context.Context, in *UsageRequest, opts ...g return out, nil } +func (c *snapshotsClient) Cleanup(ctx context.Context, in *CleanupRequest, opts ...grpc.CallOption) (*types1.Empty, error) { + out := new(types1.Empty) + err := c.cc.Invoke(ctx, "/containerd.services.snapshots.v1.Snapshots/Cleanup", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // SnapshotsServer is the server API for Snapshots service. type SnapshotsServer interface { Prepare(context.Context, *PrepareSnapshotRequest) (*PrepareSnapshotResponse, error) @@ -1020,6 +1072,7 @@ type SnapshotsServer interface { Update(context.Context, *UpdateSnapshotRequest) (*UpdateSnapshotResponse, error) List(*ListSnapshotsRequest, Snapshots_ListServer) error Usage(context.Context, *UsageRequest) (*UsageResponse, error) + Cleanup(context.Context, *CleanupRequest) (*types1.Empty, error) } func RegisterSnapshotsServer(s *grpc.Server, srv SnapshotsServer) { @@ -1191,6 +1244,24 @@ func _Snapshots_Usage_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Snapshots_Cleanup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CleanupRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SnapshotsServer).Cleanup(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/containerd.services.snapshots.v1.Snapshots/Cleanup", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SnapshotsServer).Cleanup(ctx, req.(*CleanupRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Snapshots_serviceDesc = grpc.ServiceDesc{ ServiceName: "containerd.services.snapshots.v1.Snapshots", HandlerType: (*SnapshotsServer)(nil), @@ -1227,6 +1298,10 @@ var _Snapshots_serviceDesc = grpc.ServiceDesc{ MethodName: "Usage", Handler: _Snapshots_Usage_Handler, }, + { + MethodName: "Cleanup", + Handler: _Snapshots_Cleanup_Handler, + }, }, Streams: []grpc.StreamDesc{ { @@ -1917,6 +1992,33 @@ func (m *UsageResponse) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *CleanupRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *CleanupRequest) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.Snapshotter) > 0 { + dAtA[i] = 0xa + i++ + i = encodeVarintSnapshots(dAtA, i, uint64(len(m.Snapshotter))) + i += copy(dAtA[i:], m.Snapshotter) + } + if m.XXX_unrecognized != nil { + i += copy(dAtA[i:], m.XXX_unrecognized) + } + return i, nil +} + func encodeVarintSnapshots(dAtA []byte, offset int, v uint64) int { for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -2299,6 +2401,22 @@ func (m *UsageResponse) Size() (n int) { return n } +func (m *CleanupRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Snapshotter) + if l > 0 { + n += 1 + l + sovSnapshots(uint64(l)) + } + if m.XXX_unrecognized != nil { + n += len(m.XXX_unrecognized) + } + return n +} + func sovSnapshots(x uint64) (n int) { for { n++ @@ -2561,6 +2679,17 @@ func (this *UsageResponse) String() string { }, "") return s } +func (this *CleanupRequest) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&CleanupRequest{`, + `Snapshotter:` + fmt.Sprintf("%v", this.Snapshotter) + `,`, + `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, + `}`, + }, "") + return s +} func valueToStringSnapshots(v interface{}) string { rv := reflect.ValueOf(v) if rv.IsNil() { @@ -5093,6 +5222,92 @@ func (m *UsageResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *CleanupRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSnapshots + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: CleanupRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: CleanupRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Snapshotter", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowSnapshots + } + 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 ErrInvalidLengthSnapshots + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthSnapshots + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Snapshotter = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipSnapshots(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthSnapshots + } + if (iNdEx + skippy) < 0 { + return ErrInvalidLengthSnapshots + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipSnapshots(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/api/services/snapshots/v1/snapshots.proto b/api/services/snapshots/v1/snapshots.proto index 082c96a60bab..981d8a6bac7d 100644 --- a/api/services/snapshots/v1/snapshots.proto +++ b/api/services/snapshots/v1/snapshots.proto @@ -21,6 +21,7 @@ service Snapshots { rpc Update(UpdateSnapshotRequest) returns (UpdateSnapshotResponse); rpc List(ListSnapshotsRequest) returns (stream ListSnapshotsResponse); rpc Usage(UsageRequest) returns (UsageResponse); + rpc Cleanup(CleanupRequest) returns (google.protobuf.Empty); } message PrepareSnapshotRequest { @@ -160,3 +161,7 @@ message UsageResponse { int64 size = 1; int64 inodes = 2; } + +message CleanupRequest { + string snapshotter = 1; +} diff --git a/contrib/snapshotservice/service.go b/contrib/snapshotservice/service.go index c1d1a4230552..6542333f9f36 100644 --- a/contrib/snapshotservice/service.go +++ b/contrib/snapshotservice/service.go @@ -163,6 +163,19 @@ func (s service) Usage(ctx context.Context, ur *snapshotsapi.UsageRequest) (*sna }, nil } +func (s service) Cleanup(ctx context.Context, cr *snapshotsapi.CleanupRequest) (*ptypes.Empty, error) { + c, ok := s.sn.(snapshots.Cleaner) + if !ok { + return nil, errdefs.ToGRPCf(errdefs.ErrNotImplemented, "snapshotter does not implement Cleanup method") + } + + if err := c.Cleanup(ctx); err != nil { + return nil, errdefs.ToGRPC(err) + } + + return empty, nil +} + func fromKind(kind snapshots.Kind) snapshotsapi.Kind { if kind == snapshots.KindActive { return snapshotsapi.KindActive diff --git a/metadata/snapshot.go b/metadata/snapshot.go index 73da78467c4a..389aeda45eca 100644 --- a/metadata/snapshot.go +++ b/metadata/snapshot.go @@ -791,18 +791,17 @@ func validateSnapshot(info *snapshots.Info) error { return nil } -type cleaner interface { - Cleanup(ctx context.Context) error -} - func (s *snapshotter) garbageCollect(ctx context.Context) (d time.Duration, err error) { s.l.Lock() t1 := time.Now() defer func() { s.l.Unlock() if err == nil { - if c, ok := s.Snapshotter.(cleaner); ok { + if c, ok := s.Snapshotter.(snapshots.Cleaner); ok { err = c.Cleanup(ctx) + if errdefs.IsNotImplemented(err) { + err = nil + } } } if err == nil { diff --git a/services/snapshots/service.go b/services/snapshots/service.go index d37a96585d99..1b58ac02c96d 100644 --- a/services/snapshots/service.go +++ b/services/snapshots/service.go @@ -255,6 +255,25 @@ func (s *service) Usage(ctx context.Context, ur *snapshotsapi.UsageRequest) (*sn return fromUsage(usage), nil } +func (s *service) Cleanup(ctx context.Context, cr *snapshotsapi.CleanupRequest) (*ptypes.Empty, error) { + sn, err := s.getSnapshotter(cr.Snapshotter) + if err != nil { + return nil, err + } + + c, ok := sn.(snapshots.Cleaner) + if !ok { + return nil, errdefs.ToGRPCf(errdefs.ErrNotImplemented, "snapshotter does not implement Cleanup method") + } + + err = c.Cleanup(ctx) + if err != nil { + return nil, errdefs.ToGRPC(err) + } + + return empty, nil +} + func fromKind(kind snapshots.Kind) snapshotsapi.Kind { if kind == snapshots.KindActive { return snapshotsapi.KindActive diff --git a/snapshots/proxy/proxy.go b/snapshots/proxy/proxy.go index d9803c7c8cee..00c320c60872 100644 --- a/snapshots/proxy/proxy.go +++ b/snapshots/proxy/proxy.go @@ -184,6 +184,13 @@ func (p *proxySnapshotter) Close() error { return nil } +func (p *proxySnapshotter) Cleanup(ctx context.Context) error { + _, err := p.client.Cleanup(ctx, &snapshotsapi.CleanupRequest{ + Snapshotter: p.snapshotterName, + }) + return errdefs.FromGRPC(err) +} + func toKind(kind snapshotsapi.Kind) snapshots.Kind { if kind == snapshotsapi.KindActive { return snapshots.KindActive diff --git a/snapshots/snapshotter.go b/snapshots/snapshotter.go index e884cd64711a..edf29d89e6d1 100644 --- a/snapshots/snapshotter.go +++ b/snapshots/snapshotter.go @@ -341,6 +341,17 @@ type Snapshotter interface { Close() error } +// Cleaner defines a type capable of performing asynchronous resource cleanup. +// The Cleaner interface should be used by snapshotters which implement fast +// removal and deferred resource cleanup. This prevents snapshots from needing +// to perform lengthy resource cleanup before acknowledging a snapshot key +// has been removed and available for re-use. This is also useful when +// performing multi-key removal with the intent of cleaning up all the +// resources after each snapshot key has been removed. +type Cleaner interface { + Cleanup(ctx context.Context) error +} + // Opt allows setting mutable snapshot properties on creation type Opt func(info *Info) error