maintenance.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 v3rpc
  15. import (
  16. "github.com/coreos/etcd/etcdserver"
  17. pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
  18. "github.com/coreos/etcd/storage/backend"
  19. "golang.org/x/net/context"
  20. )
  21. type BackendGetter interface {
  22. Backend() backend.Backend
  23. }
  24. type Alarmer interface {
  25. Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error)
  26. }
  27. type maintenanceServer struct {
  28. bg BackendGetter
  29. a Alarmer
  30. }
  31. func NewMaintenanceServer(s *etcdserver.EtcdServer) pb.MaintenanceServer {
  32. return &maintenanceServer{bg: s, a: s}
  33. }
  34. func (ms *maintenanceServer) Defragment(ctx context.Context, sr *pb.DefragmentRequest) (*pb.DefragmentResponse, error) {
  35. plog.Noticef("starting to defragment the storage backend...")
  36. err := ms.bg.Backend().Defrag()
  37. if err != nil {
  38. plog.Errorf("failed to deframent the storage backend (%v)", err)
  39. return nil, err
  40. }
  41. plog.Noticef("finished defragmenting the storage backend")
  42. return &pb.DefragmentResponse{}, nil
  43. }
  44. func (ms *maintenanceServer) Alarm(ctx context.Context, ar *pb.AlarmRequest) (*pb.AlarmResponse, error) {
  45. plog.Warningf("alarming %+v", ar)
  46. return ms.a.Alarm(ctx, ar)
  47. }