maintenance.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2016 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package clientv3
  15. import (
  16. "github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
  17. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  18. )
  19. type (
  20. DefragmentResponse pb.DefragmentResponse
  21. )
  22. type Maintenance interface {
  23. // Defragment defragments storage backend of the etcd member with given endpoint.
  24. // Defragment is only needed when deleting a large number of keys and want to reclaim
  25. // the resources.
  26. // Defragment is an expensive operation. User should avoid defragmenting multiple members
  27. // at the same time.
  28. // To defragment multiple members in the cluster, user need to call defragment multiple
  29. // times with different endpoints.
  30. Defragment(ctx context.Context, endpoint string) (*DefragmentResponse, error)
  31. }
  32. type maintenance struct {
  33. c *Client
  34. }
  35. func (m *maintenance) Defragment(ctx context.Context, endpoint string) (*DefragmentResponse, error) {
  36. conn, err := m.c.Dial(endpoint)
  37. if err != nil {
  38. return nil, err
  39. }
  40. remote := pb.NewMaintenanceClient(conn)
  41. resp, err := remote.Defragment(ctx, &pb.DefragmentRequest{})
  42. if err != nil {
  43. return nil, err
  44. }
  45. return (*DefragmentResponse)(resp), nil
  46. }