remote.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2015 The etcd Authors
  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 rafthttp
  15. import (
  16. "github.com/coreos/etcd/pkg/types"
  17. "github.com/coreos/etcd/raft/raftpb"
  18. )
  19. type remote struct {
  20. id types.ID
  21. status *peerStatus
  22. pipeline *pipeline
  23. }
  24. func startRemote(tr *Transport, urls types.URLs, id types.ID) *remote {
  25. picker := newURLPicker(urls)
  26. status := newPeerStatus(id)
  27. pipeline := &pipeline{
  28. peerID: id,
  29. tr: tr,
  30. picker: picker,
  31. status: status,
  32. raft: tr.Raft,
  33. errorc: tr.ErrorC,
  34. }
  35. pipeline.start()
  36. return &remote{
  37. id: id,
  38. status: status,
  39. pipeline: pipeline,
  40. }
  41. }
  42. func (g *remote) send(m raftpb.Message) {
  43. select {
  44. case g.pipeline.msgc <- m:
  45. default:
  46. if g.status.isActive() {
  47. plog.MergeWarningf("dropped internal raft message to %s since sending buffer is full (bad/overloaded network)", g.id)
  48. }
  49. plog.Debugf("dropped %s to %s since sending buffer is full", m.Type, g.id)
  50. }
  51. }
  52. func (g *remote) stop() {
  53. g.pipeline.stop()
  54. }