remote.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2015 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 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, local, to, cid types.ID, r Raft, errorc chan error) *remote {
  25. picker := newURLPicker(urls)
  26. status := newPeerStatus(to)
  27. return &remote{
  28. id: to,
  29. status: status,
  30. pipeline: newPipeline(tr, picker, local, to, cid, status, nil, r, errorc),
  31. }
  32. }
  33. func (g *remote) send(m raftpb.Message) {
  34. select {
  35. case g.pipeline.msgc <- m:
  36. default:
  37. if g.status.isActive() {
  38. plog.MergeWarningf("dropped internal raft message to %s since sending buffer is full (bad/overloaded network)", g.id)
  39. }
  40. plog.Debugf("dropped %s to %s since sending buffer is full", m.Type, g.id)
  41. }
  42. }
  43. func (g *remote) stop() {
  44. g.pipeline.stop()
  45. }